Skip to content

perf: 113-tool JSON-schema block (~17k tokens) sent on every turn regardless of intent #407

Description

@webdevtodayjason

Summary

Every agent turn currently ships the full 113-tool registry in the system prompt as JSON-schema, regardless of whether the operator's prompt is "what are the logs at?" (zero tools needed) or "delete file X" (one filesystem tool needed). At ~150 tokens of spec per tool, that's ~17,000 tokens of tool definitions on every single turn before the operator's question is even processed.

For openai-codex (gpt-5.3-codex, gpt-5.4-mini), that adds noticeable upload time, server-side parse time, and per-turn dollar cost. For local models on Ollama, it slows context build by hundreds of milliseconds and pushes context window usage.

Evidence

  • [tony-stark] telemetry: tools=113 on every turn
  • subctl, doing a comparable OAuth + 1-tool turn, completes in ~3s — likely because it registers a much smaller set of tools per session.
  • For Argent: model time was 7.7s on a turn where only memory_recall + memory_timeline were used. The other 111 tool specs were paid for in tokens and time but never used.

Proposed fix (in order of complexity)

  1. Toolkit gating (cheapest): per-agent operator config picks which toolkits to register. Operator who never uses Composio's GitHub tools can disable that toolkit and shave its specs out. Some scaffolding for this already exists per preferComposio work — extend it to all toolkits.
  2. Intent classification (medium): pre-classify the operator's prompt with a small local model into intent buckets (filesystem / memory / web / scheduling / chat-only / etc.) and only inject the relevant toolkit's specs. Bucket "chat-only" gets zero tools.
  3. Recency-weighted retrieval (advanced): rank tools by recent usage within this session + similarity to the prompt, and inject only the top-K.

Option 1 + a sane default-disabled set for most toolkits would likely cut the typical turn from 113 tools to 10-20 tools (-85% prompt block). Option 2 + 1 together would get most turns to <5 tools.

Acceptance criteria

  • Operator can configure which toolkits to load per agent.
  • Default tool count per turn for a chat-only operator (no filesystem / no memory) drops to <10.
  • [tony-stark] tools=N telemetry reflects the per-turn injected count, not the registry size.
  • No regression: turns that need a deselected toolkit get a graceful "this tool isn't available, enable X to use it" agent response, not a silent failure.

Related

🤖 Filed from a live perf investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Fields

    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