Reduce Agent Context Cost by Loading Tools on Demand

Tool definitions use context before the model handles the user's request. The cost is small for a short tool list and can become material when every request carries many long schemas.

Measure the overhead first

  1. Serialize the exact tool definitions sent with a representative request.
  2. Measure their tokens with the tokenizer for the selected model.
  3. Separate fixed tool tokens from user, retrieval, and response tokens.
  4. Repeat the measurement for the routes that use different tool sets.

Do not infer the saving from a tool count. Names, descriptions, nested schemas, and examples can make two tools very different in size.

Use a small discovery catalog

Keep a short catalog in the initial context. Each entry needs an identifier, a plain description, and enough routing information to decide whether the tool applies. Load the complete instructions only after selection.

{
  "calculate_lcoe": {
    "description": "Calculate LCOE from submitted project assumptions",
    "input": "project assumptions"
  }
}

Keep execution bounded

  1. Select a tool from the catalog.
  2. Load its full instructions and input schema.
  3. Validate the submitted input.
  4. Run the tool with its existing permission and time limits.
  5. Validate and record the output.

Lazy loading changes context assembly. It must not weaken tool authorization, input validation, or execution limits.

Account for the trade-offs

  • Routing errors: A small catalog can omit detail that helps the model select the correct tool.
  • Added latency: Fetching instructions creates another step before execution.
  • Cache drift: Catalog metadata and full instructions need the same version.
  • Debugging: Run records must show which catalog entry and instruction version were used.

Load only the tools the task needs

If tool definitions are a meaningful part of request cost, compare a fixed tool list with catalog-based loading on the same task set. Keep the design only if selection quality remains acceptable and the measured saving exceeds the added routing cost.

More Insights

Sustainability

How to Review Water Risk for an AI Data Center

A site-diligence checklist for water sources, cooling design, permits, consumption, and operating limits.

AI Architecture

Why AI Analysis Still Needs Explicit Human Approval

How specialist analysis, review records, approval authority, and external action stay separate.

Industry

What Tapestry Can and Cannot Tell a Data Center Investor

What the public Tapestry and PJM record establishes, and what site power diligence still requires.

Investment

How to Use Prediction-Market Odds Without Treating Them as Facts

A review method for contract terms, liquidity, timestamps, resolution risk, and source reporting.

Compliance

What the EU AI Act Says About Model Energy Use

A correction on general-purpose model documentation, energy estimates, scope, and application dates.

AI Architecture

Why Infrastructure Review Uses Specialist Lenses

How GreenCIO routes a question, records its sources, and leaves trade-offs with the human reviewer.

Finance

What LCOE Shows, and What It Leaves Out

How LCOE normalizes project cost, which assumptions drive it, and which risks need separate review.

Sustainability

When Carbon-Aware Scheduling Helps, and When It Does Not

How to review movable workloads, grid data, deadlines, baselines, and reporting before claiming a saving.

Technical

How a News URL Becomes a Feed Record

The bounded extraction, scoring, validation, and storage path behind each submitted source URL.

Investment

How to Review Power Risk in AI Data Center Investments

A source-based framework for power delivery, upgrades, tariffs, cooling, and schedule risk.

Finance

Who Finances Hyperscale Data Centers? A Diligence Guide

Review the contracts, funding layers, and operating dependencies behind a hyperscale project.

Sustainability

A Practical Sustainability Screen for AI Infrastructure

A review checklist for workload energy, power sources, cooling, water, hardware use, and evidence.