feat: protect against anthropic nested tool args (#2250)
This commit is contained in:
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user