AWS: One Tool Cuts Tokens Per Script by 95%, On-Demand Skills Shrink the Prompt by 97%

A request like “analyze sales and build a report” eats more than 150 thousand tokens of a 200 thousand window in 15 minutes. In AWS Deep Insight, one tool writes the script to a file, runs it, and returns three lines of summary to the context instead of 100 lines of code. That is 95% fewer tokens per script. Skills load on demand, which makes the system prompt roughly 97% shorter. Start by merging “write” and “execute” into a single tool.

AI-processed from AWS Machine Learning Blog; edited by Hamidun News
AWS: One Tool Cuts Tokens Per Script by 95%, On-Demand Skills Shrink the Prompt by 97%
Source: AWS Machine Learning Blog. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceAWS Machine Learning Blog ↗
Editor-in-Chief
Key metric #1The Coder agent stays within 25 thousand tokens of context
Key metric #2The skills catalog takes about 500 tokens instead of 20 thousand or more
Key metric #3Agent response limits are 800–1500 tokens, and everything else goes into files

Imagine asking an AI agent: “Analyze the sales data and make a report in DOCX.” The agent loads the data, calculates figures by category, draws five charts, checks the statistics, and writes the document. All of this takes about 15 minutes and more than 150 thousand tokens, while the context window (the model's working memory) of Claude Sonnet 4.

5 in Amazon Bedrock is 200 thousand. If every script the agent writes and every result it gets back stays in that memory, the window fills up fast. The agent then crashes mid-task, loses accuracy, or burns through the budget, since tokens cost money.

The AWS team showed how to avoid this in the open-source Deep Insight project. There are two headline numbers: using one tool instead of two cuts the tokens each script adds by about 95%, and loading skills on demand shrinks the system prompt by about 97%. For anyone building agents, this is a direct way to make them cheaper and more reliable.

Why an overfilled context is a problem

The issue is not only that the window can run out. Anthropic describes an effect called context rot: the more tokens in the context, the worse the model recalls the information it needs. Stale data gets in the way, and any error forces you to restart the entire pipeline. So AWS pulled together techniques from Anthropic's engineering articles and features of the Strands Agents SDK into four layers of “context engineering.” This is the second part of a series. Deep Insight is a multi-agent data analysis solution built on the Strands Agents SDK and Amazon Bedrock AgentCore, and all the examples come from it.

Layers 1 and 2: separate the agents and limit their responses

The first layer is architecture. Each specialized agent has its own window, and the coordinator receives only a compressed summary. In Deep Insight, the hierarchy looks like this: Coordinator, Planner, Plan Reviewer, Supervisor, and the worker agents Coder, Validator, Reporter, Tracker, and Auditor. The shared state is a shared_state dictionary with just four fields: the previous agent's last message, compressed notes called clues, the plan checklist, and a brief log. As a result, even the Coder, the most “hungry” agent, stays within 25 thousand tokens.

The second layer is prompts. Isolation is not enough: if an agent answers at length, the Supervisor's context still bloats. So the prompts set response budgets: Coder 1000–1500 tokens, Validator 800, Reporter 1000. All agents use the same format: status, completed tasks, key findings with figures, and a list of files. There is also a non-obvious rule: every script is self-contained, meaning it includes its own imports and loads the data from the cache itself. Variables do not persist between runs, but old code can safely be dropped from the context.

Layer 3: only references in the context, data in files

This is where the most noticeable savings come from. An agent usually has two tools: “write file” and “execute.” In that setup, every 100-line script lands in the conversation history in full, and after several analyses there are more than a thousand lines of code in it. In Deep Insight, a single tool, write_and_execute_tool, does both steps and returns a short summary: “105 lines written, executed successfully, analysis of five categories complete.” The code stays on disk, and the context holds about three lines. By AWS's estimate for this example, that works out to about 95% token savings per script.

Other techniques of the same kind also help:

  • The shared module coder_analysis_utils.py is created once, and its functions are imported with two lines instead of the 20–30 lines the agent would otherwise write from scratch each time.
  • The file all_results.txt serves as a notebook: the Coder appends details there, and the Supervisor receives a message of about 30 tokens.
  • Files replace data passing between agents: calculation_metadata.json goes from Coder to Validator, citations.json from Validator to Reporter, and audit_findings.json from Auditor to Reporter.
  • Skills load on demand. The system prompt holds a catalog of about 500 tokens, and the agent opens the full SKILL.md guide (about 3 thousand tokens) only when it needs it. Pasting in all the guides up front would cost more than 20 thousand tokens on every call. That is where the roughly 97% savings come from, and a new skill can be added without redeploying.

Caveats and what to do in practice

The figures come from AWS's own reference implementation and from a single illustrative example with a 105-line script, not from an independent benchmark. On your task the effect will differ: the longer the scripts and the more steps, the more noticeable it is. The fourth layer is verification by independent agents (Validator, Auditor) plus guardrails against context overflow. In the project, it is the last line of defense in case the first three layers miss something.

The practical order is this: separate contexts between roles, set response budgets in the prompts, and move the heavy material (code, tables, results) into files and pass it by reference. The cheapest first step is to merge “write” and “execute” into one tool. The agents-as-tools pattern in the Strands Agents SDK provides isolation at the framework level, so you won't have to rewrite your orchestration from scratch.

Story

Key Questions Answered

Why an overfilled context is a problem?

The issue is not only that the window can run out. Anthropic describes an effect called context rot: the more tokens in the context, the worse the model recalls the information it needs. Stale data gets in the way, and any error forces you to restart the entire pipeline. So AWS pulled together techniques from Anthropic's engineering articles and features of the Strands Agents SDK into four layers of “context engineering.” This is the second part of a series.

What are the key details on Layers 1 and 2: separate the agents and limit their responses?

The first layer is architecture. Each specialized agent has its own window, and the coordinator receives only a compressed summary. In Deep Insight, the hierarchy looks like this: Coordinator, Planner, Plan Reviewer, Supervisor, and the worker agents Coder, Validator, Reporter, Tracker, and Auditor. The shared state is a shared_state dictionary with just four fields: the previous agent's last message, compressed notes called clues, the plan checklist, and a brief log.

What are the key details on Layer 3: only references in the context, data in files?

This is where the most noticeable savings come from. An agent usually has two tools: “write file” and “execute.” In that setup, every 100-line script lands in the conversation history in full, and after several analyses there are more than a thousand lines of code in it. In Deep Insight, a single tool, write_and_execute_tool, does both steps and returns a short summary: “105 lines written, executed successfully, analysis of five categories complete.” The code stays on disk, and the context holds about three lines.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…