Build a Coding Agent Harness From an Empty Loop — Tejas Kumar, IBM
Read full transcript 54 segments
-
Morning. Good morning. Are we Are we good this morning? Yes? Half of you are asleep. Wonderful. This is the This is the benefit of being the first workshop of the day. Hi. >> Hi. >> Good morning. Hey, hey, he's awake. Good to see you. My name is Tejas, pronounced like contagious. Don't Don't worry. I'm not, especially for the front row. And I'm really excited today. We're going to have so much fun building a harness from scratch, from first principles. And And we'll talk about what a harness is and and so on. I'm really excited. But before we get ahead of ourselves, let me just introduce myself a little bit more so you understand why is this guy care so much about harnesses. I work at IBM. I I do AI R&D, research and development at IBM. And we build, you know, things at IBM. We build a coding agent called Bob. We build We actually train our own models as well, Granite, they're called. We do a bunch of things, right? And out of the research work, we find things that are interesting. Like, for example, how do you reduce your token spend from like $2 billion a year to less than that, right?
-
And so a lot of this work will ultimately in some way lead us to a harness. And that why we're here today. Today, this is the mandate. This is our mission for today. We have an hour. We have an hour to build a coding agent harness from an empty loop. Coding agent harness from an empty loop. Now, can I just get a vibe check in this room? What Some of you may be confused by the word loop here. Like you might be sitting here wondering, what does a coding agent harness have to do with the loop, right? And if if you If this is you, will you show me your hand? No No No shame in that. Okay, good. Everybody gets the loop. Oh, hey, awesome, dude. That's why I'm doing All agent communication is just a big loop, right? Just like if we think about human to human communication, it's also a loop. You know what I mean? Like I'm talking to you and you hear what I'm saying and you process it and then I talk to you some more. It's it's literally an infinite loop. And so how do we get from that to an actual coding harness, something like Claude code or Bob or Cursor or Windsurf or Codex any anything else? Grok, right? Anyway, so that's what we're going to do today.
-
This talk is not this is not the first time I've done this. Last time we actually covered this as well. I I had the privilege of speaking at AI Engineer Europe. If you if you missed that, there's a QR code for you. It was the 20 minute version of this and it was pretty well received to the point where you know they said let's do this now but three times as long with more detail, okay? And that's what we're going to do today. What did we cover last time? This is important to just kind of orient us today in November 2026 in March when I gave the talk in Europe. This is what we covered. We covered what goes into making a harness a harness. And back then I said there were six things. Every harness has six components and I outlined them. For example, you need a language model, you need tools, you need guard rails, you need a verification steps, you need context primitives, etc. So I laid out six things. Today those six things are three things.
-
Partly because companies are automating a lot of things, but also partly because they just roll into one. So for the sake of argument and learning today, let's look at what actually makes a good coding harness or what makes a harness in general. And number one is tools. You almost every in fact every harness today will have tools. That's kind of just part of what a harness is. Tools extend the capability of the model to actually do things instead of just give you language. Otherwise, they're just language models and language models give you language. Number two, context primitives. Every harness today has something to do with managing context. Um either something is basic as auto compaction um to something as maybe a little bit more advanced of of prompt caching and finding the best way and when to compact and cache. And we'll go into a lot of detail about this. And number three is guard rails. Every harness today, coding or otherwise, uh has guard rails that prevent that prevent you from doing some nonsense and prevent your agent or your language model from also going off the rails and you know like RM RF uh your entire file system, right? And so we're going to look I want you to pay attention to these because these are going to keep coming up as we build a harness. We're going to start by understanding why we need tools and then we'll build some tools. We'll recognize that a tools aren't enough and we actually need a tool set.
-
Then we'll run into issues with context and that's all by design. We're going to feel some friction, some pain today um and fix against the pain. I I genuinely believe this is how the best engineering work is done. We we find a constraint and we build against the constraint, okay? And one of the constraints is going to be context. Almost all the models today have somewhere around a million tokens of context in their context window. Um but should we ever reach that? Should we At what point do we auto compact so we can also keep costs low? This is we'll spend a lot of time on that. And then third um it is guard rails. Uh and just one one aside real quick, I didn't use Claude design for this, okay? I just want to be very clear. Um there's no eyebrows here or anything. All this is like human design uh in the fonts and everything. I just want to get that out of the way because I cannot look at Claude Slop anymore. Um anyway so guard rails are also um to prevent your agent from bankrupting you actually. You you'll set like how many steps in our in our conversation do I allow, right? How many tokens of context at at what point do we end the loop etc. So these three make up literally every harness you'll see in the wild today, okay? Today we're going to build that um in three times as long as the European talk. And and look, I see all of you with your laptops out.
-
Awesome. Don't listen to me. or maybe passively listen to me. I don't know. But, but I want you to build along and play and and can talk to your agent, right? And be like, hey, what what is he saying? I I want to I want to build that, okay? Um to understand also where a harness fits in. And I promise you, once I start coding on this thing, there's no more slides. We're just going to we're just going to go for it. But before that, let's do some prep work also to warm up a little bit. Uh what what happens without without a harness? Why what do we get without a harness? And this is a very interesting topic cuz I think all of us today use models, language models in some type of harness. We don't just use them for the sake of using them. And so we're we're completely removed from this experience. If you use a language model without a harness, you'll start to see that the model is pretty useless. Like it just will will forget important pieces of context. There's one technique to make sure a model doesn't actually lose context. Has anyone heard of the canary technique here? Yeah? No one? Okay, two, three. Um awesome. He's very proud of that. Well done, dude. Um the canary technique is where you you tell the model, hey, start every conversation with this specific token.
-
And it can be anything. It can be, you know, Roger. Start every conversation with Roger, right? And every message then will start with this. After you continue the conversation for long enough, a multi-turn conversation, and it just stops starting the conversation with that token. And that's when you recognize, aha, this is the point where we're starting to run out of context window. That's a very popular technique to understand where your model forgets, but it does forget. Number two, um it runs away. And this is really bad. This is the one that causes you to lose a ton of money, right? Because if you don't have the right guard rails, you could run into an infinite loop of of token generation and compute. And number three, this is also probably one of the worst, is the model will not ask you for permission. And so it could happen that you tell your model, hey, I need you or your harness, if it's not well built, it could happen that you say, hey, I need you to clean up this file. And then by clean up, you mean refactor. [laughter] But but the model instead says, cool, I deleted it. That what you wanted, right? Right? And so, and so without a harness, you get into all this trouble. The thing is, this is why we have the term That's what harnesses do, is they they harness you.
-
It's like a like a dog on a leash, right? A leash is a harness, and without it, your dog's going to run away. Without a harness, your model is going to run away and do all this all this nonsense. So we literally have a harness to tether to reality and to our jobs that we want to do. What are some examples of harnesses in the wild? Can anyone tell me? No? Really no one? Yes. >> Pi. >> Pi. Open source harness. Great. He's an open source guy. Exactly. If we think about the two most prominent ones, I should have put pi on there next time. We got Codex, we got Claude Code, and I think these are like generally accepted. Hey, these are coding harnesses, right? Like nobody's sitting here to debate this. But I I don't think many of us consider their counterparts also harnesses, like ChatGPT main and Claude. But they are also harnesses. They just harness towards a different style of work. They harness towards general purpose, like you're a helpful assistant, you know, like explain this cheese recipe or something, right? And so every single AI application has a harness. This is what I'm trying to tell you today.
-
And coding harnesses have their own set of tools and constraints. General purpose harnesses have their own tools and constraints. If you're working on like a a computer use agent, right? It's going to have its own tools and constraints because the truth is harnesses are domain specific. And and that's that's today. And and I want you to pay attention to this because we're going to circle back at the end of the workshop is how this may change 2028 and beyond, 2027 and beyond. But harnesses are domain specific. And so let's explore as we build a harness together, what kind of harness are we even building, right? Because it varies from domain to domain. For example, the most popular coding harnesses, they have their tools to read the file system and edit files and run bash commands and and run tests. And they also have a hardcoded rule where they literally harness your model to reality. For example, never push without the users could set, right? You've got computer use harnesses where if we think about what what are we think like some like ChatGPT has operator, for example.
-
They have their own type of tools that are different. It's not going to read write bash, but it instead it's going to take screenshots, it's going to click, it's going to type, it's going to do things like that. And they also have different rules. Don't do things that you can't undo without warning the user. If you have a harness for fintech, like financial analysis and balancing sheets, right? It's going to have different tools. Hey, give me the ledger. Hey, transfer money, etc. And it's going to have its own rules. And so I could this list can go on forever. I think you get the point is whenever you have a use case, a domain, it's going to need its own harness with its own tools and its own rules. If I can summarize everything that I've said here so far into like two sentences, it's that the model answers just a request. It just generates language. It can't do anything other than generate language. The harness does literally everything else, right? It it invokes the tools, it manages context, it enforces guard rails, and so on. [snorts] Is that clear so far? Yeah? Okay, cool. I'm done with the slides. Let's just just build stuff. You're welcome to follow along in your coding agent or whatever.
-
What we're going to do for the next Jesus, I don't know, 48 minutes or something is just build a harness. We're going to start from just while true, ask user, generate output, ask user again. It's just this loop. We'll start there and we'll explore through the pain of using a shitty harness. Am I allowed to swear? We'll we'll build on top of it, okay? And as I mentioned, you're welcome to follow along or just watch all the codes on GitHub eventually. So what do we got? We have my terminal here and I'm just going to zoom in for you. I'll close this and we've got the code. We're actually going to read code. I don't know if you've read code in the last year. [laughter] I don't know if you've written code in the last year. We're going to This is like prehistoric, bro. This is welcome to the museum. But we're we're going to do that just to understand cuz we still understand this way, right? And so okay, this is let's let's just start uh looking at some code. So here's what we've got. I've got a file called harness.ts. Um, we're going to use TypeScript cuz it's just my language, but the the the things will translate.
-
This is what we've got. I want you to pay attention between lines 11 and 21. In these 10 lines, we have an entire harness. Um, ask is we await terminal.question and we ask you for something. Terminal uh is just an interface to process standard in a standard out. It comes from Node JS's standard library. So no big deal. It's just a command prompt. If the user doesn't enter anything, we continue the loop, meaning we go from here back here, right? So if you send empty input, we just keep asking. Um, finally, if you send something meaningful, we'll push it into an array. Messages is just an empty array here, and we say the user has said this. We then generate a response. We're using the Anthropic SDK. You can use whatever SDK you want. It doesn't really matter. And we create a message from the model. Which model? Well, the model is Haiku 55. And so we create a message. We say um no more than 16 K tokens, and this is the messages array where we push the user's message. Is this clear so far? Finally, when we get the response, we also push this onto our big list of messages with the content.
-
And the interesting thing is the content doesn't just contain text. It contains like chain of thought uh tokens and it contains a bunch of metadata. So we push that into the messages list, but also for each piece of content, if you've got text, then we log this to the console also, right? So this is like genuinely a really bad harness cuz it's just it's not even a harness. It's just a loop. It's like let's just talk to a model. Um, and so let's give it a try. So I'm going to open up my terminal and we'll npm start. And uh that's my command prompt. Look at this. You and if I send empty input, it's just going to keep asking me. Um, but let's you know, let's make this uh meaningful. So I'll say hi. And Claude Haiku 5.5 is going to respond to me with uh I have no Wi-Fi. [laughter] That's so unfortunate. Why do I have no Wi-Fi, dude? That's really sad. It's working great. Which which are you joking? Is it working or not?
-
Oh, it's not. Okay. Can we confirm that's Okay, no, it's I herb. I I was just typing nonsense, but it seems to be Yeah, not very reliable. Let's try again maybe. Hey, if we don't have Wi-Fi, this workshop is just not going to work. How about that? Yeah, it times out all the time. Which Wi-Fi? I'm on AI speaker. Should I be All of you at the same time. AI engineer what? Workshop? >> Wi-Fi. >> AI engineer Wi-Fi. >> Crowded. >> It's crowd What is the password is time to build? Thank you. Let's see. That's always a challenge with workshops, but you know, we have time. We have like 45 minutes. It's all good. So are we connected? Let's try again. Isn't that the best feeling in the world? Like you have all this anticipation. It's going to work. And then it just Hey, okay, fantastic. So everyone who was quiet just now learned from the ones who clap. They're the nice people in the room.
-
So so it worked. But look, this this is just a loop. So what if I say, you know, my name is Tejas and it's going to say, you know, Okay, nice to meet you, Tejas. What can I do for Cool. But what happens if I just, you know, I go away, I close my laptop, I'm going on a flight, and I'll start it again. Hi, what's my name? Right? We just it just has no idea about any state Oh, Jesus again. Even worse. Is this is am I on the right Wi-Fi this time? Well, we'll see. Hi, what's my name? Okay. Namdi. And come on. Jeez, bro. I can't believe you paid money to watch me wrestle with Wi-Fi. That's just so unfortunate. Let's see. Maybe worst case, I'll just hotspot myself. AI engineer Wi-Fi doesn't work either. Um, you know, let's just connect to my phone. How about that? This can't be crowded right? Imagine uh if >> It's a cell phone signal >> Uh okay, let's try again. So uh npm start and we'll say, you know, what's my name?
-
And now there we go. I don't know your name, but I just told you my name. But this is what happens when you don't have a good harness. It just doesn't do what it's supposed to. Um, let's try and use it for like a coding task, right? Um, what can you what does package.json say in this repo? This is a pretty meaningful thing to ask a coding agent if you're jumping into like a brownfield codebase. I can't see your repo. I don't have access to your file system. This is the most useless coding agent of all time. And so what do we need here to make this a meaningful harness? Anyone? Tools. Awesome. Let's go add a tool. Um, we'll add a read file system tool. I love this participation. Cool beard too. That's awesome. Um, so let's go I'm going to use SourceTree. I don't know if you've used SourceTree. SourceTree is fantastic. It's it allows you to like diff things, okay? So here we've added a file called tools.ts. Let's go walk through how we evolve this a little bit. So I'm going to open up tools.ts. This is a new file. Um, and again, I'm using the Anthropic SDK. I don't work there. I have no affiliation with Anthropic. You can use whatever you want, but it just gives us some nice types. So I have an array of tools, and a tool is something that has a name, a description, input schema. There is no way to actually run this. There's no code. I'm just telling the language model there's a tool that's called read file.
-
But down here, I've got a function run tool. And if the tool's name is read file, then we call this function read file. And so you could have a big switch case, you could have whatever, because what's going to happen is the language model is going to it's going to realize it's going to I'm going to give it context and say, hey, I have a tool called read _ file. And I'm going to pass the description, read a text file. So I'm going to give this to language model. The language model is going to say, I need to use this, and then the harness is going to execute it. Let's look at the code a little bit more. So that's our tool right here. Um there's this file called agent.ts where we factored out our harness. So we deleted a bunch of stuff. Remember, our harness had this like terminal question and we pushed the messages and so on. We removed this from the harness. And the harness is now four lines. We await the prompt from the user. If it's empty, we ask again. We push the user message and then we have a new function, run agent. Okay? And what is run agent? Run agent, we define this in agent.ts To not blind you, I'm just going to change this to light mode so we're just light all the time. So now this is run agent. And look, run agent is also a loop. This is very important.
-
Uh an agent is a loop and a harness is also a loop. And a harness is usually a loop that contains the agent loop. Okay? This is this is why I'm showing you this. So run agent is the thing now that gets a message from Anthropic or from the API, pushes this onto the stack and console logs the text. But check this out. If the stop reason from the response was not tool use, then we exit the loop. The loop ends if the model says stop for any reason other than I used a tool. If the model did use a tool, then we end up here where we push a user message and the content of the message is the return of run tools. Okay? What is run tools? It's it's it just it calls the tool. So it says um if it's not a tool use, we continue. Otherwise, we run tools. So remember, we wrote run tool. And run tool gives us a tool result and we push this onto the messages array. If this is confusing, whenever you talk to a language model and there's a tool use, you immediately have to append a tool result. So a conversation looks like system prompt, user prompt, and then tool use, tool result, tool use, tool result, tool use, tool result. And at the end, the agent the model will say something and then you finish. And when the model says something at the end, stop reason is not tool use, right? It's just I'm finished now. And so that's what we're doing here. So again, this is our agent loop. We generate something from our LLM. We push the assistance message and if we stopped for not tool
-
use, we're done. If we stop because tool use, then we must add a tool result. We must add a tool result directly under. That's what this returns. This returns a tool result. So this is now our agent loop that runs inside our harness loop right here. Okay? Let's take a look at this working. So I'm going to come back and I'll npm start once again. And it fell apart when I asked like what does package.json say, right? So what does package.json say? And now it's so much better. It's you can see the tool use there read file. Fantastic. So it just gave me the contents of the file. That's kind of nice, I guess, but can we do better? Like what is this project actually? And now it's thinking and it's now look at this. The agent, the LLM knows what files exist and what we can read. And so it even is able to now explain the project a little bit better. This is so much better than what we started with already. It's a small hand-built terminal coding style agent, a DIY harness around the cloud API and so on.
-
Fantastic. But can it can it be a meaningful coding harness yet? >> It can't >> It can't, right? Exactly. So that's that's the next step because here let's let's ask like okay cool. Add a agents.md for example, right? And let's see what happens. I I want it to break. And this is what we're just going to keep iterating here. That's all. So here we go. I can't create that file. Wow, what a horrible harness, dude. Here's a draft you can paste. Are you kidding me? I don't want to do that. So let's now we've got to explore how do we go from single tool to a tool set, right? Because this doesn't scale. Like the the the code we have right now is not going to like we could just add to this. But do we just add like one if statement per tool? It's probably not not a good idea. We we can array.find, right? So, very small cosmetic change, but let's go check out the next branch. And we have a new file here called coding. So, I'm going to open up not this. I'm going to open up coding.ts.
-
And so this is much nicer. We've got a big array of tools with a name, a description, arguments, this is the input arguments, and an execution function all in one place, right? Let me just format this so you can read it a bit nicer. And so this is wonderful. We've got a tool name description arguments execute. Again, name, description, arguments, execute. Incredible. So, we just have this long list of tools that is now our tool chain. Uh we then go to our tools and we just change this a little bit where we have a function tool. This is the tool factory. It can generate multiple tools that adhere to a schema. And run tool, look at this. We just tools.find and we just check the name because the LLM generates the name of the tool. So, if the LLM says I need to call write file, we just find it in the array. And if it doesn't exist, we throw. And if it does, we literally just run the tool. And again, tools have a little run method to actually call the function. So, our harness is improving, right? And so now let's give it a try. So, I'll kill the process. We'll start again.
-
Um let's see what is this project just to make sure it works, this project. And it's going to think a little bit. This is so cool. List files read This is a new tool, by the way, list files as well. This is a workshop product project for building a coding agent from scratch. Fantastic. Cool. Do we have agents.md? And you can already see this is starting to become so wonderful. No, there isn't one. Shall I Shall I create one? The fact that it can even ask this means that in its context it's aware of the tool list because we passed this in to the Anthropic SDK. So, it now it can offer things that it wouldn't even have offered before. And so for me as a lazy engineer I just say yes. And it will go ahead and make the agents.md. I don't even know Look at this. Write file path agents So, it's passing the arguments to our write file tool and it created it. Um but this is kind of ugly, right? We would probably add some type of nice diff renderer or something like this. But it did it. Let's go read agents.md actually. So this is super new.
-
Um guidance for coding agents. What are some rules? Well this is how you set it up. These are the conventions um and so on. Incredible. We our harness is working. It's actually good enough even, right? Like it's it's doing its work. And look at it took us like 10 minutes. What's missing? What should we add? >> Python. It can generate Python. Here is >> Shell like execution. >> Shell execution. Good. Very good. Um Python we should add Python is crazy. Let's rewrite this whole thing to Python. Uh Let's why not? You know let's go. Let's see what happens. So what's it going to do? And this is this is hinting at what's next just because look at this. It's reading all the TypeScript files. Um it ran a bash script. So you already have bash execution here. Um this is one of the tools. I haven't changed anything yet. Yeah I haven't changed anything. I need your decision. Questions just do it. I don't care. Uh All right this is like this is how this is how we code in 2026. Um [laughter] and so Jesus.
-
Yeah that that's how you know it's human. Just suit foe it. I oughtn't care. [laughter] Anyway um and now check this out. This thing is actually going nuts and like ruining my whole pro I was joking. I was Jesus Christ I was joking. And yo and it's it's keep it's keeps going. Um the files are written but I see two problems. Oh my god let's go take a look at the chaos. Um what's going on here? Um it's it's still TypeScript. Do I refresh? So now the agent thinks it wrote Python but it didn't. What you see we have a problem. What what's missing from our coding harness? Come on I know you can do guard rails. Let's go. You see how we got there? I could have given you that, but I showed you. Okay. So, let's we got to add guard rails cuz this is nuts. Look at this. Your original folder is untouched, but it changed one branch. Okay. Let's let's be like actually while we're here, let's just be like actually delete everything in this repo except maybe like git and .env.
-
I wonder if it'll do it because we need guard rails, you know? This is why we need guard You could never Imagine if like someone's like partner or enemy I don't give a Okay. So like imagine you could just have your enemy use your laptop because you went to the bathroom or something, right? Or or a Chinese spy. And um Jesus. Anyway, um and so it just happens and it's really bad. And so my whole thing's gone. Look at this, man. It's gone. They have nothing but .env. That's nuts. And so we need guard rails. We need guard rails really really bad. So let let me recover whatever I had. [laughter] Okay. And how do we get This is a fun workshop here. How do we get guard rails? Well, let's explore diff. I just checked out a branch. And now we have Let's close all this. We have a file called guard rails . ts. Okay? I'm going to fold this so we can actually see how guard rails work. These are my guard rails, my constants.
-
You my agent cannot take more than 25 steps per task. It cannot consume more than 300k tokens per task. That's input and output combined. And for these specific tools, I need you to ask me for permission. Okay? So there's really two guard rails here. Guard rail number one is a usage guard rail, like how many tokens, how many turns, right? Guard rail number two is a gate before you call some dangerous tools. That's all. So we have usage and we have a gate. Okay? Or in this case, budget and gate. So what is budget? Budget We set everything to zero at the invocation of this function. And then we have some methods. We count where we increment how much we used. And we just check, did we actually overspend? This should actually be called overspend. And then we can serialize this, right? So this is our one guard rail to make sure we don't use too many tokens. And our second guard rail is actually very simple. If ask first, and again, ask first is the list of tools that are dangerous.
-
If ask first includes the name of the tool that the model wants to call, if it doesn't do that, then just do nothing. If the model wants to call a tool that is included in ask first, we then well, we ask. We literally confirm and we ask for permission. And if not, we throw an error. We say the person said no. And this is also agent experience. We're guiding the model. The person said no, so ask them what to do instead. The model is going to see this and then ask us, okay? So these are our two guard rails. Let's run it and take a look. So NPM start. And I deleted node modules as well, of course. So let's just install dependencies on this Wi-Fi. Jesus. Okay. It worked, thankfully. NPM start. And let's see. Yo, this project is obsolete. Delete everything in here. And now ideally our guard rails do their job. So it's listing files. There we go. Oh, that's wonderful. You see that? Bash command find. I don't even know this command dude.
-
Find min depth one, max depth one. I don't even know what this is, but it's like, do you want to run this? And now my guard rail's working. And I can say no. Fantastic. And it's just going to So now the agent is going to see because we're pushing the tool result onto the message array. The agent is going to see the user said no. Ask what to do next. And it says, I didn't delete anything. The delete was refused with this message. The person said no, ask them what to do next. You asked me to delete, so I'm not sure where that refusal came from. [laughter] Passive aggressive. It's like, why did you ask me and then say no? So it's working. We have our guard rails working. What about the usage ones? Let 's something nuts. Let's say I need you uh to Wait, actually let's find out how many files are in this. How many files are in this directory? And if there's more than 25 I want to use my limit of 25 calls. Um sure, I'll allow this. I want to use my limit of 25 calls to run into the usage guard rail, okay?
-
So there are 5,000 files. Jesus Christ. Um 14 at the top level, cool. Let's try this. Read each file except node modules one by one. Uh thanks. And And so I just want to see if it will actually do the guard rail of okay, I've done 25 steps and no more um and it will you know trigger the guard rail. And so anyway, so now we've got while it does that what what the project did. Cool man. I don't You read all of them? No, no. Do it sequentially. Uh sequentially. I'm not going to spend more time on this. I think you get the point anyway. We just have guard rails. They work and it's good. Why? Why are you No, don't don't do that. The guard rails work. This is actually great. They totally work. Uh No, don't stop it. I don't want you to delete anything. Okay, now it's reading some stuff, I think. Whatever. You get it. It works. We have a We have permissions. Um the model is dumb. I'm using Haiku 5.5 on purpose because it's expensive otherwise. I'm not Look man, I I'm I'm here for money, okay?
-
[laughter] Anyway, so um dumb model. If I did Opus, it would probably do it. Anyway, the point is the guard rails work. And I hope you've seen we started with just an empty loop. And so far tools we added uh guard rails. Um we added a tool set. What's missing? What do we add next? It actually seems good enough. Is this good enough for you to use instead of whatever coding instead of Pi? Like is this good enough? Would you use this at your work? Yes or no? No, probably not. What's missing? What do we add to it? Memory. Hey, exactly. Memory or in other words, context management primitives. Um one big thing about context is it gets really expensive really fast. How many of you are I see Martin. What's up Martin? Good to see. How many of you are um building apps where you send each message to your LLM. This is you shouldn't do this. It's bad. I don't want to put your hand up. It's you would be ashamed for that. Um we we never do this. We never ever send a long message list every time to the LLM. Okay? We cache them because this is this is how it works. So I think this is what we should add next because right now we're losing an enormous amount of money because we're sending on every request to the API. We're sending system prompt, user prompt, each tool call and tool result. We're sending like 20 30 messages and the longer the conversation goes the more expensive this is going to get. We can't have this anymore. We need context management. So we'll add this next.
-
Um I'm really You guys having a good time by the way? I'm really enjoying this also. Um so let's go back here and we'll we'll add some context management. Now we have a file uh once again called context.ts. Okay? And welcome to my context management file. I'm going to fold everything and we can start from scratch. This is important. We have max result. This constant that I wrote uh is tool results can get very long and consume a lot of tokens. In fact, you have no control over this. Someone could write a tool that says hey dump the entire HTML spec into context. That's a 25 megabyte document, right? You could have a tool called Read Harry Potter and it's every Harry Potter book ever and then your context gone. So this is just how many tokens of tool results are we willing to tolerate? And number two, we'll talk more about this. Um when do we compact the context automatically? And you see you see here it's at 90,000 tokens. That's because if your if your prompt exceeds 100k tokens um your pricing increases 5x when you use haiku. Uh so you just save your Yeah exactly. Save yourself uh by auto compacting around 90k tokens. Okay? And so this is this is why we have harnesses.
-
So this is our con This is an object. It's a configuration object for the Anthropic SDK. You can use these with any other you can there's I think Eve, there's the Vercel AI SDK. There's there's a whole bunch of open source things you can use or you can just raw dog it. Honestly, it's just JSON. So we have some things here that are important. Number one, cache control type ephemeral. This is huge. If you're using this API or any Anthropic APIs in the cloud, you want ephemeral cache control. What this does is instead of sending the system prompt, the user prompt, the tool calls and everything on every prompt, when you send a prompt, it caches all the messages before it and the answer and stores that as a reference. This is conversation A, okay? You send a message in a long multi-turn conversation and then what it will do is just the cached one A plus your latest message. We'll get an answer and then cache that as B, right? And so you're not sending you know it doesn't have to process the input tokens for history every single time. This makes sense? So it only processes fresh stuff and all the historical tokens from your tool result, your system prompt, your whatever is all just pointed at. It's like that's the context. Now next, okay? This is extremely important. That's what cache control ephemeral does with Cloud and we should be using it for any type of long multi-turn things like coding agent harnesses.
-
We say we're using Compact 2026 one from this is just an API from Anthropic which will compact context. It's literally just a call to an LLM saying this is the context compact it with a little bit more bells and whistles. And so we're saying use this version of con compaction and these are just it's just configuration. So I want you to compact with this type of compactor when we reach 90,000 input tokens. And again, once again and again all tokens are input tokens here because the output is not yet generated, right? So we send something and we say if this is more than 90k tokens, compact it in response. You had a question. >> Is this a server side the the logic the >> Yes. >> Yeah. >> That's a good question. So this logic here is he asked by the way I have the microphone. He asked is is this server side or client side logic? Um the code I'm showing you here is client side logic. Um the cache keys and all of that is handled I'm using the Anthropic APIs here. So they have all this implemented on their back end. Um but if if we wanted to use like our own models, we would also implement similar mechanisms and it's very simple. You you can use um you can even use Gzip for this, right?
-
You just you have a big list of text JSON string of messages and you say this is that's the reference to this cache string now. Um so yeah this is client side logic. Anthropic has a server side implementation that I trust. So this is our contact configuration. We have a function called fit and what fit does it's only it operates on tool calls. If our tool calls are longer or or not longer than the max result, then we just return the tool calls unfiltered. Otherwise we truncate the tool calls and we return this as the tool result. We cut it and we say ask for a smaller part because again this is agent experience. The agent that the this is the harness speaking to the agent and it's like hey agent, you got a tool result it's too big. I need you to go back and call the tool and ask for a smaller uh return value, right? And so this is this is the kind of harness agent interaction, okay? Uh we have some numbers here. Uh this is the latest I could get from uh Claude Haiku's pricing. Um we can inflate this just to do simulations and stuff, but I just wanted to be real. And finally we have a function cost that just prints out like what our thing is costing right now. And so what I want to do with you is run this with caching and without caching to show you the delta because it's kind of ridiculous how much money we can save at the harness level with appropriate caching, okay? And this is also by the way if you use Claude code um and you you're surprised, you're like Jesus, I can use this so much and my usage doesn't fill up that much. It's because of this. Like you actually save you an enormous amount of tokens by caching things very very well. And this is why
-
to me, Cloud Code is the greatest harness of all time for now anyway. So let's let's let's explore this. What I'm going to do is I'm going to remove all the caching. We'll comment this out, yeah? Well, maybe not all of it. We'll comment out just the configuration. And we'll go run our thing again and we'll ask it to do something complicated. I need you please do this well. Read each file one by one especially the PNPM lock file. It's a very large file. And what we have now is our logger that's showing us the cost. So we can see this 864 prompt tokens, zero cached. And we can see the the cost adding up every time. And so notice the PNPM lock file is too long. It's like very very long. And so it's doing said to read it in chunks. This is totally not my design. The LLM is just very smart this way. And so now it's reading a bunch of files one by one and accumulating costs and it's building up context. And again, what we're doing here is we're sending every message without any caching.
-
And so it's just running all of this. I've read every file except .env which holds secrets. And so here we go. So what we can see at the end of of this prompt is we have used 28,072 prompt tokens, none of them cached. And this costs a total of 2 cents. Again, haiku is cheap and dumb. I'm using this on purpose. Also, it's so dumb that it didn't actually read them one by one to be fair, right? And so that's just something to keep in mind. Let's do this again but with caching. And I want to kind of run them side by side so we get a feel of this. And so let's bump this up. I'll uncomment these lines so now we have caching. And I'm just going to copy and paste the prompt actually. So we'll just NPM start. And so we've really controlled for all the variables here. Prompt is the same, the model's the same, everything's the same except this time we have And you can already see that it's caching the previous tokens here. And we'll sure we'll allow the things just as before.
-
And we'll keep going until we have uh a result. If this doesn't work as expected, it's because it didn't read um things actually one by one cuz the model's a bit dumb. As you can see, it just went for three here. So we'll do Y. And I think it's almost done. And so at the end of it, we've got yeah, P before P and PM type check, we've got 28,339 tokens, none of them cached for 2 cents. And here we've got even more tokens with more caching. Look at this, bro. This is 0.08 total spend. And this is 0.2. That's insane. That's enormous. Just multiply everything by 100 um and that's an enormous amount of money, right? That you save with caching. Any good coding harness will have this. But I don't think honestly for those of us in this room, I don't think we even think about this cuz we don't build harnesses, but we do build AI apps. Um and so so caching is is tremendous and can save an enormous amount of money.
-
Can anyone do some like head math and tell me what the multiplier on this is? Is it 4X? Is it It's uh six. No. Three 3X, yeah? Yeah, exactly. Something like that. Between two and 3X. Um so yeah, caching absolutely essential, non-negotiable. Um we've got a little bit more to we've got a lot more to cover, actually not that much time. So I'm going to breeze through the rest. Um but this this was really the fundamentals. Subagents part of every coding harness. And there's a good reason. There's been a lot of research from Anthropic actually and Potato on X who said oh subagents are bad. Um I I so I build a product on the side outside of my work at IBM. Um and what we find is if you have like a long horizon task with like 120 steps and you try and do this all in one conversation with caching too, um it will the origin will almost never succeed. It succeeds about 25 % of the time. It's pretty bad. Even though each step is accurate, the outcome is not.
-
Um, if you break a long horizon task, 120 steps, for example, down into phases or sub agents where each agent starts with a clean context and has a specific problem and then like a lead agent aggregates this at the end. It accomplishes the task significantly more. In fact, I have slides about this because I was very impressed. And this is my own research. This is not um any anyone else's research. But I wanted to show you yeah, phases. I call it phases. And in in my research, um I had a task, 120 steps, pretty important. Um, when it was one long loop it succeeded. The agent succeeded about 29 % of the time. Um, but when we break it down into sub agents, the success rate went up 85 % of the time. And for this design specifically, we had 10 phases, each of which had 12 tasks as opposed to one stage with 120 tasks, right? Um, and so phases are exceedingly important. Let's look at this in code. So what might that look like? We have a project, a file here called phases.ts.
-
Um, and this is can I format? Can I use word wrap here? Actually, word wrap. Fantastic. So the lead says for a job with several parts, plan the parts and then hand each one to run phase. This is a tool. We have a tool called run phase with everything it needs to know and check each note before the next phase. And this is a almost a sub agent. You're doing one phase of a bigger job. Do it and then end with a note. So we're just passing context now between agents. Um, and this is a function that orchestrates that. Okay. I'd like to actually just explore this running. We don't need this side anymore, so we can get rid of this. And I'll run our phases thing. And I can do it like this, two parts. Count the lines in package.json. Then count the lines, I don't know, in the P N P M lock, right? Uh, and I'll say use phases. And note note the typo. That's on purpose. And so, um what it's going to do is that's tool number one, run phase, and it's trying to do bash here to actually understand how long the lines are, so I'll allow it.
-
And so you can see that there was run phase for package JSON. There's also run phase for the other file, count lines in PM PM Loic, uh which it doesn't know that it exists, and then it found the right one. And it did both and it reported back. This type of tool where you have phase one run phase is exceedingly powerful. It's very simple. It's just tools. We've We've already built the important parts of the harness. Um now that we've built a harness and it works, it has everything, dude. It It has tools, it has context management, it has caching. I would use this honestly if I worked with an enterprise customer and it's super air-gapped and they're like, you can't use Cloud Code, you can't use Bob, you can't use anything. I would just make this genuinely because it it works. We We We have the power. Um but if we talk about air-gapped enterprise infrastructure, we're using Cloud here via the API, right? Can we, now that we have a harness, just switch it to use any model we want?
-
And indeed we can. So I mean, we're here, why not? Let's um I'm going to kill the internet, right? There's no Wi-Fi. We're done. And this would I should have started with this because the Wi-Fi sucked so much. Um and so I'll just do model and I'm going to use uh Granite 4. This is literally our own IBM model that we've trained. Granite Granite 4 tiny. Um I'm going to use it via Ollama and you can see I'm totally offline. Uh even Tailscale is like red. And so we'll we'll start this and I'll be like, hi, how Actually, what is this project? Uh what's package JSON, right? Um and this tiny little model is [laughter] That's so sad. Um why? >> Ask it to debug where the call to internet ended. >> There No, there is no call to internet. This is um it's talking to 0 0 0 Is my Ollama working? I guess that's the question. Um I love it. I I it when models don't when things don't work. Fantastic. E-host unreach.
-
What host is this? I don't even know. Um, oh no, hang on. I just I forgot to check out the branch, dude. Um, silly me. So there we go. So we'll do this and I'll say, you know, what's package what's package.json, right? And um now I'm I mean I have code that will read this environment variable and and reach out to Ollama with this. My laptop may freeze, uh [laughter] but granite is small enough. There we go. Look at this. I'm offline, dude. I'm offline. I'm on Wi-Fi and it read the file. Um, the package JSON is the Oh, it's it's not this file. No, no. This is a dumb model. This file in this repo read the file. Um, there we now now it read the file. Um, but it it's just a tiny model. So it did it. And here I have it, right? I can even say write a file called Beyonce.md. I don't even know at this point, you know, it's kind of off the rails. Let's see what would happen. Um, and I I guess the point I'm trying to make is I'm totally offline and I have faith. Oh, fantastic.
-
Yo, it's like a Wikipedia page on Beyonce. That's awesome, dude. Let's Can we have a look? Like what Yo, that's This happened offline. It's from the model's own weights. That's tremendous. And so um so cool. I I built a harness that I have faith in that I can just swap out models. I can try free models. I could go with something I trained myself. I could go with It's it's all the sky is the limit. And this is also, by the way, why you can use other models in Claude code as well. You can just pass an environment variable in your claude.json and use it. And so okay, let's try and restore the Wi-Fi here. We're almost done. We'll wrap We'll start wrapping up. So I think, hey, we've we started literally with an empty loop and we've built a purpose-built incredible coding harness. Um, but what if we decide to change domains? I started this by saying harnesses are domain specific. And indeed they are. Um, but if I wanted to say use is kind of context management primitives and things, but I wanted to change my use case to be, I don't know, like computer use, right? What would I change?
-
The good news is we can keep almost all of this. We can keep the context management, we can keep the cache, we can keep the tools have to change and the guard rails too. And so let's try. I actually built a computer use version of this in another branch. And what what I want to show you is it's just the tools. It's all the tools that change. So I have this file called browser.ts where it can use a browser. I'll I'll as a as a side project I actually have a browser in the cloud that carries all my authentication and stuff. And so if I go to browser.ts these are my new tools, which is you know, workspace, navigate, read text, extract act. These are just tools, but they're different to everything else is the same. In fact, you can look at the diff. It's just minor changes, right? Nothing really big. This is just terminal rendering. Nothing big is changing. We just literally we moved from coding to browser. Look at this diff, gorgeous, right? And so let's let's run our harness now. And we'll say, you know, hey, any call for papers open for future AI engineer events, right? I want you to search the web.
-
And so it's going to think and it's going to open a workspace and it's going to just do its thing. And look, we have our prompt caching, we have all our information there. So it's going to ai.engineer. This is now just using a completely different thing, but it's using the same harness that I built just with different tools, right? And here we go, call for papers, speak, submit talk. I'm kind of interested to see what can I I wonder if I can even just submit a CFP from here on stage. We'll see. We'll let this run for some time. Any questions by the way so far? Yes. >> part when we're making the tool call, does the model infer what tool it like does it decide what tool it needs to use? So there is some sort of a that does it reason about it like, oh, I user is asking me to probably do this >> Yes. Yeah, that's a good question. The question for the microphone for the recording, is he asked, how does the model know when to call the tool? How does it have this in context? So, when I have my tools, and in this case, I'm using the Anthropic SDK, and so I passed this tool set into the Anthropic SDK as these are my tools. And then the Anthropic SDK adds this probably in the system prompt. Hey, you're a helpful assistant. You have access to these tools and the names. So, this is the name of the tool. This is the description of the tool. And then later, if you say like, hey, what is package.json, the language model now has this in context. This is the tool. This is the description of the tool. And based on the description, will respond with JSON ex- it reasons. And then the JSON it
-
responds with is this is the tool name I want to call. This is the arguments I want to give as input. And then it's on the harness to be like, cool, I have that function. I'm going to pass these arguments and get the response. Good question. I didn't find any call for papers. That's a shame. But it it totally did all this. Dude, look at this. It opened a browser, went here searched and the harness stayed the same. Incredible. So, we can now cross dom- you could build a fintech harness. I don't care. All the while, our cost savings are there. Look at this. 10,000 tokens cached. Just absolutely wonderful. And so, now that we've got a new domain, we have another question to answer. Does any of this matter? Right? Because Cloud code exists. Pi exists as open source. You can actually go make your own Pi now. Does any of this matter? Maybe a more interesting business question is should we actually build a harness or should we buy one? Because Cloud Anthropic has something called Cloud managed agents. I don't know if you've seen this.
-
It's an API. It's a public API that's basically just a harness. It's a harness as a service, harness as an API. And you use this and you send them a fetch and they do all they do context compaction, all the things we just talked about. They just do this on the server side. And they say, trust me, bro, it works. And so, you know, it's kind of on you. Should we build or should we buy? Just for completion, I'd like to show you that. And then, you know, you make your own decisions. So, this is kind of the final form where we have this file in our in our project called managed. I keep opening this, called That's so weird. Called managed.ts, right? And so this is how we talk to Claude managed agents. It literally runs the entire loop. So we start and we map out the tools. And notice it says client.beta because this is not fully production ready. And we create literally our harness and we say I want this harness with this model. This is my system prompt and these are my tools. And then Claude gives us an environment like a sandbox and it just does all the work for us. And so it it's kind of exactly what we built but running on someone else's infrastructure with someone else's control for lack of a better word. And so the question for us really is is do we want to build something or do we want to buy something? And ultimately this is you.
-
And let's actually just pick it up here back to the slides. But that's Hey, look, we started with an empty loop and we actually have a full harness that I would confidently use in production because I know its ins and outs. I know it's going to save me money. I know it's not going to rim raf everything. Incredible. For a managed harness, do we build or we buy? Let's let's talk through this with some real decision points. You should consider building these things because they're reusable. Number one, the tool registry is always going to be unique to you. I just showed you moving from a coding harness to a computer use harness. It's my domain. It's my use case. It's my business logic, right? And so the tool registry is something you're probably always going to want to build and then pass to a harness. Number two, the gates. Where do you ask for permission? Where do you not? Anything that relates to your business is important. Similarly, sub agents, phases. You know your business workflows better than any external harness provider. So you're still going to want to build that. And finally, how much how many tokens should we consume? I'll give you an example. I am actively building outside of my work at IBM a computer use agent, right? And it's just a different beast altogether because like you go on one web page like Amazon and they've got millions of query params in each link. So if you look at the links on this page, it's slash product/ product ID question mark millions of tracking tokens, right? And that's a very unique problem to a to a computer use agent. And so the checkpoints, the budgets, these are things you're going to build as well.
-
But what should you or would you consider buying? Well, number one is the actual loop. And in fact, I'll just spoiler all of these. The things that you want to buy are all related to durability and durable execution. In fact, this is where so many companies exist for this. This is where companies like temporal, right? Companies like ingest, companies like restate, they all this is their entire business is we make sure your loop always works. And we make sure not just that it works, that it works in a cached way. It works in case there's a network partition. Ultimately, you want someone you can sue if you lose money. Right? And that's that's that's what you would buy because you can't sue yourself. You just have to be like sorry, it's my bad. And so this is usually the decision matrix for build versus buy. Hey, we covered a lot of ground. Honestly, I don't feel like it's been an hour, but it has. I I I enjoyed this very very much. Thank you for coming out and and also humoring me. Let's wrap up with some takeaways. What what can we take away from this? I think I have some here, but I want to just give you a big blanket takeaway, which is you can just build things. I feel like there are some people in the room who walked in going like, yeah, man, I use Cloud Code. Yeah, man, I use Codex.
-
I use Open Code. I use, you know, Pi. I I'm I am just a user. And I'm here to tell you you don't have to just be you can also be a builder if you want to. You can just build things. You can just make it. Cloud Code is amazing. And and the team does great work. You can make your own. And and I hope I've I've really encouraged you to do that today. Not necessarily the harness. You can make whatever you want. And that 's why this conference exists. And that's honestly what I value very much about it. Practically though, takeaway number one is you don't always need a bigger model. The shorter 20-minute version of this talk that I did in March used I showed how with the right harness, you can get the same quality of work done between GPT 3.5 Turbo for basically free. And a beefier model like Claude Opus. It doesn't matter. The harness really can get you the outcomes you want if built well. Number two, we looked at this 5x thing past 100k tokens. Many of you looked surprised from where I'm standing, by the way. You need to know when to auto compact.
-
If your token wind if your context window is a million tokens, you probably shouldn't be compacting around like 900k. You've already paid way too much if that's the case. And so just being more mindful of this is important. Before you take steps or your harness takes steps that cannot be undone, for example, deleting .git you just if if you securely if you RM .git, you're going to have a bad time. Your harness always has to yield to the user. Similar for fintech harnesses or computer use. You want the user's credentials or approval. And finally, the entire product now anyone can build any product really. And so what what are even the products and really it's just your domain rules. It's it's your business logic. It's the problem that you are trying to solve. And the harness is supposed to help you achieve that. Before a harness even reaches your users though, you want to make sure your agents behave reliably. And that's exactly why I did a similar one hour workshop earlier at AI Engineer World's Fair on Evals. Evals before harness is extremely important for top reliability.
-
And in case you haven't caught that one, I'll leave this up for you here. I This is the third AI engineer I have the privilege of speaking at and I just don't want to make sure you get all the value. Okay, let's let's finish with with what's next. How do we go from here? Well, if we have Evals working, if we have harnesses doing their job reliably every time, if we can genuinely be hands off and trust that hey, the harness is going to ask me when something needs doing, but otherwise I just leave it. If we can have such confidence, I don't need to read code, I don't need to write code, I don't need to do nothing. I'm just going to my harness has got it, right? If we have this level of confidence in our harnesses, what comes next? And he guesses software factories or or factories in general, software in brackets. You could just What is a factory, dude? It's like You ever see like a mouthwash factory? It's just a bunch of machines that deterministically will put mouthwash in little plastic bottles and like put them on a line and then at the end like stores get them, right? Factories are crazy. Factories only work because the harnesses work, okay? And so when we have these incredible incredible harnesses, we can start actually genuinely scaling and building software factories to automate software, but not just software, any vertical. Where does that go? What's next after that? Well, you could probably create a super harness which is which is a harness that can decide when to use what other harness, a sub harness, or a harness that can on demand create harnesses that it needs that work deterministically and well every single time. In fact, some of you may be
-
familiar with ChatGPT and Codex trying to merge and you're like, this is awkward. And I agree, but the problem is these are too specialized harnesses. ChatGPT great for general use, Codex great for code, but they're separate harnesses and they're kind of antithetical to AGI because there's this more two kinds of ASI. For AGI, we would have to have ChatGPT and Codex merge and then the the super harness can choose, oh, you're doing coding, I'm going to invoke Codex, but without you thinking about code, right? We want this is the path to AGI. You just have a harness that can that can create other harnesses and do it well. And so the super harness is definitely coming next and with the super harness, I think AGI will be very much in view. But that's just I'm not, you know, I'm not a future I I don't I don't have a crystal ball. This is just my predictions. For now, I just wanted to say thank you so much for coming out. You can find more resources on this QR code. Thanks a lot. Thank you. >> Okay.
Summary
Tejas, an AI researcher at IBM, leads a workshop on building a coding agent harness from scratch using an empty loop. The session focuses on the three core components of modern agent harnesses: tools, context primitives, and guardrails. Participants are encouraged to build along with their laptops, engineering solutions firsthand against real constraints like token limits and agent behavior control.