Skip to content

Commit

Permalink
Fixed LDP runner's TRUNCATED not calling gen_answer, and document…
Browse files Browse the repository at this point in the history
…ed `AgentStatus` (#690)
  • Loading branch information
jamesbraza authored Nov 15, 2024
1 parent 2cc0a6a commit 4dfd033
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
17 changes: 5 additions & 12 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ async def _run_with_timeout_failure(
f"Agent timeout after {query.settings.agent.timeout}-sec, just answering."
)
status = AgentStatus.TRUNCATED
except Exception:
logger.exception("Trajectory failed.")
status = AgentStatus.FAIL
if status == AgentStatus.TRUNCATED:
# Fail over after truncation (too many steps, timeout): just answer
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)
except Exception:
logger.exception("Trajectory failed.")
status = AgentStatus.FAIL
return env.state.session, status


Expand Down Expand Up @@ -263,15 +265,6 @@ async def rollout() -> AgentStatus:
f"Agent didn't finish within {max_timesteps} timesteps, just"
" answering."
)
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
)
return AgentStatus.TRUNCATED
agent_state.messages += obs
for attempt in Retrying(
Expand Down
8 changes: 4 additions & 4 deletions paperqa/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def __getstate__(self) -> object: ...
def __setstate__(self, state: object) -> None: ...


class AgentStatus(StrEnum):
# FAIL - no answer could be generated
class AgentStatus(StrEnum): # TODO: rename to AnswerStatus or RolloutStatus
# FAIL - during the trajectory encountered an unhandled exception
FAIL = "fail"
# SUCCESS - answer was generated
SUCCESS = "success"
# TRUNCATED - agent didn't finish naturally (e.g. timeout, too many actions),
# so we prematurely answered
# so we just generated an answer after the unnatural finish
TRUNCATED = "truncated"
# UNSURE - the agent was unsure, but an answer is present
# UNSURE - the gen_answer did not succeed, but an answer is present
UNSURE = "unsure"


Expand Down

0 comments on commit 4dfd033

Please sign in to comment.