How do I implement multi turn with tools? I’m using the simple example from the docs and it doesn’t seem to be able to handle it at all.
b’[{\n “error”: {\n “code”: 400,\n “message”: “Request contains an invalid argument.”,\n “status”: “INVALID_ARGUMENT”\n }\n}\n]’
{‘max_tokens’: 8192,
‘messages’: [{‘content’: “What’s the weather like in Chicago today?”,
‘role’: ‘user’},
{‘role’: ‘assistant’,
‘tool_calls’: [{‘function’: {‘arguments’: '{“location”: ’
‘“Chicago, IL”}’,
‘name’: ‘get_weather’},
‘id’: ‘0’,
‘type’: ‘function’}]},
{‘content’: ‘Sunny. Always Sunny.’,
‘role’: ‘assistant’,
‘tool_call_id’: ‘0’}],
‘model’: ‘gemini-1.5-flash’,
‘stream’: True,
‘stream_options’: {‘include_usage’: True},
‘temperature’: 0.5,
‘tool_choice’: ‘any’,
‘tools’: [{‘function’: {‘description’: ‘Get the weather in a given location’,
‘name’: ‘get_weather’,
‘parameters’: {‘properties’: {‘location’: {‘description’: 'The ’
'city ’
'and ’
'state, ’
'e.g. ’
'Chicago, ’
‘IL’,
‘type’: ‘string’},
‘unit’: {‘enum’: [‘celsius’,
‘fahrenheit’],
‘type’: ‘string’}},
‘required’: [‘location’],
‘type’: ‘object’}},
‘type’: ‘function’}],
‘top_p’: 0.5}
The messages I’m sending specifically:
[{‘content’: “What’s the weather like in Chicago today?”, ‘role’: ‘user’},
{‘role’: ‘assistant’,
‘tool_calls’: [{‘function’: {‘arguments’: ‘{“location”: “Chicago, IL”}’,
‘name’: ‘get_weather’},
‘id’: ‘0’,
‘type’: ‘function’}]},
{‘content’: ‘Sunny. Always Sunny.’, ‘role’: ‘tool’, ‘tool_call_id’: ‘0’}]
It’s able to make the tool call just fine, but carrying on after the response seems to break.
As soon as I add the tool response like in OpenAI, OpenRouter etc it breaks with a 400 invalid argument. Also is the muti-tool issue fixed? We can’t use this layer in prod until both of these situations work unfortunately.