Skip to content

Commit

Permalink
Removed question argument from gen_answer, since it's dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Nov 15, 2024
1 parent 4dfd033 commit 54339dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
4 changes: 2 additions & 2 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions paperqa/agents/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
30 changes: 10 additions & 20 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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": []},
},
},
]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54339dd

Please sign in to comment.