Context Engineering

Your agent just fetched
10,000 records. Now what?

Three approaches to handling large API payloads in agent workflows. One costs 1,000x more than the other. The formula is visible.

Approach 1

Raw Context

Stuff the entire API response into the agent's context window.

// Agent receives the full payload
{
  "results": [
    {"Id": "00Q000000001", "Company": "Acme Corp", ...},
    {"Id": "00Q000000002", "Company": "Globex Inc", ...},
    ... 9,998 more records ...
    // ~7.5 MB of JSON → ~1.9M tokens
  ]
}
~1,880,000 tokens
Cost (Opus) $28.23
Turns 1
Exceeds context Hallucinations
payload_bytes / 4 × $15/1M = $28.23
Approach 2

Roll Your Own

Agent writes filter code across multiple turns. Or build custom hooks/scripts.

// Turn 1: Agent inspects a sample
// Turn 2: Writes Python filter
leads = [l for l in data
         if l["State"] == "California"
         and parse(l["CreatedDate"]) > cutoff]
leads.sort(key=lambda x: x["LeadScore"], reverse=True)
result = leads[:5]
// Turn 3: Verify and format output
~3,300 tokens
Cost (Opus) $0.15
Turns 3
Accurate Multi-turn No reuse
(inspect + codegen + verify) × $15/1M = $0.15
Approach 3

DataGrout

Deterministic tools extract exactly what the agent needs. Zero LLM credits.

// Single MCP tool call chain
{
  "name": "data-grout@1/frame.filter@1",
  "arguments": {
    "cache_ref": "rc_leads_abc123",
    "where": {"State": "California"}
  }
}
// → frame.sort → frame.slice → frame.select
// Result: 5 records, 6 fields = ~340 tokens
~340 tokens
Cost (Opus) $0.03
Turns 1
Accurate Single turn Deterministic Cacheable
filtered_tokens × $15/1M + 1 credit = $0.03
99.98%
fewer tokens with DataGrout vs. raw context (10k Salesforce leads, Opus)

Cost Calculator

Adjust the parameters to see how costs scale with your data.

10,000 records
25 fields
Raw Context
$32.83
2,187,500 tokens
Exceeds typical context window
Roll Your Own
$0.1548
3,320 tokens
3 turns, custom code per task
DataGrout
$0.0290
520 tokens
100.0% token reduction · 1 DG credit

Empirical Benchmark Results

Measured on generated datasets using DataGrout's deterministic tool suite. Model: Claude Opus 4 at $15/1M input tokens.

Experiment 1: Salesforce 10k Leads

ApproachInput TokensCostTurnsAccurateSavings
Raw Context 1,880,425 $28.22 1 No baseline
Roll Your Own 3,320 $0.1548 3 Yes 99.8%
DataGrout 348 $0.0265 1 Yes 100.0%

Experiment 2: Order Trend Analysis (5k orders)

ApproachInput TokensCostTurnsAccurateSavings
Raw Context 519,475 $7.83 1 No baseline
Roll Your Own 4,300 $0.2370 3 Yes 99.2%
DataGrout 401 $0.0585 1 Yes 99.9%

Experiment 3: Multi-Source Integration (SAP + Salesforce)

ApproachInput TokensCostTurnsAccurateSavings
Raw Context 350,150 $5.30 1 No baseline
Roll Your Own 6,150 $0.3248 4 Yes 98.2%
DataGrout 750 $0.0738 1 Yes 99.8%

The Pattern

Deterministic first. LLM second. This isn't new — a recent analysis showed that awk scripts alone can collapse 108,894 bytes of terminal noise to 37. But terminal noise is the easy case.

The hard case is structured data — API responses, database results, integration payloads. You can't awk your way through 10,000 JSON records. That's where DataGrout's tool suites come in.

Pricing

5,000 free credits/month. Deterministic tools (frame.*, data.*, math.*) cost 0 credits — only the gateway base fee applies. LLM-backed tools charge 1 credit + passthrough model cost at 1.2× margin. See full pricing →