The Problem
Multi-step agents that perform web searches accumulate large context payloads. A research agent that searches 5 times generates 15-30KB of search results. When passed to the next agent step, this context can overflow the context window or push out important earlier context (conversation history, system prompts, tool definitions). The agent starts losing track of its task because search results crowd out task instructions.
The Scavio Solution
Build a context bridge that compresses search results between agent steps using structured JSON serialization. After each search step, extract only the fields the next step needs (titles+links for citation, snippets for reasoning, prices for comparison) and discard the rest. Store full results in a sidecar JSON file for retrieval if detailed data is needed later.
Before
Before the context bridge, the research agent's context window filled after 3 searches. By step 5, earlier conversation context was truncated, and the agent forgot its original task instructions.
After
After implementing the bridge, search context is compressed from ~5KB per search to ~300 bytes of extracted key facts. The agent maintains full task awareness through 10+ search steps, with full results available in sidecar storage for on-demand retrieval.
Who It Is For
Agent developers building multi-step research workflows that hit context window limits. Teams optimizing agent performance by reducing irrelevant context passed between reasoning steps.
Key Benefits
- 90% reduction in search context size between agent steps
- Agent maintains task awareness across many search iterations
- Full results preserved in sidecar storage for detailed retrieval
- Configurable extraction per step: only pass fields the next step needs
- Works with any agent framework that supports tool calls
Python Example
import requests
import json
from pathlib import Path
API_KEY = "your_scavio_api_key"
def search_and_compress(query: str, platform: str = "google", extract_fields: list[str] = None) -> dict:
"""Search and return compressed results for agent context."""
if extract_fields is None:
extract_fields = ["title", "snippet", "link"]
res = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": platform, "query": query},
timeout=15,
)
res.raise_for_status()
data = res.json()
# Store full results in sidecar
sidecar_path = Path(f"/tmp/search_sidecar_{hash(query)}.json")
sidecar_path.write_text(json.dumps(data, indent=2))
# Compress for agent context
compressed = []
for r in data.get("organic", [])[:5]:
entry = {k: r.get(k, "") for k in extract_fields if k in r}
compressed.append(entry)
return {
"query": query,
"result_count": len(compressed),
"results": compressed,
"sidecar": str(sidecar_path),
}
def bridge_for_comparison(query_a: str, query_b: str) -> dict:
"""Search two queries, return only price/title for comparison step."""
a = search_and_compress(query_a, "amazon", ["title", "price"])
b = search_and_compress(query_b, "amazon", ["title", "price"])
return {"comparison": {"a": a, "b": b}}
result = search_and_compress("best search api 2026", "google", ["title", "link"])
print(f"Compressed: {len(json.dumps(result))} bytes vs ~5000 bytes full")
for r in result["results"]:
print(f" {r['title']}")JavaScript Example
const API_KEY = "your_scavio_api_key";
import { writeFileSync } from "fs";
async function searchAndCompress(query, platform = "google", fields = ["title", "snippet", "link"]) {
const res = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": API_KEY, "content-type": "application/json" },
body: JSON.stringify({ platform, query }),
});
if (!res.ok) throw new Error(`scavio ${res.status}`);
const data = await res.json();
// Store full results in sidecar
const sidecarPath = `/tmp/search_sidecar_${query.replace(/\s/g, "_")}.json`;
writeFileSync(sidecarPath, JSON.stringify(data, null, 2));
// Compress for context
const compressed = (data.organic ?? []).slice(0, 5).map((r) => {
const entry = {};
for (const f of fields) if (r[f] !== undefined) entry[f] = r[f];
return entry;
});
return { query, resultCount: compressed.length, results: compressed, sidecar: sidecarPath };
}
const result = await searchAndCompress("best search api 2026", "google", ["title", "link"]);
console.log(`Compressed: ${JSON.stringify(result).length} bytes`);
for (const r of result.results) console.log(` ${r.title}`);Platforms Used
Web search with knowledge graph, PAA, and AI overviews
Amazon
Product search with prices, ratings, and reviews
Community, posts & threaded comments from any subreddit