K5.1.3 Task 5.1

40 Fields Returned, 5 Needed — Context Full After 4 Calls Instead of 11

An order lookup tool returns 40+ fields. The agent needs 5 for a return request. After 3 calls, the context is nearly full — 78% consumed by irrelevant fields like internal_notes, warehouse_code, and supplier_contact that the agent never uses.

Filter tool output to relevant fields before appending to context. Task completion rate jumps from 52% to 94%.

The Numbers

Across 500 agent sessions averaging 8 tool calls:

ApproachTokens per callTotal tool tokensContext left
Full output (40+ fields)~2,00016,000 (80%)4,000
Filtered (5-8 fields)~3002,400 (12%)17,600

Filtering saves 13,600 tokens per session — 68% of the total context budget. The agent goes from 4.2 tool calls before exhaustion to 11.8 calls.

How to Filter

Programmatic field filtering — Before appending tool output to context, extract only the fields the current task needs. For a return request: order_status, order_date, items, total, return_eligible. Drop the other 35+ fields.

This is more reliable than model summarization, which may generalize precise values (“$127.50” → “refund amount”). Programmatic filtering preserves exact data — only irrelevant fields are removed.

Context-aware filtering — Different task types need different fields from the same tool. Returns need status and eligibility. Billing needs payment method and invoices. Shipping needs tracking and fulfillment center. Define field relevance rules per task type in configuration — the filtering adapts automatically without code changes.

PostToolUse hooks — Intercept tool output before it enters the conversation context. The hook applies the filtering rules and returns only the relevant subset.

The “Might Need It Later” Argument

A colleague proposes keeping full output because “the model might need any field for follow-up questions we haven’t anticipated.”

This trades a definite problem (context exhaustion after 4 calls) for a hypothetical one (unexpected field needed). The solution: filter aggressively now, re-call the tool if an unexpected field is needed later. One additional tool call is cheaper than permanently storing 35 irrelevant fields in context.

What Does Not Work

Larger context windows. Delays the problem without solving it. 40+ fields per call still wastes context at any window size.

Model-generated summaries. Summaries may lose precise values (amounts, IDs, dates) from tool output. Programmatic filtering preserves exact data with certainty.

Limiting tool call count. Restricts the agent’s capability. The issue is output size per call, not call frequency.

Hoping the model ignores irrelevant fields. All content in context influences the model’s attention. Irrelevant fields do not get reliably ignored — they dilute attention on relevant data. Removing them before context insertion is the only reliable approach.


One-liner: Filter tool output to relevant fields before appending to context — this frees 68% of the context budget, enables 3x more tool calls, and raises task completion from 52% to 94%.