An agent makes many order lookups, each returning 40 fields, and only 5 fields ever matter. Long sessions hit context limits. What is the best fix?
Why B is the answer
Trim tool results to the relevant fields before they enter the conversation
Tool output consumes context whether or not the model uses it. Pruning before it accumulates is the direct fix. max_tokens limits the reply, not the input.
In detail
- Tool output stays in the conversation and is sent again on later turns.
- Fields that are never used still consume context.
- Trimming results in your code, before they enter the conversation, removes the cost at its source.
- Add a way to request more detail for the rare case that needs it.
Use case
An illustrative scenario, not a real incident.
An order agent receives 40 fields per lookup and hits limits in long chats. A small function keeps order ID, status, date, total and address, and the sessions finish comfortably.
See it in different ways
flowchart LR A["Tool returns 40 fields"] --> B["Keep the 5 that matter"] B --> C["Add to the conversation"] C --> D["Context stays small"]
sequenceDiagram participant A as Your code participant C as Claude A->>C: Request with tools C-->>A: tool_use blocks A->>A: Run the tools A->>C: tool_result blocks first, then any text C-->>A: Final answer
flowchart LR S0["Tool returns 40 fields"] --> S1["Your code keeps 5"] --> S2["Result enters context"] --> S3["Later turns stay small"]
Key point: Trim tool results before they enter the conversation.
Why the other options are wrong
- A. Raise max_tokens on each request so the model has more room to work with
- max_tokens limits the reply, not what the conversation holds.
- C. Ask the model in the system prompt to ignore the fields it does not need
- The fields would still be in context, even if the model ignores them.
- D. Restart the conversation every ten turns and drop the earlier history
- Restarting loses useful history along with the noise.

