How Databricks Cut AI Coding Agent Costs: Unity AI Gateway, Smart Routing and Trace Analysis
Summary
- Agent Trace Analysis: Systematically auditing agent execution traces reveals hidden interface bugs and bloated context responses that waste thousands in redundant token usage.
- Smart Model Routing: Dynamically routing tasks based on complexity rather than defaulting to expensive frontier models significantly reduces costs while maintaining output quality.
- Context Truncation: Capping tool response sizes and search result windows can reclaim up to 60% of token consumption without degrading agent performance or code quality.
How Databricks Cut AI Coding Agent Costs: Unity AI Gateway, Smart Routing and Trace Analysis

Talk by Casey Olen Hoot, Director of Product Management, AI, Databricks
To reduce AI coding agent costs, route simple tasks to cheaper models, cap oversized MCP tool responses, and analyze your agent traces. This video shows how Databricks uses Unity AI Gateway to put budgets, security policies and trace tracking on coding agents, then mines those traces to improve cost, quality and security.
A Databricks product director walks through the cost findings. A Jira MCP tool that expected a comma-separated string but received arrays took about 12 turns to recover, cost roughly 90k a year in tokens and about 5,000 hours of agent churn, and a coding agent fixed seven MCP bugs in under an hour. Truncating Slack MCP search results reclaimed about 60% of tokens. 82% of launches defaulted to the most expensive model while about 25% of prompts were trivial or low complexity, which led to task-aware smart routing. Benchmarks built from traces compared harnesses and models on a cost-quality curve, and combining model families plus the Omnigent meta-harness improved quality.
Chapters
00:00Introduction00:52What blocks autonomous coding agents: cost, quality, security02:19Unity AI Gateway: budgets, security policies and traces03:59How MCP tool errors waste tokens and how to fix them06:47Truncating MCP responses to reclaim 60% of tokens08:35Are all tasks equal? Default models and smart routing12:50Which harness and model give the best cost-quality tradeoff15:22Analyzing agent traces for security misalignment16:24Improving output quality with multi-LLM architectures17:39Meta-harness and Omnigent across coding agents18:54Takeaway: analyze your agent traces
FAQs
How can enterprises dramatically reduce token costs for autonomous coding agents?
Analyze agent execution traces to identify hidden interface bugs and bloated responses wasting tokens, then implement task-aware smart routing instead of defaulting to expensive models. This video demonstrates real savings while maintaining code quality.
What is context window bloat in AI agents and how do you fix it?
Agents often return oversized tool responses and unnecessary search results that consume tokens without adding value. This video shows truncation strategies that can reclaim up to 60% of token usage without impacting agent performance.
Why should teams implement multi-LLM architectures over single-model systems?
Combining diverse models and meta-harness architectures prevents context fragmentation and yields superior coding accuracy. This video explores research proving mixed-model approaches significantly outperform single-model systems.
What operational risks do unmonitored long-running autonomous agents create?
Unmonitored agents lead to runaway token expenses and security vulnerabilities. This video discusses centralized gateway infrastructure and monitoring strategies essential for controlling autonomous agent behavior.
Full transcript
00:00 Introduction
Hello everyone. I'm Casey Olen Hoot, director of product management for the AI team at Datarix. Very excited to be here. Thank you for all coming. Uh, it's going to be a jam-packed night of fun learning about agents, governance, security, all of those things. So, I thought that we would start by talking about I was trying to figure out what would be interesting for you all to hear. I think the real goal is everyone wants these autonomous agents and how do you actually run them efficiently.
So I'm going to walk you through everything the data bricks team has done for our thousands of engineers to make it so that we can run our coding agents efficiently in our organization. Uh and then what our research team has actually been doing with the data that we've collected from all these agent traces to then figure out what we can do and what the levers are that we can pull to actually drive a lot of this efficiency.
So it's going to be a little bit of a practical talk but hopefully will resonate with you all. All right. So, we did a big survey of like hundreds of developers out there in the world asking them like, "Hey, what's preventing you from getting full autonomy with your agents? Like, what's preventing you from having your agent swarms run overnight? Like, what's the thing keeping you up at night here?" Uh, there was three things that really stood out.
00:52 What blocks autonomous coding agents: cost, quality, security
One was cost, one was quality of the output, which was kind of interesting to us, not really what we expected. Uh, and the last was security. Uh, so those are the three main things we see. Uh we also see them in headlines today. You probably saw like the OpenAI hugging face thing that came out uh recently. The uh agents are going rogue deleting production databases. Uh and then token maxing is of course a huge issue.
Uh if it's not an issue for you now, you might find your manager is changing your budget soon for your agents. So heads up on that one. We had similar things at data bricks. Actually cost is our main driver. You probably see with like series M and all these other things. we need to be able to start cutting costs uh inside of our organization. So, as we started rolling out coding agents across uh our company, we started seeing that the costs were skyrocketing.
And this is because most uh developers are running goal-based agents that run into the goals achieved, which means they're extremely longunning and they'll do many things uh in there. And because of that, that causes price or costs to go up a lot and then introduces a lot of security risk because there's not really anyone watching these longunning agents. Uh so this is what's motivated us to actually build something called Unity Gateway.
02:19 Unity AI Gateway: budgets, security policies and traces
Unity gateway is our like AI gateway. It's AI gateway plus. Uh it basically allows you to put cost controls, budgets um on all your coding agents or external agents. allows you to have security policies and track all of the traces from your agents. Uh and then it also gives you access to the frontier open source and proprietary models so that you can actually switch to different models uh and different harnesses uh to get better costs uh if you need or better efficiencies uh in there.
So we built this thing, we use it today like all of data bricks engineering coding agents go through this unity gateway today as well as thousands of our customers. But it turns out the real value ad that we're really getting or where a lot of the bang for the buck is coming in are all the agent traces coming from here. And you'll have to welcome my special guest Spongebob who will be joining us on this adventure. Turns out these agent traces are super helpful and not everyone's collecting traces and even looking at their traces is what we found when we talked to a lot of the enterprises using us.
And so I'm going to kind of go through how we used agents to actually analyze all of our agent traces and then all the things that we learned uh from that. Uh I have to do a slight pub here of we did use Genie which is datab bricks's data smart agent to do all the analysis. It actually worked really well on this uh but you can probably use any agent to do it but that's what we used to do the majority of this analysis.
All right so we'll start with costs. So there's four main findings that we had on cost by analyzing all of these traces. Uh the first is we kind of had this hunch that probably MCPs have a lot of errors and that's causing a lot of like churn in the agent and that's like driving up costs for us. So you know and if you ever have watched an agent try to call an MCP, it will often like mess up something and try again try again. and then it'll just like guess something random like oh dear we got to figure out what's happening here.
03:59 How MCP tool errors waste tokens and how to fix them
Uh so we looked through all of our agent traces and then we like took a step further. So this is a bunch of MCPS that we created. So we like wrapped the Jira APIs, we wrapped the Slack APIs, stuff like that. So if we dive in deeper in our Jira MCP we had a tool called issue search which basically just returns a bunch of issues that match some key terms. uh the MCP expected a comma-epparated string, but the model was sending it an array of strings, which is a fair assumption on behalf of the model.
It didn't really understand what the MCP wanted. But the problem was is that the MCP was calling a dotsplit Python call, which fails on an array but works on a string call. And so because of that, I was hitting errors. So the consequence of this when we looked into our traces was it took 12 turns on average for the agent to actually recover when it was calling that agent or calling that MCP. About 30% of sessions that called this Jira tool hit this error more than two times.
And the consequence of that was about 90k a year in tokens was being spent on this as well as about 5,000 hours a year. 5,000 hours a year were being spent of the agent just like churning to try to figure this out. And it's like the tiniest issue ever where it's just wanted the arguments in a different format uh in there. So kind of crazy what could happen. And you know that's you know that could be someone's salary a year that you just wasted on this.
Uh so what was the fix? Uh it was actually super trivial to fix. We just gave our genie report of the trace analysis to a coding agent. It found seven bugs from all those traces across all of our MCPS and it fixed them in less than an hour. So worked pretty good. So that then saved us 90K a year at least on that one bug and then more on the other seven or six that it found. Uh, I think the main takeaway that we got from this is a lot of people would have added a skill to actually improve how the agent can call the MCP, but a skill is just going to add more tokens to the equation.
And because we own the MCP, it's just easier to make it so your MCP can also take an array. And so that allowed us to be much more efficient uh, in here. All right, the next kind of hunch we had as we were analyzing all this tracing data was that when we were looking through all of the MCP errors, we're like, "Wow, some of these things return a lot of data." So like they're returning like SQL like tons of data in like from SQL output. uh they're returning a lot a lot of times on these search equations like huge JSON dumps um and blobs that are just really hard or like really big and like jam up your context window like make you you're sending it on every call then it's just a lot of tokens being spread around.
06:47 Truncating MCP responses to reclaim 60% of tokens
Uh so we're like hm let's look at this. So for our Slack MCP, we looked at our message search tool and it turned out that 300 million tokens a week were being sent through the Slack MCP and the average call had about 12K tokens. And we were like, hm, is it actually using all of these tokens? Like is it actually using half the search responses in there? Could we just like return the first half and call it a day? Uh, and so because we have the traces, we can actually analyze this.
So that's what our research team did was they built a benchmark data set uh from all of these traces and then they said okay if we truncate like to 20 the top 20% of search results do you get the same output if you do the top 30% top 40 50 and so they just kept slicing and seeing how much they could truncate of the responses and it turned out that about 60% of the tokens from that Slack MCP that we were returning were reclaimable so we only needed to really return the top 40% uh in there and you would get the same results.
And so that then is like a 60% like price reduction in the number of tokens that you're sending each call uh in there. And so now we actually have built all these caps on our MCPS to actually restrict how many tokens they can return um based on like our analysis from these traces. So that worked really well as well. Let's get away from MCP. So the next thing that we looked at is are all tasks created equal? Uh, and it turns out we're like, is everyone just using the most expensive model to do everything at work?
08:35 Are all tasks equal? Default models and smart routing
And are people actually doing work with all these coding agents? Are they doing other random stuff? Turns out there's actually a lot of people like ordering lunch and like asking for career advice and all these other things that aren't necessarily directly related to their job uh in there. Uh, so we're like, okay, let's analyze the traces and see what they're doing. So what we actually found was if we look at I believe the bottom one you can see like 82% of our sessions started with opus 4.
- So like they defaulted to the most expensive model when we looked at that. So if you look at the bottom graph if you look at that bottom graph most of our spend is asking trivial questions to that expensive model. Very few people were actually asking appropriate questions to the most expensive model we found. uh and that was just on a pilot where I was given access to a very small set of traces in like a day. But then when we expanded it to sort of all of our uh traces over the last 30 days, we saw something that looks more like the top graph where it's about 8% of prompts sent to our like coding agents are trivial.
And then the low complexity is another almost 20%. So about like 25% of the questions asked to our coding agents only require a very basic model to answer but 82% of the time we're using the most expensive model out there. Uh and and you can also see how many people are actually asking really complex questions only 12% of the time. So it's like do we really need the most intelligent model to be the default? And so that is what we ended up changing is one we now change what our default model is that we launch with.
Uh we have I'll show you in a second we built smart routing in our unity gateway so that it will actually launch sessions with the appropriate model for the task or the most efficient model for that task. Uh and then we actually now before upgrading to a new model we will actually use the benchmarks that we built from tracing to do that. So for example, uh, Opus 5 came out. Before determining if we were going to move to Opus 5, we actually evaluated it versus 4.
8 on those traces to see does it have a meaningful quality increase or not uh in there. So that was what we did there. So then we also did smart routing. So we built this smart router. I should have added a slide that actually illustrates how our smart router works, but I'll tell you. So we did taskaware routing. So rather than doing per request routing, which would like hit the KV cache each time, we did task aware routing.
So that means whatever question you ask, the session will be launched with the model that will best answer that question. So if you ask a simple question, you're going to have a simple model running as your main agent. Uh if you ask a complex question, you'll have a complex uh agent running as your main agent. But the other thing that we added is every sub agent created will call the smart router again. So if you had a simple model and then you asked a complex or needed to do something complex for you, it could then spin up uh a larger model to do it uh in there.
So there's different things that we're playing around with smart routing. I think this is an area that needs a lot more research in there. But just off our very like trivial sort of implementation of it, we've seen huge uh savings uh in there. What we ideally love to do is right now the way that harnesses are built, the main agent is where most of the work gets done and they rarely kind of spin up all these sub aents.
Uh what we're kind of exploring is having the main agent actually just be this very small delegator and it's always breaking tasks down into smaller subtasks which in those subtasks you can then figure out what's the best routing and what's the best model to go for for each of those subtasks. So rather than having this really expensive main model that's doing the majority of the work, you're actually farming it out um always and it's kind of more the modular style um that we're used to working in uh in there.
But that's not how harnesses are kind of built today. So that's something that we have to actively explore. Great segue for myself to the next one. Uh so then we're like, okay, let's investigate these harnesses uh and how are they impacting efficiency? So we actually took all of our P like pull requests from our codebase uh and along with all the traces and we said okay let's try a bunch of different configurations of harnesses.
12:50 Which harness and model give the best cost-quality tradeoff
So let's like change if they're max effort or high effort or medium effort. Let's like try different model harnesses and let's try open source harnesses versus the native harness uh for different models. And in here we basically found a paro curve uh in here where you can I don't know if you can actually see that's definitely too minuscule for people in the back. Top point is using opus with pi. Then there's using uh oh wait there's uh opus uh high effort with pi.
Then it's opus uh hold on I can't even read it. Oh and then it's using cloud code the native harness with uh high effort. And then it's actually GLM with PI. So those are like the one, two, three um going down there. So you can see depending on like the cost quality tradeoff you're willing to do. One, open source models are getting really good. Two, open- source harnesses might actually save you a bunch of efficiencies and there over using native harnesses.
Um, and so that's actually one of the things that we were exploring is turns out that a lot of the open source harnesses use way less uh of your context window. So they're sending way fewer tokens in and that's actually where a lot of the cost savings um are coming in. But you can only know that if you actually analyze this on your own data um in there. So then I think it's important to call out this kind of crazy stat.
Since May about every 5 days a new frontier model has launched. Uh so the amount of innovation in the model space is just exponentially increasing it seems like. So it's really important that you bake in this model flexibility uh into sort of your like AI future. Uh and so model flexibility is a huge like cost lever that you have where actually many of our customers that we work with are actually trying to move to open source models uh to cut costs uh in a lot of their work.
And so it's important for them to like build these benchmarks uh from all their traces so they can actually figure out you know what's their paro curve for their work to then figure out what to do. So that was the efficiencies that we got on cost. Now for security which I'm going to have to disappoint you all. I'd have to kill you if I shared all the security findings that we found. But I can give you the general direction of what we're looking at with our security.
15:22 Analyzing agent traces for security misalignment
So we're basically looking at all these traces to see if misalignment is happening. So is the agent actually doing what we asked it to do or is it trying to work around what we're doing to do other things. So we're analyzing the traces for that. Uh and then are the agents trying to actually post sensitive stuff on the internet that it's not supposed to be doing and is it like getting blocked by our guardrails and then trying to go around them to do that?
Um so these are kind of the main things that we're analyzing our traces for right now. Uh and then the goal is we're trying to actually build agents to fight the agents uh as they do this. Um so that's sort of like where we're going on the security angle. Luckily, we have many security talks this evening. So if you want more details, you can go to all of those different sessions. Uh but I unfortunately do not have permission to share with you all the things that we've learned on the security side.
All right. So lastly, we have output quality. So what have we found with like how do you get better outputs? uh from your agents. So the first is in coding. Turns out most people are using two to five different coding agents which kind of crazy. I can't believe people are using five. That's a lot. Uh but we've actually found through our own Genie research. So Genie is like the coding agent that we build at data bricks that's like data smart that basically does a lot of like data engineering, data science work and BI analytics.
16:24 Improving output quality with multi-LLM architectures
Uh we basically showed through our research on that that having a multilm architecture gives you the best results. So it was when we combined anthropic and GPT models that we were able to actually see way better accuracy uh in the results. So it kind of like fits into like a whole diverse team thing going our way. Also from the developer survey that we did at the beginning where we like got surveyed like hundreds of developers about how they work.
Uh we learned that over 70% are using two or more coding agents. Now the issue is they don't talk to each other. they don't share conversation history. They can't, you know, share memory across each other. And so engineers are just copy pasting between the two back and forth. Uh which is wild. Uh and as a PM, that's like my worst nightmare is my users are doing that. So that's what's motivated data bricks to kind of look at the layer above the coding harnesses to something that we call the meta harness which is this layer of abstraction over all the harnesses to then say like hey you can actually share context conversation history and controls across all the different harnesses you have rather than having a unique configuration for each one and having to like manually pass it along each one.
17:39 Meta-harness and Omnigent across coding agents
So that's kind of like why we built Omnient and how we saw it today. We rolled it out to all of our engineers. We use it today. We actually built Omnigent with OmniTent. There's a whole deep dive session with Brian today on this if you want to learn more. Um, but kind of the interesting thing uh in here is that the main like research that needs to be done is like what is the perfect recipe? So is it like have Claude code plan, have codeex implement the code and then have like GLM or Kimmy review it or is it some other combo in there that works best?
And so there's a lot of like research going on right now to figure out like what's the right recipe or the best like team for success that you can create of these like multi-harness teams. And so this is one things that we're excited about especially as new models come out and new models are better at different tasks. So my main takeaway for all of you all is please analyze your agent traces. You all will learn so much from this and you'll be able to really improve the efficiency uh of your work in there.
18:54 Takeaway: analyze your agent traces
So like again like we did a pretty simple recipe. It's like you analyze your traces. Ideally with an agent it's way faster. Then create benchmarks from your traces. So then you can do a bunch of experimentation to figure out hey what is the right harness for you? What's the right model? Um and what's the right setup? help you save cost, increase your security, increase your quality um in there. So, use the rest of tonight then to explore deep dive in agent security, explore what's in the open like there's uh I believe like open model talk as well as the open harnesses uh that you can explore and then figure out like what kind of hunches you have about your own usage of your agents uh that then you can deep dive in with your traces uh to explore.
So, with that, thank you all for coming. It's going to be a super fun night. Uh, and I hope that these insights were helpful or relevant to you all uh, as you go about your everyday work. Thanks.
Learn more about the Databricks Data and AI platform.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.