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 signature to content parts (#5134)

cthomascc913df27c97
diff --git a/fern/openapi.json b/fern/openapi.json
index bf303be18..387bfef65 100644
--- a/fern/openapi.json
+++ b/fern/openapi.json
@@ -30547,6 +30547,18 @@
"title": "Type",
"description": "Indicates this is an omitted reasoning step.",
"default": "omitted_reasoning"
+ },
+ "signature": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Signature",
+ "description": "A unique identifier for this reasoning step."
}
},
"type": "object",
@@ -33579,6 +33591,18 @@
"type": "string",
"title": "Text",
"description": "The text content of the message."
+ },
+ "signature": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Signature",
+ "description": "Stores a unique identifier for any reasoning associated with this text content."
}
},
"type": "object",
@@ -33893,6 +33917,18 @@
"type": "object",
"title": "Input",
"description": "The parameters being passed to the tool, structured as a dictionary of parameter names to values."
+ },
+ "signature": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Signature",
+ "description": "Stores a unique identifier for any reasoning associated with this tool call."
}
},
"type": "object",
diff --git a/letta/interfaces/gemini_streaming_interface.py b/letta/interfaces/gemini_streaming_interface.py
index 052006612..97fd613d1 100644
--- a/letta/interfaces/gemini_streaming_interface.py
+++ b/letta/interfaces/gemini_streaming_interface.py
@@ -72,10 +72,10 @@ class SimpleGeminiStreamingInterface:
def get_content(self) -> List[ReasoningContent | TextContent | ToolCallContent]:
"""This is (unusually) in chunked format, instead of merged"""
- # for content in self.content_parts:
- # if isinstance(content, ReasoningContent):
- # # This assumes there is only one signature per turn
- # content.signature = self.thinking_signature
+ for content in self.content_parts:
+ if isinstance(content, ReasoningContent):
+ # This assumes there is only one signature per turn
+ content.signature = self.thinking_signature
return self.content_parts
def get_tool_call_object(self) -> ToolCall:
@@ -181,7 +181,7 @@ class SimpleGeminiStreamingInterface:
if part.thought_signature:
# NOTE: the thought_signature comes on the Part with the function_call
thought_signature = part.thought_signature
- self.thinking_signature = thought_signature
+ self.thinking_signature = base64.b64encode(thought_signature).decode("utf-8")
if prev_message_type and prev_message_type != "reasoning_message":
message_index += 1
yield ReasoningMessage(
@@ -190,7 +190,7 @@ class SimpleGeminiStreamingInterface:
otid=Message.generate_otid_from_id(self.letta_message_id, message_index),
source="reasoner_model",
reasoning="",
- signature=base64.b64encode(thought_signature).decode("utf-8"),
+ signature=self.thinking_signature,
)
prev_message_type = "reasoning_message"
@@ -235,6 +235,7 @@ class SimpleGeminiStreamingInterface:
self.content_parts.append(
TextContent(
text=content,
+ signature=self.thinking_signature,
)
)
diff --git a/letta/schemas/letta_message_content.py b/letta/schemas/letta_message_content.py
index 69e073ab2..24265777f 100644
--- a/letta/schemas/letta_message_content.py
+++ b/letta/schemas/letta_message_content.py
@@ -39,6 +39,9 @@ class MessageContent(BaseModel):
class TextContent(MessageContent):
type: Literal[MessageContentType.text] = Field(default=MessageContentType.text, description="The type of the message.")
text: str = Field(..., description="The text content of the message.")
+ signature: Optional[str] = Field(
+ default=None, description="Stores a unique identifier for any reasoning associated with this text content."
+ )
def to_text(self) -> str:
"""Return the text content."""
@@ -188,6 +191,9 @@ class ToolCallContent(MessageContent):
input: dict = Field(
..., description="The parameters being passed to the tool, structured as a dictionary of parameter names to values."
)
+ signature: Optional[str] = Field(
+ default=None, description="Stores a unique identifier for any reasoning associated with this tool call."
+ )
def to_text(self) -> str:
"""Return a text representation of the tool call."""
@@ -241,6 +247,7 @@ class OmittedReasoningContent(MessageContent):
type: Literal[MessageContentType.omitted_reasoning] = Field(
default=MessageContentType.omitted_reasoning, description="Indicates this is an omitted reasoning step."
)
+ signature: Optional[str] = Field(default=None, description="A unique identifier for this reasoning step.")
# NOTE: dropping because we don't track this kind of information for the other reasoning types
# tokens: int = Field(..., description="The reasoning token count for intermediate reasoning content.")
diff --git a/letta/schemas/message.py b/letta/schemas/message.py
index 7334f9d10..a10d59e31 100644
--- a/letta/schemas/message.py
+++ b/letta/schemas/message.py
@@ -1399,19 +1399,22 @@ class Message(BaseMessage):
native_google_content_parts = []
for content in self.content:
if isinstance(content, TextContent):
- native_google_content_parts.append({"text": content.text})
+ native_part = {"text": content.text}
+ if content.signature:
+ native_part["thought_signature"] = content.signature
+ native_google_content_parts.append(native_part)
elif isinstance(content, ReasoningContent):
native_google_content_parts.append({"text": content.reasoning, "thought": True})
elif isinstance(content, ToolCallContent):
- native_google_content_parts.append(
- {
- "function_call": {
- "name": content.name,
- "args": content.input,
- },
- # "thought_signature": content.signature,
- }
- )
+ native_part = {
+ "function_call": {
+ "name": content.name,
+ "args": content.input,
+ },
+ }
+ if content.signature:
+ native_part["thought_signature"] = content.signature
+ native_google_content_parts.append(native_part)
else:
raise ValueError(f"Unsupported content type: {content.type}")
if native_google_content_parts: