Resumen
Agent teams know their total LLM spend pero rarely know como mucho cada herramienta call contributes. Este flujo de trabajo audits el token cost of search-augmented agent calls by measuring context tamano antes de y despues de search injection. It identifies cual consultas produce oversized contexts, cual herramienta calls return low-value resultados, y donde structured search podria replace raw pagina obtiene to cut costs.
Desencadenador
Cron programar (semanal Monday at 7 AM UTC)
Programación
Semanal Monday at 7 AM UTC
Pasos del flujo de trabajo
Recopilar agent registros
Pull el past week's agent interaction registros including herramienta calls, context sizes, y consultas de busqueda.
Measure search context tokens
For cada search-related herramienta call, calcular el token conteo of el injected search context.
Benchmark contra structured search
Re-run un sample of consultas a traves de Scavio's structured API. Comparar token conteo of structured resultados versus el original context.
Calcular savings potential
Estimate semanal token y cost savings if todos search contexts usado structured resultados.
Identificar worst offenders
Clasificar consultas by context tamano. Marcar el top 10 mas expensive search-grounded calls.
Generar audit informe
Crear un resumen con total search token spend, savings potential, y especifico consultas to optimizar.
Implementacion en Python
import requests, os, json
H = {"x-api-key": os.environ["SCAVIO_API_KEY"]}
def audit_query(query, platform="google"):
"""Compare structured API context size vs typical raw page fetch."""
r = requests.post("https://api.scavio.dev/api/v1/search", headers=H,
json={"platform": platform, "query": query}, timeout=10).json()
structured_context = ""
for o in r.get("organic", [])[:5]:
structured_context += f"{o.get('title')}: {o.get('snippet')}\n"
structured_tokens = len(structured_context) // 4
estimated_raw_tokens = 8000 * 5 # typical 5-page raw fetch
return {
"query": query,
"structured_tokens": structured_tokens,
"estimated_raw_tokens": estimated_raw_tokens,
"savings_pct": round((1 - structured_tokens / estimated_raw_tokens) * 100, 1),
"savings_tokens": estimated_raw_tokens - structured_tokens
}
SAMPLE_QUERIES = [
"best search api for agents 2026",
"how to reduce llm token cost",
"search api pricing comparison"
]
total_savings = 0
for q in SAMPLE_QUERIES:
result = audit_query(q)
total_savings += result["savings_tokens"]
print(json.dumps(result))
print(f"\nTotal token savings across sample: {total_savings:,}")Implementacion en JavaScript
const H = {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"};
async function auditQuery(query, platform = "google") {
const r = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST", headers: H,
body: JSON.stringify({platform, query})
}).then(r => r.json());
let ctx = "";
for (const o of (r.organic || []).slice(0, 5)) {
ctx += o.title + ": " + o.snippet + "\n";
}
const structuredTokens = Math.ceil(ctx.length / 4);
const rawTokens = 8000 * 5;
return {
query, structuredTokens, estimatedRawTokens: rawTokens,
savingsPct: Math.round((1 - structuredTokens / rawTokens) * 1000) / 10,
savingsTokens: rawTokens - structuredTokens
};
}Plataformas utilizadas
Búsqueda web con grafo de conocimiento, PAA y resúmenes de IA
Comunidad, publicaciones y comentarios en hilos de cualquier subreddit
YouTube
Búsqueda de videos con transcripciones y metadatos