Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix(core): preserve Gemini thought_signature on function calls in non-streaming path (#9351)
Kian Jonesf20fdc73d177
diff --git a/letta/adapters/letta_llm_request_adapter.py b/letta/adapters/letta_llm_request_adapter.pyindex 17c3a77fe..8ea956801 100644--- a/letta/adapters/letta_llm_request_adapter.py+++ b/letta/adapters/letta_llm_request_adapter.py@@ -66,7 +66,13 @@ class LettaLLMRequestAdapter(LettaLLMAdapter):self.reasoning_content = [OmittedReasoningContent()]elif self.chat_completions_response.choices[0].message.content:# Reasoning placed into content for legacy reasons- self.reasoning_content = [TextContent(text=self.chat_completions_response.choices[0].message.content)]+ # Carry thought_signature on TextContent when ReasoningContent doesn't exist to hold it+ self.reasoning_content = [+ TextContent(+ text=self.chat_completions_response.choices[0].message.content,+ signature=self.chat_completions_response.choices[0].message.reasoning_content_signature,+ )+ ]else:# logger.info("No reasoning content found.")self.reasoning_content = Nonediff --git a/letta/adapters/simple_llm_request_adapter.py b/letta/adapters/simple_llm_request_adapter.pyindex 7cf5b260b..7cec9472c 100644--- a/letta/adapters/simple_llm_request_adapter.py+++ b/letta/adapters/simple_llm_request_adapter.py@@ -81,7 +81,12 @@ class SimpleLLMRequestAdapter(LettaLLMRequestAdapter):if self.chat_completions_response.choices[0].message.content:# NOTE: big difference - 'content' goes into 'content'# Reasoning placed into content for legacy reasons- self.content = [TextContent(text=self.chat_completions_response.choices[0].message.content)]+ # Carry thought_signature on TextContent when ReasoningContent doesn't exist to hold it+ # (e.g. Gemini 2.5 Flash with include_thoughts=False still returns thought_signature)+ orphan_sig = (+ self.chat_completions_response.choices[0].message.reasoning_content_signature if not self.reasoning_content else None+ )+ self.content = [TextContent(text=self.chat_completions_response.choices[0].message.content, signature=orphan_sig)]else:self.content = Nonediff --git a/letta/agents/letta_agent.py b/letta/agents/letta_agent.pyindex 246f6d3f1..98e562059 100644--- a/letta/agents/letta_agent.py+++ b/letta/agents/letta_agent.py@@ -370,8 +370,12 @@ class LettaAgent(BaseAgent):elif response.choices[0].message.omitted_reasoning_content:reasoning = [OmittedReasoningContent()]elif response.choices[0].message.content:+ # Carry thought_signature on TextContent when ReasoningContent doesn't exist to hold itreasoning = [- TextContent(text=response.choices[0].message.content)+ TextContent(+ text=response.choices[0].message.content,+ signature=response.choices[0].message.reasoning_content_signature,+ )] # reasoning placed into content for legacy reasonselse:self.logger.info("No reasoning content found.")@@ -703,8 +707,12 @@ class LettaAgent(BaseAgent):)]elif response.choices[0].message.content:+ # Carry thought_signature on TextContent when ReasoningContent doesn't exist to hold itreasoning = [- TextContent(text=response.choices[0].message.content)+ TextContent(+ text=response.choices[0].message.content,+ signature=response.choices[0].message.reasoning_content_signature,+ )] # reasoning placed into content for legacy reasonselif response.choices[0].message.omitted_reasoning_content:reasoning = [OmittedReasoningContent()]diff --git a/letta/llm_api/google_vertex_client.py b/letta/llm_api/google_vertex_client.pyindex 56ed0ae12..ccbee0ca2 100644--- a/letta/llm_api/google_vertex_client.py+++ b/letta/llm_api/google_vertex_client.py@@ -593,6 +593,9 @@ class GoogleVertexClient(LLMClientBase):content=inner_thoughts,tool_calls=[tool_call],)+ if response_message.thought_signature:+ thought_signature = base64.b64encode(response_message.thought_signature).decode("utf-8")+ openai_response_message.reasoning_content_signature = thought_signatureelse:openai_response_message.content = inner_thoughtsif openai_response_message.tool_calls is None: