
Agents that don't bankrupt you: cost control for agentic systems on AWS
Agents use many more tokens than chat, so cost has to be designed in before the first run. This article gives a three-moment framework (before you start, while in use, continuously) with a system side and a people side for each. It ends with a worked example from COBRA, our internal BOM agent, where a typical estimate costs about US$0.05 to run and the architect's review is about 87% of the monthly cost that remains.
AI Solution Architect | AWS CB | AI Tinkerer Hong Kong Co-Organiser | 11x AWS certified
Agents that don't bankrupt you: cost control for agentic systems on AWS
By John NG, Partner Solution Architect, Ingram Micro Hong Kong
TL;DR: Agents use many more tokens than chat, so cost has to be designed in before the first run. This article gives a three-moment framework (before you start, while in use, continuously) with a system side and a people side for each. It ends with a worked example from COBRA, our internal BOM agent, where a typical estimate costs about US$0.05 to run and the architect's review is about 87% of the monthly cost that remains.
Why this matters now
Agent adoption is moving fast:
- 88% of enterprise leaders say they use or are testing AI agents, up from 72% a year earlier (Zapier AI Agents survey, 2026).
- Gartner predicts that 40% of enterprise applications will include task-specific agents by the end of 2026, up from less than 5% in 2025.
Tokens grow faster than the number of agents. Anthropic measured that an agent uses about 4× the tokens of a chat interaction, and a multi-agent system about 15× (How we built our multi-agent research system, https://www.anthropic.com/engineering/multi-agent-research-system ). Moving from chat to agents therefore changes the unit cost, not only the volume.
Where cost escapes
Three things tend to go wrong:
- Loops and bloat. Agent loops, retries and long histories add up. Tool definitions alone can take 55K–134K tokens before the conversation starts (Advanced tool use, https://www.anthropic.com/engineering/advanced-tool-use ).
- Projects get cancelled. Gartner expects more than 40% of agentic AI projects to be cancelled by the end of 2027, citing escalating costs, unclear business value or weak risk controls. In Harness's State of AI in FinOps 2026, 20% of enterprises report spending US$1M a month on AI.
- Nobody knows who to bill. If every team shares one account or API key, you can't charge spend back to the business unit (BU) that caused it. FinOps Foundation's State of FinOps 2026 reports that 98% of respondents now manage AI spend, up from 31% two years earlier.
The approach: cost is an architecture decision
AWS already gives a structure for this. The Well-Architected Generative AI Lens ( https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/generative-ai-lens.html ) applies the six Well-Architected pillars across the generative AI lifecycle. Here I take the cost optimization pillar and make it practical.
The framework has three moments and two owners:
| Before you start | While in use | Continuously |
|---|---|---|---|
System (what the platform enforces) | Model selection, orchestration, effort and retry caps, harness, budgets and alerts, tagging | Prompt caching, token-efficient tools, call method by workload | Budget alerts, FinOps, evals, simplify |
People (what users and owners do) | ROI gate, workshops | Prompt engineering | Showback, playbook, champions |
1. Before you start
System
- Model selection. Use the smallest model that passes your evaluation. Route sub-tasks to cheaper models: Anthropic's research system used a stronger lead agent with cheaper subagents.
- Orchestration. Choose the pattern by its token multiplier: workflow, then single agent, then multi-agent. Use multi-agent only when the value of the task justifies about 15× the tokens.
- Effort and retry caps. Early versions of Anthropic's research system spawned 50 subagents for simple queries. Put scaling rules in the prompt (a simple question gets one agent and a handful of tool calls) and set hard caps on retries, tool calls and turns.
- Harness. A harness is worth its cost only where the model can't do the task alone. Anthropic reported its full harness cost over 20× a solo agent run for a long-running app (Harness design for long-running apps, https://www.anthropic.com/engineering/harness-design-long-running-apps ).
- Budgets and alerts. Set up AWS Budgets per account or tag from day one.
- Tag every call. Create one tagged Amazon Bedrock application inference profile ( https://docs.aws.amazon.com/bedrock/latest/userguide/cost-mgmt-application-inference-profiles.html ) per BU or application, with tags such as
business-unitandcost-center. The tags flow into Cost Explorer and the Cost and Usage Report, which fixes the "who do we bill" problem.
In code. The first snippet creates a tagged profile and sends a call through it. The second snippet (it continues from the first) wraps an agent loop in hard caps on turns, tool calls and tokens, and returns the token usage so you can price each run.
import boto3
bedrock = boto3.client("bedrock", region_name="us-east-1")runtime = boto3.client("bedrock-runtime", region_name="us-east-1")
# One tagged application inference profile per business unitprofile = bedrock.create_inference_profile( inferenceProfileName="cobra-hk-prod", description="COBRA agent, Hong Kong BU", modelSource={"copyFrom": "<model-or-system-inference-profile-ARN>"}, tags=[ {"key": "business-unit", "value": "hk-presales"}, {"key": "cost-center", "value": "CC-1234"}, {"key": "application", "value": "cobra"}, ],)profile_arn = profile["inferenceProfileArn"]
# Every call goes through the profile ARN, so its cost lands on these tagsresp = runtime.converse( modelId=profile_arn, messages=[{"role": "user", "content": [{"text": "Summarise this inventory."}]}], inferenceConfig={"maxTokens": 512},)MAX_TURNS = 8 # hard cap on model calls per taskMAX_TOOL_CALLS = 12 # hard cap on tool executions per taskMAX_TOKENS_PER_TASK = 150_000
USAGE_KEYS = ("inputTokens", "outputTokens", "cacheReadInputTokens", "cacheWriteInputTokens")
def add_usage(totals, usage): for k in USAGE_KEYS: totals[k] = totals.get(k, 0) + usage.get(k, 0)
def run_task(task, system, tool_config, run_tool): messages = [{"role": "user", "content": [{"text": task}]}] usage, tool_calls = {}, 0 for _ in range(MAX_TURNS): resp = runtime.converse( modelId=profile_arn, system=system, messages=messages, toolConfig=tool_config, inferenceConfig={"maxTokens": 1024}, ) add_usage(usage, resp["usage"]) message = resp["output"]["message"] messages.append(message) if resp["stopReason"] != "tool_use": return {"status": "completed", "usage": usage, "answer": message["content"]} uses = [b["toolUse"] for b in message["content"] if "toolUse" in b] tool_calls += len(uses) if sum(usage.values()) > MAX_TOKENS_PER_TASK or tool_calls > MAX_TOOL_CALLS: return {"status": "stopped_over_budget", "usage": usage} results = [ {"toolResult": {"toolUseId": u["toolUseId"], "content": [{"json": run_tool(u["name"], u["input"])}]}} # tool results must be a JSON object (dict) for u in uses ] messages.append({"role": "user", "content": results}) return {"status": "stopped_max_turns", "usage": usage}These are minimal sketches that show the shape, not production code. Replace the placeholders, add error handling, and make sure your IAM role allows the calls.
People
- ROI gate. Before building, compare the value of one completed task with a target cost per task. If the gap can't close, reshape or stop the project.
- Workshops. Teach teams when an agent is needed and when chat or a simple workflow is enough, how to scope a task, and what a run costs.
2. While in use
System
- Prompt caching. On supported Amazon Bedrock models, caching can cut input cost by up to 90% and latency by up to 85% (Amazon Bedrock cost optimization, https://aws.amazon.com/bedrock/cost-optimization/ ). Put the stable system prompt and tools first and the variable content last, so the prefix stays cacheable.
- Concise tool replies. Give tools a "concise" response mode. Anthropic found it used about a third of the tokens (Writing tools for agents, https://www.anthropic.com/engineering/writing-tools-for-agents ).
- Programmatic tool calls and code execution. Process intermediate data in code, not in the model's context. Anthropic reported a 37% average token reduction on complex research tasks, and one example fell from 150K to 2K tokens (Code execution with MCP, https://www.anthropic.com/engineering/code-execution-with-mcp ).
- Call method by workload. Amazon Bedrock service tiers ( https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html ) let you match the call to the job:
Tier | Use it for |
|---|---|
Priority | Customer-facing, latency-critical work (premium price) |
Standard | Default interactive work |
Flex | Work that tolerates delay (discounted) |
Batch | Asynchronous jobs through Amazon S3, at 50% of on-demand price; no tool calling |
Reserved | Steady, high-volume workloads |
Check the pricing page for the current Priority and Flex rates for your model and Region.
Caching and a service tier go on the same Converse call. Put stable content before the cache checkpoint and variable content after it:
resp = runtime.converse( modelId=profile_arn, system=[ {"text": STABLE_SYSTEM_PROMPT}, # stable content first {"cachePoint": {"type": "default"}}, # cache everything above this line ], messages=[{"role": "user", "content": [{"text": variable_question}]}], # variable content last serviceTier={"type": "flex"}, # "default" (Standard), "priority" or "flex" inferenceConfig={"maxTokens": 512},)
u = resp["usage"]print("input", u["inputTokens"], "| cache read", u.get("cacheReadInputTokens", 0), "| cache write", u.get("cacheWriteInputTokens", 0), "| output", u["outputTokens"])Not every model supports every tier or prompt caching through Converse, so check the model's card first. Work that can wait can go through a batch job instead:
job = bedrock.create_model_invocation_job( jobName="cobra-overnight-estimates", roleArn="arn:aws:iam::<account-id>:role/<BedrockBatchRole>", modelId="<model-id>", inputDataConfig={"s3InputDataConfig": {"s3Uri": "s3://<bucket>/input/requests.jsonl"}}, outputDataConfig={"s3OutputDataConfig": {"s3Uri": "s3://<bucket>/output/"}}, tags=[{"key": "business-unit", "value": "hk-presales"}],)print(job["jobArn"])People
- Prompt with intent. State the objective, output format, tool guidance and task limits. Ask for concise output: output tokens cost about five times input tokens on the Anthropic model we priced (US$11.00 against US$2.20 per million, in-region standard, us-east-1, AWS Price List, 9 November 2026).
- Start a new session for a new task rather than carrying a long history.
3. Continuously
System
- Measure, allocate, evaluate, simplify. Use Budgets, Cost Anomaly Detection and Amazon CloudWatch token metrics, then allocate cost by inference-profile tag.
- Pick a unit metric. Track cost per completed task, not monthly tokens.
- Evaluate. A fixed task bank gives you tokens, cost, latency and error rate for every change, so a cost cut doesn't silently cost quality (Demystifying evals for AI agents, https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents ).
- Simplify. Re-check your harness on each model upgrade. Scaffolding a newer model doesn't need is pure cost.
To track cost per completed task, price each run from its token usage, then group the monthly bill by tag:
# Prices are US$ per 1M tokens: take them from the AWS Price List for your model, Region and tierdef run_cost(usage, price): return (usage.get("inputTokens", 0) * price["input"] + usage.get("outputTokens", 0) * price["output"] + usage.get("cacheReadInputTokens", 0) * price["cache_read"] + usage.get("cacheWriteInputTokens", 0) * price["cache_write"]) / 1_000_000
def cost_per_completed_task(results, price): spend = sum(run_cost(r["usage"], price) for r in results) done = sum(1 for r in results if r["status"] == "completed") return spend / done if done else None
# Showback by tag (the tag must be activated as a cost allocation tag in Billing)ce = boto3.client("ce", region_name="us-east-1")report = ce.get_cost_and_usage( TimePeriod={"Start": "2026-11-01", "End": "2026-12-01"}, Granularity="MONTHLY", Metrics=["UnblendedCost"], GroupBy=[{"Type": "TAG", "Key": "business-unit"}],)for g in report["ResultsByTime"][0]["Groups"]: print(g["Keys"][0], g["Metrics"]["UnblendedCost"]["Amount"])Fill in the prices for your model, Region and service tier. The Cost Explorer query only returns a tag after it has been activated as a cost allocation tag.
People
- Showback. Review cost with each BU every month.
- Playbook and champions. Keep a shared playbook of patterns that work, and name champions who pass the habits on.
Worked example: COBRA
COBRA is Ingram Micro Hong Kong's internal application that turns a customer's server inventory into a reviewable AWS bill of materials (BOM). Its agent version runs on AWS. The question I want to answer is not "what is the token bill?" but "what does one run cost against the value it provides?"
The monthly mix (Ingram Micro Hong Kong estimates): 1 hard BOM, 6 medium and 5 small. Done manually, a hard BOM takes 1 man-day (MD), a medium one 2 hours and a small one 30 minutes. We price 1 MD at US$500 and assume 8 working hours per MD, so US$62.50 an hour. With COBRA, an architect reviews the output: 10 minutes for a hard BOM, 5 for a medium one and none for a small one. COBRA also uses 2 Amazon Quick agent hours a month, at US$3 an hour.
BOM | Manual | COBRA run | Architect review | Total with COBRA | Saving |
|---|---|---|---|---|---|
Hard | US$500.00 | US$0.15 | US$10.42 | US$10.57 | 97.9% |
Medium | US$125.00 | US$0.05 | US$5.21 | US$5.26 | 95.8% |
Small | US$31.25 | US$0.01 | none | US$0.01 | 99.97% |
Multiplying by the monthly mix and adding the fixed Quick agent hours gives the monthly total:
Monthly mix | BOMs | Manual | With COBRA | Saving |
|---|---|---|---|---|
Hard | 1 | US$500.00 | US$10.57 | US$489.43 |
Medium | 6 | US$750.00 | US$31.55 | US$718.45 |
Small | 5 | US$156.25 | US$0.05 | US$156.20 |
Quick agent hours | 2 hours at US$3 | none | US$6.00 | -US$6.00 |
Total per month | 12 | US$1,406.25 | US$48.17 | US$1,358.08 (96.6%) |
The per-BOM figures above leave out the Quick agent hours, because they are a fixed monthly cost. Across the month, manual work costs about US$1,406 (22.5 hours). With COBRA it costs about US$48: US$41.67 of architect review, US$6.00 of Quick agent hours and US$0.50 of runs. That is roughly 29× cheaper, saving about US$1,360 a month.
Two lessons stand out:
- The run is cheap; the review is the cost. Review is about 87% of what remains, Quick agent hours about 12% and runs about 1%. That is the right place for human time, and it tells us where to look next.
- The ratio is what you defend. A finance team can't judge a token bill. It can judge "US$48 against US$1,406".
These figures are internal estimates, not audited results. The run cost is the per-run estimate we use for planning; it is not a published AWS price. The Quick agent hours are priced at US$3 an hour.
Five takeaways
- Agents multiply tokens, so design for cost before the first run.
- Tag every call to an owner from day one.
- Match every call to the right model and service tier.
- Engineer context: cache it, trim it and move data work into code.
- Measure cost per completed task, and re-simplify as models improve.
What to do next
- Create a tagged application inference profile for your next agent workload.
- Pick one workload and decide whether Standard, Flex or Batch fits it.
- Define your unit metric (cost per completed task) before launch, and put it on a dashboard.
If you want to talk through your own agent workloads, connect with me on LinkedIn.
References
(there was some issue with including links here, so just the article title are mentioned)
Anthropic Engineering
- How we built our multi-agent research system
- Advanced tool use
- Code execution with MCP
- Writing tools for agents
- Demystifying evals for AI agents
- Harness design for long-running apps
AWS documentation
- Well-Architected Generative AI Lens
- Amazon Bedrock service tiers
- Amazon Bedrock application inference profiles
- Amazon Bedrock cost optimization
- Amazon Bedrock Converse API
- Amazon Bedrock prompt caching
Market data
- Gartner press release, 25 June 2025: over 40% of agentic AI projects will be cancelled by the end of 2027
- Gartner press release, 26 August 2025: 40% of enterprise applications will feature task-specific AI agents by 2026
- Zapier, AI Agents survey 2026
- Harness, State of AI in FinOps 2026
- FinOps Foundation, State of FinOps
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article