Skip to content

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

Closed

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.ts — toolChoice 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

Activity

  1. pentaxis93 commented on Feb 18, 2026

    @pentaxis93
    Author

    Filed in error — wrong repository.

  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 18, 2026
  3. github-actions commented on Feb 18, 2026

    @github-actions
    Contributor

    This issue appears to be a duplicate of #14090, which was closed as it was filed in error in the wrong repository. Please ensure this is the correct repository for this feature request.

    If you have questions or need assistance, feel free to reach out to the maintainers.

  4. github-actions commented on Apr 20, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions