Skip to content

[Tool Intelligence Runtime] Enforce cumulative schema-context budgets for dynamically discovered tools #286

Closed

Description

@gaobrian

Priority

P1 — prompt-cost control and predictable runtime behavior.

Current implementation

A single find_tool result is bounded: it describes at most five tools and prices the schemas against a 4,096-byte budget. The ReAct engine then calls reveal_tools, which adds each returned schema to the live context. The context's add_tool implementation deduplicates by tool name, but the discovery path has no explicit cumulative budget or active-schema lifecycle of its own.

Problem

Per-search limits do not bound the total number or token cost of schemas revealed over a multi-step task. A model can issue multiple different searches and progressively grow the live tool array. This can increase prompt cost, reduce attention and make request-size behavior unpredictable even though every individual search is bounded.

Requirement

Add a task/turn-scoped dynamic tool-schema budget and lifecycle manager. It must account for the actual schemas added to model requests, not only the bytes returned by one search.

Acceptance criteria

  • Define configurable per-tool and cumulative per-turn/task schema budgets, with a safe default.
  • Measure the serialized schema and description cost using the same representation sent to the model; expose byte and estimated-token accounting.
  • Repeated discovery of the same stable capability/version is idempotent and does not spend budget twice.
  • A new version or changed schema is treated as a new revision and cannot silently reuse stale definitions.
  • When the budget is exhausted, return an explicit bounded result explaining the limit and how to continue; never silently omit a selected schema.
  • Keep only schemas relevant to the current execution scope; define when discovered definitions expire or are removed.
  • Ensure dynamic schemas do not leak into later tasks, sessions or unrelated concurrent runs.
  • Preserve deterministic ordering for provider/KV cache stability.
  • Add tests for repeated searches, many distinct searches, large schemas, schema revision, budget exhaustion, concurrent tasks and turn cleanup.
  • Report prompt-byte/token reduction and task success against the current behavior.

Non-goals

  • Do not reduce the existing safety validation or tool output cap.
  • Do not make the model's tool list an authorization mechanism.

References

  • crates/agent/src/agent/agentic/discovery.rs — per-search budget
  • crates/react/src/engine/mod.rs — reveal_tools
  • crates/agent/src/agent/context.rs — context tool deduplication

Activity

  1. gaobrian commented on Nov 11, 2026

    @gaobrian
    ContributorAuthor

    Implemented in the unified intelligence runtime change: goal fencing and localized round limits, metadata-only Skill indexing, task-scoped Skill runtime with request-scoped instruction composition, dependency/conflict resolution, provenance/trust enforcement, governed federated metadata discovery, an offline activation benchmark, metadata-aware tool retrieval, per-turn schema budgets, and turn-correlated discovery/selection telemetry. See docs/bsh-intelligence-runtime.md for the contracts and coverage. Verified by the agent, react and bsh test suites plus clippy.

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

Metadata

Metadata

Assignees

No one assigned

    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