Skip to content

Commit

Permalink
Now when encountering empty tool calls, continuing onwards
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Nov 15, 2024
1 parent 6aed5da commit 275cb93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
14 changes: 1 addition & 13 deletions paperqa/agents/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,11 @@ async def step(
self, action: ToolRequestMessage
) -> tuple[Messages, float, bool, bool]:
self.state.record_action(action)
if not action.tool_calls:
return (
# NOTE: don't put:
# - GenerateAnswer.FAILED_TO_ANSWER here because this wasn't a failure
# - 'cannot answer' because that information belongs in
# PQASession.answer, not in the message history
# Let's just put a nice message about being done :)
[Message(content="Agent specified 0 tool calls, which means done.")],
self.USE_POST_PROCESSED_REWARD,
True, # Matching LangChain: https://github.com/langchain-ai/langchain/blob/langchain%3D%3D0.2.17/libs/langchain/langchain/agents/output_parsers/openai_functions.py#L38-L77
False, # Let caller determine truncations
)

response_messages = cast(
list[Message],
await self.exec_tool_calls(action, state=self.state, handle_tool_exc=True),
)
) or [Message(content=f"No tool calls input in tool request {action}.")]
return (
response_messages,
self.USE_POST_PROCESSED_REWARD,
Expand Down
5 changes: 2 additions & 3 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,8 @@ async def test_empty_tool_calls(self, agent_test_settings: Settings) -> None:
obs, _, done, truncated = await env.step(ToolRequestMessage())
assert len(obs) == 1
assert obs[0].content
assert GenerateAnswer.did_not_fail_to_answer(obs[0].content)
assert "0 tool calls" in obs[0].content
assert done
assert "no tool calls" in obs[0].content.lower()
assert not done
assert not truncated

@pytest.mark.asyncio
Expand Down

0 comments on commit 275cb93

Please sign in to comment.