From b17b2dc31e98b49152531099f72c268c21a745cc Mon Sep 17 00:00:00 2001 From: cthomas Date: Tue, 27 May 2025 13:50:41 -0700 Subject: [PATCH] chore: move ttft logging for new agent loop (#2465) --- letta/agents/letta_agent.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/letta/agents/letta_agent.py b/letta/agents/letta_agent.py index fd946878..062e800f 100644 --- a/letta/agents/letta_agent.py +++ b/letta/agents/letta_agent.py @@ -314,6 +314,10 @@ class LettaAgent(BaseAgent): actor=self.actor, ) usage = LettaUsageStatistics() + first_chunk, ttft_span = True, None + if request_start_timestamp_ns is not None: + ttft_span = tracer.start_span("time_to_first_token", start_time=request_start_timestamp_ns) + ttft_span.set_attributes({f"llm_config.{k}": v for k, v in agent_state.llm_config.model_dump().items() if v is not None}) for _ in range(max_steps): step_id = generate_step_id() @@ -354,11 +358,6 @@ class LettaAgent(BaseAgent): else: raise ValueError(f"Streaming not supported for {agent_state.llm_config}") - first_chunk, ttft_span = True, None - if request_start_timestamp_ns is not None: - ttft_span = tracer.start_span("time_to_first_token", start_time=request_start_timestamp_ns) - ttft_span.set_attributes({f"llm_config.{k}": v for k, v in agent_state.llm_config.model_dump().items() if v is not None}) - async for chunk in interface.process(stream): # Measure time to first token if first_chunk and ttft_span is not None: