Resumen
LLM agents consume thousands of tokens per search resultado cuando they recibir raw HTML o full fragmentos. Este flujo de trabajo pre-processes resultados de busqueda en structured JSON con solo el campos el agent necesita, reducing token consumption by 60-80% per search call.
Desencadenador
On agent search solicitud (middleware)
Programación
On cada agent search call (middleware)
Pasos del flujo de trabajo
Intercept agent consulta de busqueda
Catch el search solicitud de el agent antes de it hits el API, extracting el consulta y el campos el agent actually necesita.
Ejecutar structured search
Enviar el consulta to el search API requesting solo esencial campos: titulo, fragmento, enlace. Exclude raw HTML, metadata, y auxiliary datos.
Compress resultados
Truncate fragmentos to 100 characters, limite to top 3 resultados, y formato as un minimal JSON objeto.
Return to agent
Pass el compressed resultados back to el agent context window, registro el token savings for monitoreo.
Implementacion en Python
import requests, os, json
H = {"x-api-key": os.environ["SCAVIO_API_KEY"], "Content-Type": "application/json"}
def optimized_search(query, max_results=3, snippet_len=100):
r = requests.post("https://api.scavio.dev/api/v1/search", headers=H,
json={"platform": "google", "query": query}).json()
results = []
for o in r.get("organic", [])[:max_results]:
results.append({
"title": o.get("title", ""),
"snippet": o.get("snippet", "")[:snippet_len],
"url": o.get("link", ""),
})
compressed = json.dumps(results)
raw_size = len(json.dumps(r))
print(f"Token savings: {raw_size} -> {len(compressed)} chars ({round((1-len(compressed)/raw_size)*100)}% reduction)")
return results
results = optimized_search("n8n search API integration 2026")
for r in results:
print(f" {r['title'][:50]}")Implementacion en JavaScript
const H = {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"};
async function optimizedSearch(query, maxResults = 3, snippetLen = 100) {
const r = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST", headers: H,
body: JSON.stringify({platform: "google", query})
}).then(r => r.json());
const results = (r.organic || []).slice(0, maxResults).map(o => ({
title: o.title || "",
snippet: (o.snippet || "").slice(0, snippetLen),
url: o.link || "",
}));
const rawSize = JSON.stringify(r).length;
const compressedSize = JSON.stringify(results).length;
console.log(`Token savings: ${rawSize} -> ${compressedSize} chars (${Math.round((1-compressedSize/rawSize)*100)}% reduction)`);
return results;
}
optimizedSearch("n8n search API integration 2026").then(r =>
r.forEach(o => console.log(` ${o.title.slice(0, 50)}`))
);Plataformas utilizadas
Búsqueda web con grafo de conocimiento, PAA y resúmenes de IA