Skip to content

[FEATURE]: Expose toolChoice as a configurable agent option in opencode.json #14090

@pentaxis93

Description

@pentaxis93

Summary

OpenCode's streamText call in src/session/llm.ts never passes toolChoice, so the Vercel AI SDK defaults to { type: "auto" } for all models. There is currently no way for users to configure this — not through opencode.json agent options, not through the additional passthrough (which routes to providerOptions, not toolChoice).

This matters most for OpenAI models. GPT's RLHF prior defaults to conversational text response; tool calling is additive. With tool_choice: "auto", GPT is free to narrate intended tool use instead of executing it — a failure mode that makes autonomous agentic sessions unreliable.

Root cause (from source)

src/session/llm.tstoolChoice is absent from the streamText call:

const result = streamText({
  model,
  messages,
  tools,
  // toolChoice is never set — defaults to { type: "auto" }
  maxSteps: ...,
  ...
})

src/config/config.ts — agent additional options flow to providerOptions, not toolChoice:

// extras from agent.options go here:
experimental_providerMetadata: { ... }
// toolChoice is a separate, first-class streamText parameter

Requested change

Add a tool_choice field to the agent config schema that maps directly to the toolChoice parameter of streamText:

// opencode.json
{
  "agents": {
    "my-agent": {
      "model": "openai/gpt-4.1",
      "tool_choice": "required"
    }
  }
}

Accepted values should follow the Vercel AI SDK's toolChoice type: "auto" (default, current behaviour), "required", "none", or { type: "tool", toolName: "..." }.

Why this matters

The Vercel AI SDK already supports toolChoice: "required" — OpenCode just never exposes it. This is the canonical fix for GPT models that default to text response instead of calling tools. OpenAI's own agentic system prompt guide calls out this failure mode explicitly and recommends tool_choice: "required" as the API-level solution.

Workarounds (stronger system prompts) help but are model-specific and fragile. A first-class config option would let users opt into reliable tool use on a per-agent basis, without touching prompt engineering.

Vercel AI SDK reference

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

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