Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: Turn off parallel tool calling for Claude (#2736)
Matthew Zhou96b8f155d877
diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.pyindex 65489166a..78bac4143 100644--- a/letta/interfaces/anthropic_streaming_interface.py+++ b/letta/interfaces/anthropic_streaming_interface.py@@ -91,7 +91,14 @@ class AnthropicStreamingInterface:def get_tool_call_object(self) -> ToolCall:"""Useful for agent loop"""# hack for tool rules- tool_input = json.loads(self.accumulated_tool_call_args)+ try:+ tool_input = json.loads(self.accumulated_tool_call_args)+ except json.JSONDecodeError as e:+ logger.warning(+ f"Failed to decode tool call arguments for tool_call_id={self.tool_call_id}, "+ f"name={self.tool_call_name}. Raw input: {self.accumulated_tool_call_args!r}. Error: {e}"+ )+ raiseif "id" in tool_input and tool_input["id"].startswith("toolu_") and "function" in tool_input:arguments = str(json.dumps(tool_input["function"]["arguments"], indent=2))else:diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.pyindex f8bc5a6b8..1f61d960a 100644--- a/letta/llm_api/anthropic_client.py+++ b/letta/llm_api/anthropic_client.py@@ -202,7 +202,7 @@ class AnthropicClient(LLMClientBase):tool_choice = {"type": "auto", "disable_parallel_tool_use": True}tools_for_request = [OpenAITool(function=f) for f in tools]elif force_tool_call is not None:- tool_choice = {"type": "tool", "name": force_tool_call}+ tool_choice = {"type": "tool", "name": force_tool_call, "disable_parallel_tool_use": True}tools_for_request = [OpenAITool(function=f) for f in tools if f["name"] == force_tool_call]# need to have this setting to be able to put inner thoughts in kwargsdiff --git a/letta/otel/metrics.py b/letta/otel/metrics.pyindex 239a6430b..e37f252ae 100644--- a/letta/otel/metrics.py+++ b/letta/otel/metrics.py@@ -1,8 +1,8 @@import reimport time-from typing import List, Optional+from typing import List-from fastapi import Depends, FastAPI, Request+from fastapi import FastAPI, Requestfrom opentelemetry import metricsfrom opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporterfrom opentelemetry.metrics import NoOpMeter