Skip to content

tool_choice field not sent in API requests, causing 400 errors with strict OpenAI-compatible gateways #2804

@deutschbp

Description

@deutschbp

Summary

docker-agent does not include a tool_choice field in its Chat Completions API requests, even when tools is present. The OpenAI spec treats omission of tool_choice as implying "auto", so this is technically valid — but strict OpenAI-compatible gateway implementations (notably LiteLLM-based proxies) require the field to be explicitly present and reject requests with a 400 Bad Request when it is absent.

Error

HTTP 400: litellm.BadRequestError: BedrockException -
{"message":"The model returned the following errors: tool_choice.type: Field required"}
This error occurs on every request where tools are present, exhausting all fallback models since the validation fires before the model is reached.

Root Cause

In pkg/model/provider/openai/client.go, ChatCompletionNewParams is built without setting ToolChoice. When the request reaches a LiteLLM gateway that enforces strict Pydantic validation, the missing field causes a 400 rejection.
Per the OpenAI spec, omitting tool_choice is equivalent to "auto" — but LiteLLM in certain configurations requires the object form explicitly:
```json
"tool_choice": { "type": "auto" }
```

Proposed Fix

Explicitly send "tool_choice": "auto" whenever tools is non-empty in the request. This is:

  • Spec-compliant — it matches the OpenAI default behavior exactly
  • Backwards-compatible — no behavior change for gateways that already handle omission correctly
  • Safe for the agentic loop"auto" preserves the model's autonomy to decide when to call tools
    Optionally, expose a tool_choice: field in the model config schema (alongside the existing parallel_tool_calls) for users who need to override the value.

Workarounds

  • Gateway side: Add drop_params: true to LiteLLM's general_settings to silently accept requests missing optional fields
  • Client side: None currently available in agent.yamlprovider_opts does not forward tool_choice

Environment

  • docker-agent version: v1.59.0
  • Gateway: LiteLLM proxy (OpenAI-compatible) in front of AWS Bedrock
  • All models affected (validation fires before model routing)

Metadata

Metadata

Assignees

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