feat: protect against anthropic nested tool args (#2250)

This commit is contained in:
cthomas
2025-05-19 16:01:59 -07:00
committed by GitHub
parent 26ffd19e1f
commit fe592eda72
3 changed files with 15 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import json
from datetime import datetime, timezone
from enum import Enum
from typing import AsyncGenerator, List, Union
@@ -89,7 +90,13 @@ class AnthropicStreamingInterface:
def get_tool_call_object(self) -> ToolCall:
"""Useful for agent loop"""
return ToolCall(id=self.tool_call_id, function=FunctionCall(arguments=self.accumulated_tool_call_args, name=self.tool_call_name))
# hack for tool rules
tool_input = json.loads(self.accumulated_tool_call_args)
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:
arguments = self.accumulated_tool_call_args
return ToolCall(id=self.tool_call_id, function=FunctionCall(arguments=arguments, name=self.tool_call_name))
def _check_inner_thoughts_complete(self, combined_args: str) -> bool:
"""