feat: ade support for showing errored messages in ade

This commit is contained in:
Andy Li
2025-07-21 13:03:20 -07:00
committed by GitHub
parent b7d6cf7167
commit a3bb0b5fdf
3 changed files with 13 additions and 11 deletions

View File

@@ -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):

View File

@@ -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:

View File

@@ -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