Back to library
AI
tutorial

Clean Up Agent Context Using Web Search Parameters

Optimize agent memory by dropping redundant web search blocks.

Implement the `response_inclusion` parameter in Claude’s web search tools to automatically remove unnecessary data from API responses.

Claude

The Scenario

You are building a research agent that performs multiple consecutive web searches. You want to keep the conversation history clean so the agent stays focused on the findings rather than re-reading the raw HTML results.

Before & after

The old way

Developers previously had to write custom scripts to parse and 'clean' the search result blocks out of the AI's response history to prevent context clutter. This took 20–30 minutes of coding and testing.

With AI

By passing the `response_inclusion` parameter in the Web Search/Fetch tools, the AI drops redundant data from the API response. This streamlines the agent's logic in 2–3 minutes.

The Prompt

// Use the new web search tool parameter to optimize agent context
{
  "tools": [{
    "name": "web_search_20260318",
    "parameters": {
      "query": "[SEARCH_QUERY]",
      "response_inclusion": "drop_consumed_blocks"
    }
  }]
}

The latest Web Search and Web Fetch tools (`web_search_20260318`) allow for more efficient agentic workflows by dropping consumed result blocks. This prevents the context window from becoming bloated with raw search data that the agent has already processed.

Source

Claude Platform - Claude API Docs
"adding a response_inclusion parameter to drop consumed result blocks from the API response for agentic workflows."