Multi turn tool usage with Gemini + OpenAI

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.

Hi,
AFAIK, it’s not operational yet.
The team is aware of this and hopefully supports this soon. Right now, it works with a single Tool only.

Understood thanks, will be looking for this!

Hello, for now this prevents me from swapping with OpenAI/Anthropic for my use case. Is there a way to be notified once the feature is available? Thank you

Hi, not that I’m aware of.
I usually follow the responsible Googlers’ accounts on social media.

1 Like