Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: step metrics not found (#6472)
jnjpngc90eacdcbb93
diff --git a/letta/agents/letta_agent_v2.py b/letta/agents/letta_agent_v2.pyindex 3969a8f1d..f575d77ab 100644--- a/letta/agents/letta_agent_v2.py+++ b/letta/agents/letta_agent_v2.py@@ -822,6 +822,9 @@ class LettaAgentV2(BaseAgentV2):project_id=self.agent_state.project_id,status=StepStatus.PENDING,)++ # Also create step metrics early and update at the end of the step+ self._record_step_metrics(step_id=step_id, step_metrics=step_metrics, run_id=run_id)return StepProgression.START, logged_step, step_metrics, agent_step_span@trace_methoddiff --git a/letta/services/step_manager.py b/letta/services/step_manager.pyindex eb6a37db6..c64a1e089 100644--- a/letta/services/step_manager.py+++ b/letta/services/step_manager.py@@ -511,12 +511,33 @@ class StepManager:if step.organization_id != actor.organization_id:raise Exception("Unauthorized")- if allow_partial:- try:- metrics = await StepMetricsModel.read_async(db_session=session, identifier=step_id, actor=actor)+ try:+ metrics = await StepMetricsModel.read_async(db_session=session, identifier=step_id, actor=actor)++ if allow_partial:return metrics.to_pydantic()- except NoResultFound:- pass++ # Update existing metrics+ if llm_request_ns is not None:+ metrics.llm_request_ns = llm_request_ns+ if tool_execution_ns is not None:+ metrics.tool_execution_ns = tool_execution_ns+ if step_ns is not None:+ metrics.step_ns = step_ns+ if agent_id is not None:+ metrics.agent_id = agent_id+ if run_id is not None:+ metrics.run_id = run_id+ if project_id is not None:+ metrics.project_id = project_id+ if template_id is not None:+ metrics.template_id = template_id+ if base_template_id is not None:+ metrics.base_template_id = base_template_id+ await session.commit()+ return metrics.to_pydantic()+ except NoResultFound:+ passmetrics_data = {"id": step_id,