diff --git a/paperqa/agents/main.py b/paperqa/agents/main.py index 24022fae..d84c8c28 100644 --- a/paperqa/agents/main.py +++ b/paperqa/agents/main.py @@ -163,7 +163,7 @@ async def _run_with_timeout_failure( generate_answer_tool = next( filter(lambda x: x.info.name == GenerateAnswer.TOOL_FN_NAME, env.tools) ) - await generate_answer_tool._tool_fn(question=query.query, state=env.state) + await generate_answer_tool._tool_fn(state=env.state) return env.state.session, status @@ -216,7 +216,7 @@ async def rollout() -> AgentStatus: ): await step(search_tool, query=search, min_year=None, max_year=None) await step(gather_evidence_tool, question=question) - await step(generate_answer_tool, question=question) + await step(generate_answer_tool) return AgentStatus.SUCCESS return await _run_with_timeout_failure(rollout, query, env) diff --git a/paperqa/agents/tools.py b/paperqa/agents/tools.py index ff58cd95..33929cae 100644 --- a/paperqa/agents/tools.py +++ b/paperqa/agents/tools.py @@ -268,19 +268,18 @@ class GenerateAnswer(NamedTool): summary_llm_model: LiteLLMModel embedding_model: EmbeddingModel - async def gen_answer(self, question: str, state: EnvironmentState) -> str: + async def gen_answer(self, state: EnvironmentState) -> str: """ - Ask a model to propose an answer using current evidence. + Generate an answer using current evidence. The tool may fail, indicating that better or different evidence should be found. Aim for at least five pieces of evidence from multiple sources before invoking this tool. Feel free to invoke this tool in parallel with other tools, but do not call this tool in parallel with itself. Args: - question: Question to be answered. state: Current state. """ - logger.info(f"Generating answer for '{question}'.") + logger.info(f"Generating answer for '{state.session.question}'.") if f"{self.TOOL_FN_NAME}_initialized" in self.settings.agent.callbacks: await asyncio.gather( @@ -292,8 +291,6 @@ async def gen_answer(self, question: str, state: EnvironmentState) -> str: ) ) - # TODO: Should we allow the agent to change the question? - # self.answer.question = query state.session = await state.docs.aquery( query=state.session, settings=self.settings, diff --git a/tests/test_agents.py b/tests/test_agents.py index 13236dcc..009b83f4 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -404,7 +404,7 @@ async def test_gather_evidence_rejects_empty_docs( ) -> None: @wraps(GenerateAnswer.gen_answer) - async def gen_answer(self, question: str, state) -> str: # noqa: ARG001 + async def gen_answer(self, state) -> str: # noqa: ARG001 return "I cannot answer." # Patch GenerateAnswerTool.gen_answer so that if this tool is chosen first, @@ -525,7 +525,7 @@ async def test_agent_sharing_state( summary_llm_model=summary_llm_model, embedding_model=embedding_model, ) - result = await generate_answer_tool.gen_answer(answer.question, state=env_state) + result = await generate_answer_tool.gen_answer(state=env_state) if callback_type == "async": gen_answer_initialized_callback.assert_awaited_once_with(env_state) @@ -655,24 +655,14 @@ def test_tool_schema(agent_test_settings: Settings) -> None: "info": { "name": "gen_answer", "description": ( - "Ask a model to propose an answer using current" - " evidence.\n\nThe tool may fail, indicating that better or" - " different evidence should be found.\nAim for at least five" - " pieces of evidence from multiple sources before invoking this" - " tool.\nFeel free to invoke this tool in parallel with other" - " tools, but do not call this tool in parallel with itself." + "Generate an answer using current evidence.\n\nThe tool may fail," + " indicating that better or different evidence should be" + " found.\nAim for at least five pieces of evidence from multiple" + " sources before invoking this tool.\nFeel free to invoke this tool" + " in parallel with other tools, but do not call this tool in" + " parallel with itself." ), - "parameters": { - "type": "object", - "properties": { - "question": { - "type": "string", - "description": "Question to be answered.", - "title": "Question", - } - }, - "required": ["question"], - }, + "parameters": {"type": "object", "properties": {}, "required": []}, }, }, ] @@ -752,7 +742,7 @@ async def test_deepcopy_env(self, agent_test_settings: Settings) -> None: # 3. Generate an answer for both, and confirm they are identical gen_answer_action = ToolRequestMessage( - tool_calls=[ToolCall.from_name("gen_answer", question=question)] + tool_calls=[ToolCall.from_name("gen_answer")] ) _, _, done, _ = await env.step(gen_answer_action) assert done