Skip to content

fix(agent): add missing name field to tool messages for Gemini compatibility#16583

Open
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/tool-message-name-field
Open

fix(agent): add missing name field to tool messages for Gemini compatibility#16583
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/tool-message-name-field

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Fixes #16478

Problem

All tool result messages (role: "tool") were missing the required name field. While OpenAI's API tolerates this, Gemini and other strict OpenAI-compatible providers return HTTP 400 when name is absent.

Root Cause

The tool message dicts in run_agent.py only included role, content, and tool_call_id, but omitted the name field that identifies which function the tool response belongs to.

Fix

Added "name": <function_name> to all 9 tool message construction sites in run_agent.py:

  1. Context sanitizer stub (line ~4716) — pre-call gap-filler
  2. Argument repair insertion (line ~8248) — corrupted JSON repair
  3. Parallel pre-flight interrupt (line ~8568) — user interrupt during parallel
  4. Parallel execution result (line ~8834) — main parallel tool result
  5. Sequential interrupt mid-tool (line ~8872) — user interrupt during sequential
  6. Sequential execution result (line ~9199) — main sequential tool result
  7. Sequential interrupt after-tool (line ~9227) — user interrupt after partial completion
  8. Invalid tool name error (line ~12059) — unknown tool self-correction
  9. Invalid JSON args error (line ~12151) — malformed arguments self-correction

Testing

  • All 10 role: "tool" messages now include the name field
  • Syntax verified with ast.parse() on the full file
  • No functional changes to tool execution logic — only message formatting

…ibility

All tool result messages (role: "tool") were missing the required name
field. While OpenAI tolerates this, Gemini and other strict
OpenAI-compatible providers return HTTP 400 when name is absent.

Fixes NousResearch#16478
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/gemini Google Gemini (AI Studio, Cloud Code) labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #16482 — both add missing name field to role:tool messages in run_agent.py for Gemini compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Missing name field in tool messages causes Gemini API HTTP 400

2 participants