feat: add last_stop_reason to AgentState [LET-5911] (#5772)

* feat: add last_stop_reason to AgentState [LET-5911]

* undo agent loop changes, use update_run_by_id_async

* add run manager test

* add integration tests

* remove comment

* remove duplicate test
This commit is contained in:
Christina Tong
2025-11-04 23:32:56 -08:00
committed by Caren Thomas
parent dbad510a6e
commit ef3df907c5
10 changed files with 248 additions and 0 deletions

View File

@@ -341,6 +341,20 @@ class RunManager:
await session.commit()
# Update agent's last_stop_reason when run completes
# Do this after run update is committed to database
if is_terminal_update and update.stop_reason:
try:
from letta.schemas.agent import UpdateAgent
await self.agent_manager.update_agent_async(
agent_id=pydantic_run.agent_id,
agent_update=UpdateAgent(last_stop_reason=update.stop_reason),
actor=actor,
)
except Exception as e:
logger.error(f"Failed to update agent's last_stop_reason for run {run_id}: {e}")
# update run metrics table
num_steps = len(await self.step_manager.list_steps_async(run_id=run_id, actor=actor))