From 96b8f155d8771c196cbd98971035bee3f3c809a9 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Tue, 10 Jun 2025 13:04:20 -0700 Subject: [PATCH] fix: Turn off parallel tool calling for Claude (#2736) --- letta/interfaces/anthropic_streaming_interface.py | 9 ++++++++- letta/llm_api/anthropic_client.py | 2 +- letta/otel/metrics.py | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.py index 65489166..78bac414 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}" + ) + raise if "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.py index f8bc5a6b..1f61d960 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 kwargs diff --git a/letta/otel/metrics.py b/letta/otel/metrics.py index 239a6430..e37f252a 100644 --- a/letta/otel/metrics.py +++ b/letta/otel/metrics.py @@ -1,8 +1,8 @@ import re import time -from typing import List, Optional +from typing import List -from fastapi import Depends, FastAPI, Request +from fastapi import FastAPI, Request from opentelemetry import metrics from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter from opentelemetry.metrics import NoOpMeter