From a3bb0b5fdfc7c9b17279f5e19bcbf169ad9cd01d Mon Sep 17 00:00:00 2001 From: Andy Li <55300002+cliandy@users.noreply.github.com> Date: Mon, 21 Jul 2025 13:03:20 -0700 Subject: [PATCH] feat: ade support for showing errored messages in ade --- letta/schemas/letta_message.py | 6 +++--- letta/schemas/message.py | 9 +++++++++ letta/server/rest_api/streaming_response.py | 9 +-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/letta/schemas/letta_message.py b/letta/schemas/letta_message.py index d1e9b2a7..1e772191 100644 --- a/letta/schemas/letta_message.py +++ b/letta/schemas/letta_message.py @@ -63,13 +63,13 @@ class LettaMessage(BaseModel): dt = dt.replace(tzinfo=timezone.utc) return dt.isoformat(timespec="seconds") - @field_serializer("is_err", when_used="unless-none") - def serialize_is_err(self, value: bool | None, _info): + @field_serializer("is_err", mode="wrap") + def serialize_is_err(self, value: bool | None, handler, _info): """ Only serialize is_err field when it's True (for debugging purposes). When is_err is None or False, this field will be excluded from the JSON output. """ - return value if value is True else None + return handler(value) if value is True else None class SystemMessage(LettaMessage): diff --git a/letta/schemas/message.py b/letta/schemas/message.py index ec690577..73bf73db 100644 --- a/letta/schemas/message.py +++ b/letta/schemas/message.py @@ -269,6 +269,7 @@ class Message(BaseMessage): otid=otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) # Otherwise, we may have a list of multiple types @@ -287,6 +288,7 @@ class Message(BaseMessage): otid=otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) elif isinstance(content_part, ReasoningContent): @@ -301,6 +303,7 @@ class Message(BaseMessage): name=self.name, otid=otid, step_id=self.step_id, + is_err=self.is_err, ) ) elif isinstance(content_part, RedactedReasoningContent): @@ -315,6 +318,7 @@ class Message(BaseMessage): otid=otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) elif isinstance(content_part, OmittedReasoningContent): @@ -328,6 +332,7 @@ class Message(BaseMessage): name=self.name, otid=otid, step_id=self.step_id, + is_err=self.is_err, ) ) else: @@ -355,6 +360,7 @@ class Message(BaseMessage): otid=otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) else: @@ -371,6 +377,7 @@ class Message(BaseMessage): otid=otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) elif self.role == MessageRole.tool: @@ -416,6 +423,7 @@ class Message(BaseMessage): otid=Message.generate_otid_from_id(self.id, len(messages)), sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) elif self.role == MessageRole.user: @@ -437,6 +445,7 @@ class Message(BaseMessage): otid=self.otid, sender_id=self.sender_id, step_id=self.step_id, + is_err=self.is_err, ) ) elif self.role == MessageRole.system: diff --git a/letta/server/rest_api/streaming_response.py b/letta/server/rest_api/streaming_response.py index 4daf65a7..344d067d 100644 --- a/letta/server/rest_api/streaming_response.py +++ b/letta/server/rest_api/streaming_response.py @@ -125,14 +125,7 @@ class StreamingResponseWithStatusCode(StreamingResponse): if not isinstance(content, bytes): content = content.encode(self.charset) more_body = False - await send( - { - "type": "http.response.body", - "body": content, - "more_body": more_body, - } - ) - raise Exception(f"An exception occurred mid-stream with status code {status_code}", detail={"content": content}) + raise Exception(f"An exception occurred mid-stream with status code {status_code} with content {content}") else: content = chunk