Skip to content

Combining tools (Function Calling) and outputSchema causes infinite request loops #411

@b2rpt

Description

@b2rpt

Describe the bug
In @google/adk (v1.1.0), combining outputSchema (which configures the model to enforce strict JSON structure using responseMimeType: 'application/json' ) and tools (Function Calling) in an LlmAgent causes a conflict in the Gemini API interaction:

  1. Under gemini-3.1-flash-lite (preview): The agent gets stuck in an infinite tool-invocation / model-request loop. It keeps logging Sending out
    request, model: gemini-3.1-flash-lite, backend: GEMINI_API, stream: false repeatedly without ever completing the user's turn.

  2. Under stable models (e.g. gemini-2.5-flash / gemini-1.5-flash ): The request crashes immediately with a 400 Bad Request API error because Gemini
    API natively does not support mixing function calling ( tools ) and strict JSON output mode ( responseMimeType: 'application/json' ) in the same model
    turn.

To Reproduce

  1. Initialize a clean ADK project.
  2. Put the self-contained code in bug.ts .
  3. Run the agent using the ADK CLI:
    npx adk run bug.ts
  4. Query the agent with: london
  5. Observe the infinite looping requests:
    WARN: [ADK] 2026-06-06T09:26:34.060Z Invalid config for agent bug_reproduce_agent: outputSchema cannot co-exist with agent transfer configurations.
    Setting disallowTransferToParent=true, disallowTransferToPeers=true
    Running agent bug_reproduce_agent, type exit to exit.
    [user]: london
    INFO: [ADK] 2026-06-06T09:26:48.076Z event: {"invocationId":"e-4954e5ed-13c6-4ffb-a092-5a5b75de799e","author":"user","actions":{"stateDelta":{},
    "artifactDelta":{},"requestedAuthConfigs":{},"requestedToolConfirmations":{}},"content":{"role":"user","parts":[{"text":"london"}]},"id":"E3m08jq3",
    "longRunningToolIds":[],"timestamp":1780738008075}
    INFO: [ADK] 2026-06-06T09:26:48.082Z Sending out request, model: gemini-3.1-flash-lite, backend: GEMINI_API, stream: false
    INFO: [ADK] 2026-06-06T09:26:51.523Z Sending out request, model: gemini-3.1-flash-lite, backend: GEMINI_API, stream: false
    INFO: [ADK] 2026-06-06T09:26:59.183Z Sending out request, model: gemini-3.1-flash-lite, backend: GEMINI_API, stream: false
    INFO: [ADK] 2026-06-06T09:27:01.394Z Sending out request, model: gemini-3.1-flash-lite, backend: GEMINI_API, stream: false
    ... (continues infinitely)
Image

Expected behavior
The ADK framework should either:

• Two-stage validation: Execute tool calling turns normally, then execute a final completion turn requesting the structured output schema (applying
outputSchema formatting rules only at the final step once no more tool calls are pending).
• Warning/Crash Mitigation: Throw a clear validation error during initialization if an agent is configured with both tools and outputSchema ,
preventing execution and advising the user to format using custom prompts.

Desktop / Environment

• OS: Windows 11
• Node.js: v24.15.0
• ADK version: @google/adk: ^1.1.0
• Model: gemini-3.1-flash-lite (also reproducible with gemini-2.5-flash resulting in 400 Bad Request errors)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds review[Status] The PR/issue is awaiting review from the maintainer

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions