Agentflow icon indicating copy to clipboard operation
Agentflow copied to clipboard

Gemini 400 INVALID_ARGUMENT on parallel tool calls — _convert_to_google_format doesn't group consecutive tool results

Open suchith83 opened this issue 6 months ago • 0 comments

Gemini's contract: one model turn = one Content with all function_call parts → the following user turn must be a single Content whose parts are all the matching function_responses (same count, same order). The current converter breaks this whenever the agent issues parallel tool calls in a single turn.

Relevant files

  • agentflow/core/graph/agent_internal/google.py — _convert_to_google_format. Needs to group consecutive role="tool" messages into one Content(role="user", parts=[fr1, fr2, ...]) (e.g. outer while i < n + inner while messages[i].role == "tool"), and extract a _tool_response_part(msg) helper to keep the loop readable. The existing call_id_to_name map can be reused for the lookup.

Happy to send a PR.

suchith83 avatar May 30 '26 09:05 suchith83