diff --git a/app/crew/crew.py b/app/crew/crew.py index 7ab3a12..a821953 100644 --- a/app/crew/crew.py +++ b/app/crew/crew.py @@ -42,25 +42,17 @@ def get_research_crew(query: ResearchQuery) -> Crew: relevancy_agent = get_relevancy_agent(AgentInput(query=query)) research_agent = get_research_agent(AgentInput(query=query, tools=[serper_tool])) query_agent = get_query_agent(AgentInput(query=query)) - retrieval_agent = get_retrieval_agent( - AgentInput(query=query, tools=[serper_tool, qdrant_tool]) - ) + retrieval_agent = get_retrieval_agent(AgentInput(query=query, tools=[serper_tool, qdrant_tool])) synthesizer_agent = get_synthesizer_agent(AgentInput(query=query)) # Initialize tasks with assigned agents - question_relevancy_task = get_question_relevancy_task( - TaskInput(relevancy_agent, query) - ) - research_approach_task = get_research_approach_creation_task( - TaskInput(research_agent, query, [serper_tool]) - ) + question_relevancy_task = get_question_relevancy_task(TaskInput(relevancy_agent, query)) + research_approach_task = get_research_approach_creation_task(TaskInput(research_agent, query, [serper_tool])) search_query_task = get_search_query_generation_task(TaskInput(query_agent, query)) rag_retrieval_task = get_rag_retrieval_results_task( TaskInput(retrieval_agent, query, [qdrant_tool], [search_query_task]) ) - web_search_task = get_web_search_results_task( - TaskInput(retrieval_agent, query, [serper_tool], [search_query_task]) - ) + web_search_task = get_web_search_results_task(TaskInput(retrieval_agent, query, [serper_tool], [search_query_task])) keep_relevant_data_task = get_keep_relevant_data_task( TaskInput(relevancy_agent, query, [], [rag_retrieval_task, web_search_task]) ) diff --git a/app/crew/tasks.py b/app/crew/tasks.py index 2d2a3ba..9bc0620 100644 --- a/app/crew/tasks.py +++ b/app/crew/tasks.py @@ -9,11 +9,7 @@ @traceable(run_type="task") def get_question_relevancy_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "question_relevancy.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "question_relevancy.txt") return Task( agent=task_input.agent, description=f"Evaluate if the question '{task_input.query.query}' is relevant for research. Consider factors such as clarity, specificity, research potential, and whether it is answerable through research. Flag questions that are too vague, nonsensical, or impossible to research effectively.{task_input.query.context_info}", @@ -32,11 +28,7 @@ def get_question_relevancy_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_research_approach_creation_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "research_approach.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "research_approach.txt") return Task( agent=task_input.agent, description=f"Create a comprehensive research approach for the question: '{task_input.query.query}'. Outline the key areas to investigate, potential sources of information, and methodologies to employ. Consider different angles and perspectives that might provide valuable insights.{task_input.query.context_info}", @@ -53,11 +45,7 @@ def get_research_approach_creation_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_search_query_generation_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "search_queries.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "search_queries.txt") return Task( agent=task_input.agent, description=f"Generate a diverse set of search queries related to the research question: '{task_input.query.query}'. Create at least 5 distinct search queries that will help gather comprehensive information. Queries should target different aspects of the question and use varying keywords to maximize relevant results.{task_input.query.context_info}", @@ -74,11 +62,7 @@ def get_search_query_generation_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_rag_retrieval_results_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "rag_retrieval_results.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "rag_retrieval_results.txt") return Task( agent=task_input.agent, description=f"Using Retrieval Augmented Generation (RAG), retrieve relevant information from the knowledge base to answer the research question: '{task_input.query.query}'. Focus on finding high-quality, accurate information that directly addresses the question and provides context.{task_input.query.context_info}", @@ -95,11 +79,7 @@ def get_rag_retrieval_results_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_web_search_results_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "web_search_results.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "web_search_results.txt") return Task( agent=task_input.agent, description=f"Conduct comprehensive web searches using the generated queries to find the most relevant and up-to-date information related to the research question: '{task_input.query.query.query}'. Focus on authoritative sources, recent publications, and diverse perspectives.{task_input.query.context_info}", @@ -116,11 +96,7 @@ def get_web_search_results_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_keep_relevant_data_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "relevant_data.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "relevant_data.txt") return Task( agent=task_input.agent, description=f"Critically evaluate all gathered information (from RAG and web searches) based on its direct relevance to the research question: '{task_input.query.query.query}'. Apply a strict filter, discarding any information that is tangential, low-quality, or lacks credible sourcing. Retain only the most pertinent and verifiable data points.{task_input.query.context_info}", @@ -137,11 +113,7 @@ def get_keep_relevant_data_task(task_input: TaskInput) -> Task: @traceable(run_type="task") def get_summarizing_task(task_input: TaskInput) -> Task: - output_file = ( - task_input.output_file - if task_input.output_file - else Path("out" / "research_synthesis.txt") - ) + output_file = task_input.output_file if task_input.output_file else Path("out" / "research_synthesis.txt") return Task( agent=task_input.agent, description=f"Synthesize the curated, relevant information into a final, comprehensive, and coherent report answering the research question: '{task_input.query.query}'. Integrate the verified data points, ensuring a logical flow and addressing the core aspects of the query. *Crucially, every statement or piece of information presented must be accurately attributed to its source* based on the curated data provided in the context.{task_input.query.context_info}", diff --git a/app/models.py b/app/models.py index 89b70f7..90f64d3 100644 --- a/app/models.py +++ b/app/models.py @@ -10,9 +10,7 @@ class AgentInput(BaseModel): ..., description="The research query to be processed by the agent.", ) - tools: list[BaseTool] | None = Field( - None, description="List of tools available to the agent." - ) + tools: list[BaseTool] | None = Field(None, description="List of tools available to the agent.") class TaskInput(BaseModel): @@ -24,9 +22,7 @@ class TaskInput(BaseModel): ..., description="The research query to be processed by the task.", ) - tools: list[BaseTool] | None = Field( - None, description="List of tools available to the task." - ) + tools: list[BaseTool] | None = Field(None, description="List of tools available to the task.") context: list[Task] | None = Field( None, description="List of tasks that are contextually relevant to this task.", diff --git a/app/schemas.py b/app/schemas.py index ad9c541..23c0130 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -20,9 +20,7 @@ def __eq__(self, other: "ResearchQuery") -> bool: @computed_field @property def context_info(self) -> str: - return ( - f"\nAdditional Context: {self.query.context}" if self.query.context else "" - ) + return f"\nAdditional Context: {self.query.context}" if self.query.context else "" class ResearchResponse(BaseModel):