Skip to content

Commit db30b6e

Browse files
fixed tool calling array args to allow items (#131)
- also fixed json parsing of function_call['arguments'] in agent
1 parent f043801 commit db30b6e

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

flo_ai/flo_ai/llm/anthropic_llm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]:
9595
name: {
9696
'type': info.get('type', 'string'),
9797
'description': info.get('description', ''),
98+
**(
99+
{'items': info['items']}
100+
if info.get('type') == 'array' and 'items' in info
101+
else {}
102+
),
98103
}
99104
for name, info in tool.parameters.items()
100105
},

flo_ai/flo_ai/llm/gemini_llm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]:
106106
name: {
107107
'type': info.get('type', 'string'),
108108
'description': info.get('description', ''),
109+
**(
110+
{'items': info['items']}
111+
if info.get('type') == 'array' and 'items' in info
112+
else {}
113+
),
109114
}
110115
for name, info in tool.parameters.items()
111116
},

flo_ai/flo_ai/llm/ollama_llm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]:
8282
name: {
8383
'type': info.get('type', 'string'),
8484
'description': info.get('description', ''),
85+
**(
86+
{'items': info['items']}
87+
if info.get('type') == 'array' and 'items' in info
88+
else {}
89+
),
8590
}
8691
for name, info in tool.parameters.items()
8792
},

flo_ai/flo_ai/llm/openai_llm.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ def format_tool_for_llm(self, tool: 'Tool') -> Dict[str, Any]:
8080
'parameters': {
8181
'type': 'object',
8282
'properties': {
83-
name: {'type': info['type'], 'description': info['description']}
83+
name: {
84+
'type': info['type'],
85+
'description': info['description'],
86+
**(
87+
{'items': info['items']}
88+
if info.get('type') == 'array' and 'items' in info
89+
else {}
90+
),
91+
}
8492
for name, info in tool.parameters.items()
8593
},
8694
'required': list(tool.parameters.keys()),

flo_ai/flo_ai/models/agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ async def _run_with_tools(
210210
# Execute the tool
211211
try:
212212
function_name = function_call['name']
213-
function_args = json.loads(function_call['arguments'])
213+
if isinstance(function_call['arguments'], str):
214+
function_args = json.loads(function_call['arguments'])
215+
else:
216+
function_args = function_call['arguments']
214217

215218
tool = self.tools_dict[function_name]
216219
function_response = await tool.execute(**function_args)

0 commit comments

Comments
 (0)