Skip to content

todoListMiddleware produces ToolMessages without name, breaking Gemini (400 InvalidArgument) #10705

@JadenKim-dev

Description

Description

todoListMiddleware emits ToolMessages for write_todos without setting name. Google Gemini requires name on function responses and rejects the request with HTTP 400. Because the ToolMessage persists in history, every subsequent turn in the session keeps failing.

Anthropic and OpenAI accept the missing field, so the bug only surfaces on Gemini.

Affected code

Two call sites in libs/langchain/src/agents/middleware/todoListMiddleware.ts:

  1. Successful write_todos result (≈ line 312).
  2. Parallel-call error branch in afterModel (≈ line 382).

Every other ToolMessage producer in the package (ToolNode, hitl, toolCallLimit, toolRetry, toolEmulator, contextEditing, pii) already sets name.

Reproduction

  1. Build createAgent with middleware: [todoListMiddleware()] and a Gemini chat model.
  2. Prompt the agent to trigger write_todos.
  3. Send any follow-up — the Gemini call returns 400, and every later turn fails too.

Proposed fix

Set name: "write_todos" at both ToolMessage constructions, with regression tests asserting name is set on both the success and parallel-rejection paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions