Skip to content

fix: cap active tools for providers with tool count limits#18916

Open
Svtter wants to merge 2 commits intoanomalyco:devfrom
Svtter:fix/tool-limit-cap
Open

fix: cap active tools for providers with tool count limits#18916
Svtter wants to merge 2 commits intoanomalyco:devfrom
Svtter:fix/tool-limit-cap

Conversation

@Svtter
Copy link
Copy Markdown

@Svtter Svtter commented Mar 24, 2026

Issue for this PR

Fixes #17405
Split from #18635

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR contains the tool-limit work split out from #18635.

It includes:

  • model/provider support for limit.tools
  • xAI fallback tool caps when model metadata does not provide one
  • runtime tool capping in the LLM layer
  • a user-facing warning when tools are capped
  • a fix to preserve explicit tools: 0 values instead of treating them as missing

These changes are intended to reduce oversized tool payloads for providers like xAI/Grok that fail when too many tools are exposed in one turn.

How did you verify your code works?

  • cd packages/opencode && bun typecheck
  • cd packages/opencode && bun test test/provider/provider.test.ts

Screenshots / recordings

N/A - backend/provider behavior, no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Brendan DeBeasi and others added 2 commits March 24, 2026 18:19
Some providers (e.g. xAI) enforce undocumented tool count limits.
Add limit.tools to model schema and cap activeTools in streamText
when the total exceeds the provider limit, prioritizing built-in
tools over MCP tools.
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xAI/Grok requests fail with 'grammar is too complex' when tool payloads are oversized

1 participant