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.

fix: anthropic thinking tag nesting bug (#1548)

cthomascf5da6202176
diff --git a/letta/schemas/message.py b/letta/schemas/message.py
index 65e5d84be..4881ab0e1 100644
--- a/letta/schemas/message.py
+++ b/letta/schemas/message.py
@@ -670,6 +670,9 @@ class Message(BaseMessage):
def add_xml_tag(string: str, xml_tag: Optional[str]):
# NOTE: Anthropic docs recommends using <thinking> tag when using CoT + tool use
+ if f"<{xml_tag}>" in string and f"</{xml_tag}>" in string:
+ # don't nest if tags already exist
+ return string
return f"<{xml_tag}>{string}</{xml_tag}" if xml_tag else string
if self.role == "system":