Skip to content

"Unavailable tool" error message lists every available tool, burning thousands of tokens on repeated occurrences #41047

Description

@davzdec

Description

Related upstream trigger: #33618 (Qwen via OpenRouter sporadically emits phantom/invalid tool calls). This issue is about the cost of the error response, which is independent of that bug.

When a model emits a malformed/invalid tool call (e.g. a phantom unknown tool call, which happens occasionally with some models during parallel tool batching), the harness responds with an error message that enumerates the complete list of available tools:

The arguments provided to the tool are invalid: Model tried to call unavailable
tool 'unknown'. Available tools: <full list of 100+ tool names…>

In a session with many MCP servers configured (~130 tools in my setup), each of these error messages injects several thousand tokens into the context. The underlying model behavior can repeat dozens of times in a single session (observed with openrouter/qwen/qwen3.8-max), so this adds up to a very large amount of wasted tokens and cost — far more than the invalid call itself.

A secondary effect: when the invalid call is part of a parallel batch, sibling tool calls in the same batch sometimes get aborted ("Tool execution aborted"), forcing the agent to re-issue them — more tokens and slower progress.

Expected behavior

The error should be minimal and actionable, e.g.:

Tool 'unknown' is not available. See the system prompt for the list of available tools.

The model already has the tool list in its system prompt; repeating it in every error message provides no additional value and is very expensive.

Suggested fix

  • Truncate/omit the Available tools: … enumeration from the error message (or cap it to a short prefix / first N names).
  • Optionally, deduplicate: if the same invalid-tool error already occurred in the session, return an even shorter message on repeats.

Environment

  • opencode CLI (latest at time of writing)
  • Model: openrouter/qwen/qwen3.8-max (observed repeatedly), likely model-agnostic
  • Setup: ~130 tools configured via MCP servers (supabase, atlascloud, cloudflare, agentmemory, etc.)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions