Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: add check before logging step metrics (#4495)

cthomasa0c4f086d0ee
diff --git a/letta/agents/letta_agent_v2.py b/letta/agents/letta_agent_v2.py
index db66c5415..26d1c6ba5 100644
--- a/letta/agents/letta_agent_v2.py
+++ b/letta/agents/letta_agent_v2.py
@@ -779,11 +779,12 @@ class LettaAgentV2(BaseAgentV2):
def _step_checkpoint_finish(
self, step_metrics: StepMetrics, agent_step_span: Span | None, run_id: str | None
) -> Tuple[StepProgression, StepMetrics]:
- step_ns = get_utc_timestamp_ns() - step_metrics.step_start_ns
- step_metrics.step_ns = step_ns
- if agent_step_span is not None:
- agent_step_span.add_event(name="step_ms", attributes={"duration_ms": ns_to_ms(step_ns)})
- agent_step_span.end()
+ if step_metrics.step_start_ns:
+ step_ns = get_utc_timestamp_ns() - step_metrics.step_start_ns
+ step_metrics.step_ns = step_ns
+ if agent_step_span is not None:
+ agent_step_span.add_event(name="step_ms", attributes={"duration_ms": ns_to_ms(step_ns)})
+ agent_step_span.end()
self._record_step_metrics(step_id=step_metrics.id, step_metrics=step_metrics)
return StepProgression.FINISHED, step_metrics