Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add tracing to streaming interface (#2477)
cthomas982cf0c6fe9a
diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.pyindex 1a8aa2201..6fb0ae346 100644--- a/letta/interfaces/anthropic_streaming_interface.py+++ b/letta/interfaces/anthropic_streaming_interface.py@@ -37,6 +37,7 @@ from letta.schemas.letta_message_content import ReasoningContent, RedactedReasonfrom letta.schemas.message import Messagefrom letta.schemas.openai.chat_completion_response import FunctionCall, ToolCallfrom letta.server.rest_api.json_parser import JSONParser, PydanticJSONParser+from letta.tracing import trace_methodlogger = get_logger(__name__)@@ -115,6 +116,7 @@ class AnthropicStreamingInterface:logger.error("Error checking inner thoughts: %s", e)raise+ @trace_methodasync def process(self, stream: AsyncStream[BetaRawMessageStreamEvent]) -> AsyncGenerator[LettaMessage, None]:prev_message_type = Nonemessage_index = 0diff --git a/letta/interfaces/openai_streaming_interface.py b/letta/interfaces/openai_streaming_interface.pyindex 212817e0f..3edde5ece 100644--- a/letta/interfaces/openai_streaming_interface.py+++ b/letta/interfaces/openai_streaming_interface.py@@ -11,6 +11,7 @@ from letta.schemas.message import Messagefrom letta.schemas.openai.chat_completion_response import FunctionCall, ToolCallfrom letta.server.rest_api.json_parser import OptimisticJSONParserfrom letta.streaming_utils import JSONInnerThoughtsExtractor+from letta.tracing import trace_methodclass OpenAIStreamingInterface:@@ -64,6 +65,7 @@ class OpenAIStreamingInterface:function=FunctionCall(arguments=self.current_function_arguments, name=function_name),)+ @trace_methodasync def process(self, stream: AsyncStream[ChatCompletionChunk]) -> AsyncGenerator[LettaMessage, None]:"""Iterates over the OpenAI stream, yielding SSE events.diff --git a/letta/services/helpers/agent_manager_helper.py b/letta/services/helpers/agent_manager_helper.pyindex 0b20e31b8..23146bbcb 100644--- a/letta/services/helpers/agent_manager_helper.py+++ b/letta/services/helpers/agent_manager_helper.py@@ -1,7 +1,7 @@import datetimefrom typing import List, Literal, Optional-from sqlalchemy import and_, asc, desc, func, literal, or_, select+from sqlalchemy import and_, asc, desc, or_, selectfrom sqlalchemy.sql.expression import existsfrom letta import system