Your agent's biggest expense isn't the work it does. It's the context it re-reads on every single turn. A 30-message agent conversation costs 15x more than 30 standalone messages. Here are 6 techniques that cut that cost by 40-70% without changing your model.
Stop paying to re-read the same context.
Smart context management is built into the platform. Hybrid vector + keyword memory retrieves only what each turn needs. Free forever, not a trial. Start free → No credit card · No Docker · No config files
My support agent was costing $140/day. Five hundred conversations. Claude Sonnet. The math seemed right when I set it up. $3/M tokens. Reasonable.
Then I looked at the actual token usage. Each conversation averaged 30 messages. And every message re-sent the entire conversation history plus the system prompt plus all tool definitions. By message 30, the context window held 232,500 cumulative tokens across all API calls for one conversation.
$140/day for 500 conversations. That's $0.28 per conversation. Seventy percent of that cost was context re-reading, not actual work.
I changed nothing about the model. Nothing about the prompts. Nothing about the agent's behavior. I only changed what went into the context window and when. The daily cost dropped to $42. Same agent. Same quality. Same 500 conversations.
Here's how to cut your agent's token costs by 40-70% using the same six techniques.
Why context is the real cost (the math nobody shows you)
Every LLM API call includes the entire context. The model doesn't "remember." It re-reads everything from scratch on every turn. This is how agent memory actually works.
The token count grows triangularly, not linearly.
Message 1: 500 tokens sent. Message 2: 1,000 tokens sent (message 1 + message 2). Message 10: 5,000 tokens sent. Message 20: 10,000 tokens sent. Message 30: 15,000 tokens sent.
Total tokens consumed across all 30 API calls: ~232,500. Not 15,000.
On Sonnet at $3/M input: $0.70 per 30-message conversation. On 500 daily conversations: $350/day in context re-reading alone.
The #1 hidden cost in AI agents: every old message gets re-sent with every new message. A 30-message conversation doesn't cost 30x one message. It costs roughly 465x one message (the triangular sum).

Technique 1: Cap and summarize sessions (saves 30-40%)
The single highest-impact change. After 10-15 messages, compress the conversation into a 200-300 token summary. Start a fresh session with the summary as the first message.

Before: Messages 1-30 in one session. 232,500 cumulative tokens.
After: Messages 1-10, summarize (25,000 cumulative tokens). Messages 11-20 with summary (25,000 cumulative tokens). Messages 21-30 with summary (25,000 cumulative tokens). Total: 75,000 tokens. That's a 68% reduction.
The quality tradeoff: the model loses access to exact conversation history from earlier segments. It has the summary instead. For most agent tasks (support, classification, drafting), the summary contains everything needed. For tasks requiring exact recall of early messages ("what did the customer say in message 3?"), keep the full history.
Technique 2: Trim tool responses (saves 15-25%)
Tool responses are the biggest context consumers that nobody optimizes. A CRM lookup returns the full customer record (2,000 tokens) when your agent only needs name, plan, and last interaction (150 tokens).

Before: Agent calls CRM tool. Full customer record (2,000 tokens) enters the context. Agent uses 150 tokens of it. 1,850 tokens of waste re-sent on every subsequent message.
After: Post-process tool responses before they enter the context. Keep only the fields the agent needs for the current task. Those 1,850 wasted tokens, multiplied by every remaining message in the session, add up fast.
# Before: full tool response enters context
tool_response = crm.get_customer(customer_id) # 2,000 tokens
# After: trim to relevant fields
trimmed = {
"name": tool_response["name"],
"plan": tool_response["subscription"]["plan"],
"last_interaction": tool_response["interactions"][-1]["summary"]
} # 150 tokens
At 5 tool calls per conversation, trimming saves 9,250 tokens per conversation. On 500 daily conversations: 4.6M tokens/day saved. On Sonnet: $13.88/day. That's $416/month from trimming alone.
Technique 3: Use prompt caching (saves 25-50%)
Anthropic offers 90% discount on cached input tokens. OpenAI offers 50%. The cache applies to the static prefix of your prompt (system prompt + tool definitions).
How it works: The first request sends the full system prompt (~3,000 tokens) at full price. Subsequent requests reuse the cached prefix at 10% cost (Anthropic) or 50% cost (OpenAI).
The math: A 3,000-token system prompt re-sent 30 times = 90,000 input tokens. Without caching: $0.27 on Sonnet. With caching: $0.027 (first call full, rest at 90% off). Saves ~$0.24 per conversation.
For the full setup on every major provider, see our prompt caching guide. For the broader picture including model routing, see our comprehensive cost-cutting guide.
Technique 4: Separate stable context from growing context
Your system prompt and tool definitions don't change between messages. Your conversation history does. Treat them differently.

