diff --git a/flo_ai/flo_ai/llm/anthropic_llm.py b/flo_ai/flo_ai/llm/anthropic_llm.py index 05c45cf1..aa3e9c2f 100644 --- a/flo_ai/flo_ai/llm/anthropic_llm.py +++ b/flo_ai/flo_ai/llm/anthropic_llm.py @@ -95,6 +95,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]: name: { 'type': info.get('type', 'string'), 'description': info.get('description', ''), + **( + {'items': info['items']} + if info.get('type') == 'array' and 'items' in info + else {} + ), } for name, info in tool.parameters.items() }, diff --git a/flo_ai/flo_ai/llm/gemini_llm.py b/flo_ai/flo_ai/llm/gemini_llm.py index 6b3f2550..55885659 100644 --- a/flo_ai/flo_ai/llm/gemini_llm.py +++ b/flo_ai/flo_ai/llm/gemini_llm.py @@ -106,6 +106,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]: name: { 'type': info.get('type', 'string'), 'description': info.get('description', ''), + **( + {'items': info['items']} + if info.get('type') == 'array' and 'items' in info + else {} + ), } for name, info in tool.parameters.items() }, diff --git a/flo_ai/flo_ai/llm/ollama_llm.py b/flo_ai/flo_ai/llm/ollama_llm.py index 01dfc320..d4e12602 100644 --- a/flo_ai/flo_ai/llm/ollama_llm.py +++ b/flo_ai/flo_ai/llm/ollama_llm.py @@ -82,6 +82,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]: name: { 'type': info.get('type', 'string'), 'description': info.get('description', ''), + **( + {'items': info['items']} + if info.get('type') == 'array' and 'items' in info + else {} + ), } for name, info in tool.parameters.items() }, diff --git a/flo_ai/flo_ai/llm/openai_llm.py b/flo_ai/flo_ai/llm/openai_llm.py index 6c823bb3..383ed916 100644 --- a/flo_ai/flo_ai/llm/openai_llm.py +++ b/flo_ai/flo_ai/llm/openai_llm.py @@ -80,7 +80,15 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]: 'parameters': { 'type': 'object', 'properties': { - name: {'type': info['type'], 'description': info['description']} + name: { + 'type': info['type'], + 'description': info['description'], + **( + {'items': info['items']} + if info.get('type') == 'array' and 'items' in info + else {} + ), + } for name, info in tool.parameters.items() }, 'required': list(tool.parameters.keys()), diff --git a/flo_ai/flo_ai/models/agent.py b/flo_ai/flo_ai/models/agent.py index 22f8b526..a3b78b26 100644 --- a/flo_ai/flo_ai/models/agent.py +++ b/flo_ai/flo_ai/models/agent.py @@ -210,7 +210,10 @@ async def _run_with_tools( # Execute the tool try: function_name = function_call['name'] - function_args = json.loads(function_call['arguments']) + if isinstance(function_call['arguments'], str): + function_args = json.loads(function_call['arguments']) + else: + function_args = function_call['arguments'] tool = self.tools_dict[function_name] function_response = await tool.execute(**function_args)