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 417e666 commit 7c8bb2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
8 changes: 3 additions & 5 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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)
except Exception:
logger.exception("Trajectory failed.")
status = AgentStatus.FAIL
Expand Down Expand Up @@ -214,7 +214,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 Expand Up @@ -269,9 +269,7 @@ async def rollout() -> AgentStatus:
env.tools,
)
)
await generate_answer_tool._tool_fn(
question=query.query, state=env.state
)
await generate_answer_tool._tool_fn(state=env.state)
return AgentStatus.TRUNCATED
agent_state.messages += obs
for attempt in Retrying(
Expand Down
9 changes: 3 additions & 6 deletions paperqa/agents/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,18 @@ class GenerateAnswer(NamedTool):
def did_not_fail_to_answer(cls, message: str | None) -> bool:
return not (message or "").startswith(cls.FAILED_TO_ANSWER)

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.
Propose 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 @@ -300,8 +299,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
28 changes: 9 additions & 19 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,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 @@ -659,24 +659,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."
"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."
),
"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 @@ -756,7 +746,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 7c8bb2b

Please sign in to comment.