Stable context (fixed size): System prompt. Tool definitions. Memory files (SOUL.md, AGENTS.md). These should be cached and reused.
Growing context (variable size): Conversation history. Tool responses. Intermediate reasoning. This is what you need to manage, summarize, and trim.
The insight: stop treating the context window as one blob. It's two layers: a stable foundation (cacheable, fixed cost) and a growing conversation (the expensive part that needs active management).
Technique 5: Selective memory retrieval (not dump-everything)
Most agent frameworks inject all memory into every turn. Your agent has 50 facts in memory. It retrieves all 50 on every message. But message 17 about a billing dispute only needs the customer's plan and payment history. Not their onboarding preferences or product feedback from six months ago.
Dump-everything approach: 50 facts x ~100 tokens each = 5,000 tokens of memory on every turn. Over 30 messages: 150,000 tokens of mostly irrelevant memory.
Selective retrieval: Query the memory store for only the facts relevant to the current message. Inject 3-5 relevant facts (~300-500 tokens) instead of all 50.

BetterClaw's hybrid vector + keyword search does this automatically. On each turn, the platform retrieves only the memories relevant to the current task, not everything the agent has ever learned. This keeps context lean regardless of how much the agent knows.
OpenClaw and Hermes use file-based memory that dumps everything. You'd need to build your own retrieval layer to get selective injection. $19/month per agent on Pro. Free plan with every feature.
Technique 6: Compress conversation history (saves 10-20%)
Instead of keeping every message verbatim, compress older messages into shorter summaries while keeping recent messages full.
Pattern: Messages 1-5: summarized (one paragraph). Messages 6-10: summarized (one paragraph). Messages 11-15: full text. Current message: full text.
This "sliding window with summaries" approach keeps the most recent context in full detail while compressing older context. The agent retains awareness of the full conversation arc without re-reading every word of every old message.
The combined impact
| Technique | Savings | Effort |
|---|---|---|
| Cap and summarize sessions | 30-40% | Medium (needs summarization logic) |
| Trim tool responses | 15-25% | Low (filter fields before context) |
| Prompt caching | 25-50% | Low (API flag, almost free to enable) |
| Separate stable/growing context | 10-15% | Low (architectural decision) |
| Selective memory retrieval | 10-20% | High (needs vector search) or $0 on BetterClaw |
| Compress conversation history | 10-20% | Medium (sliding window logic) |
Applied together, these techniques compound. A 500-conversation daily workload on Sonnet ($3/M):
Before: $140/day ($4,200/month).
After (all 6 techniques): $42-56/day ($1,260-1,680/month).
Savings: $2,520-2,940/month. That's a 60-70% reduction without changing your model, your prompts, or your agent's behavior.

The teams building sustainable agent deployments in 2026 aren't just picking the cheapest models. They're engineering what goes into the context window on every turn. The model sees less. It costs less. And because the context is more relevant, the quality often goes up, not down.
Give BetterClaw a look if you want context management built into the platform. Smart context management prevents token bloat automatically. Hybrid vector + keyword memory retrieval. Per-agent cost caps. Free plan with 1 agent and every feature. $19/month per agent for Pro. We handle the context engineering. You handle the agent logic.
Frequently Asked Questions
Why do AI agent token costs grow so fast?
LLMs re-read the entire context on every API call. A 30-message conversation doesn't cost 30 messages. It costs the triangular sum: 1+2+3+...+30 = 465 message-equivalents. On Sonnet at $3/M, a 30-message conversation costs approximately $0.70 in context re-reading alone. The fix: cap sessions at 10-15 messages and summarize, reducing cumulative tokens by 60-70%.
What is context engineering for AI agents?
Context engineering is the practice of deliberately managing what goes into an LLM's context window on each turn. Instead of dumping the full conversation history, all memory, and unfiltered tool responses into every API call, you selectively include only what's relevant. Techniques include session summarization, tool response trimming, prompt caching, selective memory retrieval, and conversation compression. Together, these reduce token costs by 40-70%.
How much can prompt caching save on agent costs?
Anthropic's prompt caching saves 90% on repeated input prefixes (system prompt + tool definitions). OpenAI's saves 50%. A 3,000-token system prompt sent 30 times costs $0.27 without caching and $0.027 with caching on Sonnet. For agents processing 500 daily conversations, caching the system prompt alone saves $120-150/month. Enabling caching is typically a single API flag with no code changes.
Does trimming context reduce agent quality?
For most agent tasks, no. Trimming irrelevant tool response fields and summarizing old conversation history actually improves quality because the model's attention focuses on relevant information instead of being diluted by noise. The "lost in the middle" effect means the model pays less attention to the middle of long contexts. Shorter, more relevant contexts get more consistent attention across all content.
Which agent platforms handle context management automatically?
BetterClaw includes smart context management and hybrid vector + keyword search memory that retrieves only relevant context per turn. OpenClaw and Hermes use file-based memory that dumps all context on every turn (you need to build your own optimization layer). CrewAI and LangGraph leave context management to the developer. n8n has no built-in agent memory or context management. For the highest savings with the least engineering effort, managed platforms with built-in optimization win.
Context management without the plumbing.
Session summarization, prompt caching, and selective memory retrieval, built in. Set a per-agent cost cap and deploy in 60 seconds. Free forever, not a trial. Start free →




