Reduce Agent Context Cost by Loading Tools on Demand
Every tool schema injected into a prompt consumes input tokens before the model reads the user's question. Measure that overhead first, then load full schemas only when a task selects them.
1. Measure actual schema tokens before optimizing
Do not estimate overhead from tool count—nested parameters and examples vary wildly. Serialize the exact tool payload for a representative request, count tokens with the target model's tokenizer, and separate fixed tool overhead from user, retrieval, and output tokens.
2. Keep a minimal discovery catalog in initial context
{
"calculate_lcoe": {
"description": "Calculate LCOE from submitted project assumptions",
"input": "project assumptions"
}
}3. Preserve strict execution boundaries
- 1Select a candidate tool from the compact discovery catalog.
- 2Fetch its full instruction set and JSON input schema.
- 3Validate arguments against the schema before execution.
- 4Run under existing permission scopes and timeouts.
- 5Log catalog version, schema version, and validated output.
4. Trade-offs to benchmark on the same eval set
Routing misses
Keep descriptions concrete enough to disambiguate overlapping tools.
Extra round-trip
Measure whether added routing latency offsets token savings.
Schema drift
Version catalog entries and full instructions together.
Auditability
Persist exact catalog and instruction versions in run logs.
Related articles
How a News URL Becomes a Feed Record
Bounded HTML extraction, deterministic identity, and GCS generation-checked writes.
How to Review Water Risk for an AI Data Center
Separate withdrawal from consumption, match cooling mode to climate, and verify local permits.
Why AI Analysis Still Needs Explicit Human Approval
Keep generation, run records, approval authority, and external action strictly separate.