AI Engineer World's Fair 2026
Your Agent Is Wasting Tokens and You Don't Know It
About this talk
AWS developer advocate [REDACTED:username] presents five practical ways to reduce AI-agent token costs using Strands Agents: cache prompts, route requests between cheaper and more capable models, offload and summarize large tool results, cap and observe repeated tool calls, and limit multi-turn conversation history with a sliding-window conversation manager.
Chapters
- 0:00Introduction and prompt caching with Strands Agents
- 1:01Route tasks between Claude Haiku and Claude Sonnet
- 1:51Offload and summarize large tool results
- 2:41Cap tool loops and inspect agent observability
- 3:42Control conversation history with a sliding window
- 5:37Closing and professional contact information
Talk transcript
- 0:00
Hey everyone. My name is [REDACTED:username]. I am a senior developer advocate at AWS, and I'm gonna talk to you about how you can save on token costs. Now I'm gonna show you five ways that you can reduce your token costs while using and creating agents.
- 0:18
So the first way you can do that is to cache your system prompt. Let me show you some code. Now I'm using AWS's Strands Agents. This works with all different providers.
- 0:33
This is a little bit of pseudocode, but the idea is that you can add cache_prompt=default, and what that'll do is on the first call of your agent, it will send the full system prompt over, and then on every subsequent call, it will have a much reduced system prompt being sent over.
- 0:54
So it'll be cached. You can also cache the tool prompts and messages as well.
- 1:01
This may sound obvious, but you want to look into routing your different messages based on the difficulty. So here's a code example. Let's imagine that you have a task that's very difficult.
- 1:15
You may wanna use one of the newer frontier models. However, if it's something simpler, you want to use a cheaper model. In this case, maybe we use Claude Haiku for a cheap-- something cheap, and then use Claude Sonnet for something a little bit more difficult.
- 1:30
And then you can use an if statement. You can even have another model that's very cheap decide which model to use. So you can play around with this, but I highly recommend don't use the most expensive model for everything you're doing.
- 1:43
You want to use multiple different models based on the use case, and then try to route to it inside your agent.
- 1:51
Another good tip is to offload the tool result. Let me show you some code on here. Once again, I'm using Strands Agents. This is a, a manual way to do it.
- 2:00
There is some additional APIs that the Strands Agents offers to do this. If you have a large tool result that's coming back, you can store it locally or in the cloud and then use some kind of summarization that saves on tokens.
- 2:18
So that way when it's being called over and over again, the tool result isn't added into the context every time, every time the tool loops or every time the agent loops.
- 2:30
So if you can find any way that where you have this tool result that you don't necessarily send it on every single call back to the large language model, that will save a lot of tokens for you.
- 2:41
And like I said, there's a few APIs to do this, but e-essentially you can do the summarization technique. You can also cap your tool loops. So when you're dealing with the agent loop and it decides to do a tool call, I've had this happen often where it calls the tool over and over and over again.
- 3:00
And if you don't cap that tool call, then it might run ten, twenty times. It might get into an infinite loop, which would be very bad for your token usage.
- 3:10
So always set a max iterations of how many times it will loop. A, a good thing you can do before you deploy your agent is to run some observability tools and take a look at the tool call use for every single tool, and then see how long each one of them is running and how many times they're
- 3:30
looping. And that way you can get an idea of how efficient the tool call is.
- 3:37
Last but not least, we can trim the history.
- 3:42
So if we're using a, a multi-turn agent and we are talking back and forth, you will find at times that the conversation history will get very large. On every single call, that whole conversation history will be sent back to the large language model, and this can eat through hundreds if not thousands of tokens.
- 4:03
In Strands Agents, we have something called Sliding Window Conversation Manager, which, which this does is it looks back at the last ten messages and only sends those back, and you can set this to whatever you want.
- 4:16
And that way you're not sending these huge message histories back to the agent every single time a new message comes in. The downfall of this, or the trade-off of this I should say, is that you will lose the message history from the beginning.
- 4:33
The way you wanna deal with that is you can use, uh, some sort of summarization of the history and then put that into the context window. So rather than sending all of it, you may send a small amount once you hit this sliding window.
- 4:46
Uh, this will save you a lot of tokens.
- 4:51
So in conclusion, we have five things. Cache the system prompt, and if you can, maybe the tool prompt to messages. Route by difficulty. Don't use the same expensive model for everything you're doing, for every single task.
- 5:05
Offload these big tool results. So if you have a large tool result, you can summarize it and not have it being sent in the agent loop and overloading your context.
- 5:16
You can cap those tool loops. Make sure you use observability tools to see how long tool calls are taking and how many loops they're, they're doing and, and then try to iterate over that.
- 5:27
And then of course trim the history if you're using a multi-turn conversation with your agent, so that way the whole conversation isn't being sent over and over again for very long conversations.
- 5:37
Thank you for listening to my very quick almost lightning talk today. If you'd like to go deeper, find me on LinkedIn at [REDACTED:username]. I also blog at programwitherik.com, and then you can find me on social media at [REDACTED:username].
- 5:52
Love to talk to you guys more. Thanks.