Build a Coding Agent Harness From an Empty Loop
AI Engineer Code Summit 2026 (Workshop) / 1:01:19
Chapters
- 00:00Introduction and workshop goal
- 03:00Tools, context and guardrails
- 06:26What fails without a harness
- 08:28Why harnesses are domain specific
- 11:18Starting with an empty conversation loop
- 17:09Adding file access and the agent tool loop
- 22:09Building a tool registry
- 26:26Usage budgets and permission gates
- 32:33Context management, caching and compaction
- 38:24Comparing cached and uncached requests
- 42:19Phases and subagents for longer tasks
- 45:50Running the harness locally with IBM Granite
- 48:40Changing domains: browser tools
- 52:15Build versus buy: managed harnesses
- 56:18Practical takeaways and evaluation
- 58:46Software factories and future harnesses
Transcript
59 paragraphs
This is an automatic transcript of the recording above. It is published in full and unedited, apart from correcting names the recogniser reliably mishears. It will contain mistakes.
00:00Morning. 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 Tis. Uh pronounced like contagious. Uh don't don't worry, I'm not. Uh especially for the front row. Uh and I'm really excited today. We're going to have so much fun uh building a harness from scratch from first principles and and we'll talk about what a harness is and and so on. Really excited. But before we get ahead of ourselves, uh let me just introduce myself a little bit more so you understand why does this guy care so much about harnesses. Um I work at IBM.
00:53Uh I I do AI R&D research and development uh at IBM and we build you know things um at IBM we build a coding agent called Bob. We build um we actually train our own models as well granite they're called. Um 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's why we're here today um 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 a coding agent harness from an empty loop loop. Now, can I just get a vibe check in this room? Uh what some of you may be confused by the word loop here?
01:44Like you might be sitting here wondering um what does a coding agent harness have to do with a loop, right? And uh 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 this. Um all agent communication is just a big loop, right? Just like if we think about humanto 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 codeex um any anything else? Grock, right? Uh anyway, so that's what we're going to do today. Uh this talk is not this is not the first time I've done this. Uh last time we actually covered this as well. I I had the privilege of speaking at AI Engineer Europe. Uh if you if you missed that uh there's a QR code for you. It was the 20inut version of this and it was pretty wellreceived 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. Um what did we cover last? 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
03:12components and I outlined them. Uh for example, you need a language model, you need tools, you need guardrails, you need verification steps, um you need context primitives, etc. So I laid out six things today. Those six things are three things. Um 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. Um you almost every har in fact every harness today will have tools. Uh that's kind of just part of what a harness is. uh 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, um context primitives. Every harness today has something to do with managing context.
04:06Um either something as basic as autocompaction 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 guardrails. Every harness today, coding or otherwise, uh has guardrails 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 hey 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 autoco compact so we can also keep costs low? This is we'll spend a lot of time on that. And then third um is guardrails. Uh and just one one aside real quick. I didn't use cloud design for this. Okay, I just want to be
05:27very 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 cloud slop anymore. Um anyway, so guardrails 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 will 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 uh or maybe passively listen to me I don't know but but I want you to build along and play and and you 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 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 because 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
06:45a language model without a harness, you'll start to see that the model is pretty useless. Like it just will we'll 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 uh Roger start every conversation with Roger, right? And every message then will start with this after you continue the conversation for long enough the 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 when 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.
07:36This 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 you say, hey, I need you to clean up this file. And and by clean up, you mean refactor, [laughter] but but the model instead says, "Cool, I deleted it. That's 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.
08:21Without 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. Uh, what are some examples of harnesses in the wild? Uh, can anyone tell me? No, really, no one. Um, 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. Um, we got Codeex, got cloud code, and I think these are like generally accepted. Hey, these are coding harnesses, right? Like nobody's sitting here to debate this. Um but I I don't think many of us consider their counterparts also harnesses like chatgpt main uh 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 uh cheese recipe or something right and so every single AI application has a harness this is what I'm trying to tell you today um and coding harnesses have their own set of tools and constraints um general General purpose harnesses have their own tools and constraints. If you're working on like a a a computer use agent, right, it's going to have its own tools and constraints because the truth is harnesses are domain specific. Um 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
09:39the workshop is how this may change uh 2028 and beyond um 2027 and beyond. Um 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 um 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 hard-coded rule where they literally harness your model to reality. Um for example, never push uh without the user's consent, right? Um you you've got computer use harnesses where if we think about what what do we think like some um like chat GPD has operator for example um 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.
10:34If 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. pace, 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 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 guardrails and so on.
11:14[snorts] Is that clear so far? Yeah. Okay, cool. I'm done with the slides. Let's just let's just build stuff. Um, you're welcome to follow along uh in your coding agent or whatever. Um, what we're going to do for the next Jesus, I don't know 48 minutes or something is uh 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. Uh am I allowed to swear? Um we'll we'll build on top of it. Okay. And uh as I mentioned, you're welcome to follow along or just watch. Uh all the code's 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. Um 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 welcome to the museum. Um, but we're we're going to do that just to understand because 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 because 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
12:33entire harness. Um, ask is we await terminal.quest question and we ask you for something. Terminal uh is just an interface to process standard in and 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 no more than 16k tokens. And this is the messages array where we push the user's message. This clear so far.
13:25Finally, 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 it's not even a 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. Um, why do I have no Wi-Fi, dude? That's really sad. It's working great. Which are you joking? Is it working or not? Oh, it's not. Okay.
14:31Uh, can we confirm that's okay? No, it's I Herb. I I was just typing nonsense. Um, but it seems to be Yeah, not very reliable. Let's try again, maybe. Um, hey, if we don't have Wi-Fi, this workshop is just not going to work. How about that? Yeah, times out all the time. Which Wi-Fi? I'm on AIE speaker. Should I be all of you at the same time? AI engineer. What workshop? Wi-Fi. Yeah, engineer. Wi-Fi. Crowded. It's crow. What is the password? Is time to build. Thank you. Uh, 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, learn from the ones who clap. They're the nice people in the room. Okay. So, um, so it work. But look, this this is just a loop. So, what if I say, you know, my name is Tis and it's going to say, you know, um, okay, nice to meet you, Tis. What can I do for you? 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? Um, right. We just, it just has no idea about any state. Oh, Jesus again. Um, even worse. Is this is Am I on the right Wi-Fi this time? Well, we'll see. Hi. What's my name?
16:06Okay, Nambdi. And uh, come on. Jeez, bro. I can't believe you paid money to watch me wrestle with Wi-Fi. That's just so unfortunate. Um, let's see. Maybe worst case, I'll just hotspot myself. AI engineer Wi-Fi doesn't work either. Um, you Let's just connect to my phone. How about that? This can't be crowded, right? Imagine. 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 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.
17:17Cool beard, too. That's awesome. Um so let's go. I'm going to use source tree. I don't know if you've used source tree. Source tree 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's no way to actually run this. There's no code. I'm just telling the language model there's a tool it's called read file but down here I've got a function run tool and if the tool's name is read 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 real 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 underscore file and I'm going to pass the description read a text file so I'm going to give this to the language model the language model is going to say I need to use this and then the harness is going to execute it.
18:26Let'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. A an agent is a loop and a harness is also a loop.
19:12And 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 tool. 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 stopped because tool use then we must add a tool result.
20:42We 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? Um 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.
21:29This is so much better than what we started with already. It's a small handbuilt 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 write. Exactly. So that's that's the next step because here let's uh let's ask like okay cool uh add a agents.mmd 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. Uh, 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 code we have right now is not going to like we could just add to this.
22:19Um, but do we just add like one if statement per uh tool? It's probably not not a good idea. We we can do array.find, right? So very small uh 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. So, 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 it again. Um let's see uh what is this project just to make sure it works. This project and it's
23:47going to think a little bit. This is so cool. List files re 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.mmd? And you can already see this is starting to become so wonderful. No, there isn't one. Should 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 right file tool and it created it.
24:32Um but this is kind of ugly, right? We would probably add some type of nice diff render or something like this, but it did it. Let's go read agents.mmd 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 did it took us like 10 minutes. What's missing? What should we add? Python. It can generate Python. Here shell execution. Good. Very good. Um Python, we should add Python. It's 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 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 right. This is like this is how this is how we code in 2026. Um, [laughter] and so Jesus.
25:48Yeah, that's how you know it's human. Jut fo 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 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 guardrails. Let's go. You see how we got there? I could have given you that, but I showed you. Okay, so let's um we got to add guardrails cuz this is nuts.
26:38Look at this. Your original folder is untouched, but it changed one branch. Okay. Uh 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 guardrails, you know? This is why we need guardrail. 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. I have nothing but that's nuts. And so we need guardrails.
27:28We need guardrails really really bad. So let let me recover whatever I had. [laughter] Okay. And how do we get This is a fun workshop. You How do we get guardrails? Well, let's explore a diff. I just checked out a branch. And now we have Let's close all this. We have a file called guardrails. TS. Okay, I'm going to fold this so we can actually see how guardrails work. These are my guardrails, 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. Um, and for these specific tools, I need you to ask me for permission. Okay? So, there's really two guardrails here. Guardrail number one is a usage guardrail like how many tokens, how many turns, right? Guardrail number two is a gate before you call some dangerous tools. That's all. So, we have usage and we have a gate. Okay? Uh, 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.
28:42This should actually be called overspend. Um and then we we can serialize this. Right? So this is our one guardrail to make sure we don't use too many tokens. And our second guardrail 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 um 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 guardrails. Let's run it and take a look. So, npm start and oh uh I deleted node modules as well of course. Uh so let's just install dependencies on this Wi-Fi. Jesus. Okay.
29:37NP it worked thankfully. npm start and let's see uh yo this project is obsolete. Delete everything in here. Um and now ideally our guardrails do their job. So it's listing files. There we go. A that's wonderful. You see that bash command find I don't even know this command dude find minepth 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 guardrail is working and I can say no um 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.
30:24So, I'm not sure where that refusal came from. [laughter] It's passive aggressive. It's like, why did you ask me and then say no? Um, so it's working. We have our guardrails working. What about the usage ones? Let's try 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 guardrail. 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 guardrail of okay, I've done 25 steps and no more. Um, and it will, you know, trigger the guardrail. So anyway, so now we've got while it does that what the project is cool man I don't you read all of them 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 guardrails they work and it's good why why are you No don't don't do that the guardrails work this is actually great they totally work uh no stop it I don't want you to delete any Okay, now it's reading some stuff, I think.
31:54Whatever. 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 guardrails work. And I hope you've seen we started with just an empty loop and so far tools, we added uh guardrails. 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?
32:35Memory. Hey, exactly. Memory or in other words, context management primitives. Um, one big thing about context is it gets really expensive really fast. Um, how many of you are I see Morton. What's up, Morton? Good to see. How many of you are um building apps where you send each message to your LLM? This you shouldn't do this. It's bad. I don't want to put your hand up. It's you would be shamed 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.
33:24We 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 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?
34:19And you 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 Yeah, exact u by autoco compacting around 90k tokens. Okay. And so this is this is why we have harnesses. So this is our con this is just an object. It's a configuration object for the anthropic SDK. Um, you can use these with any other you can there's I think Eve, there's the Verscell AI SDK. Um, 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 uh 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 uh 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 f you know it doesn't have to process the input tokens for history every single time. Does this make 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.
35:54Okay, this is extremely important. That's what cache control ephemeral does with cloud and uh we should be using it for any type of long multi-turn things like coding agent harnesses. Um we say we're using compact 202612. 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 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, one second. 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 and respond. You had a question.
36:44Yes. 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 backend. Um but if if we wanted to use like our own models, we would also implement similar mechanisms. And it's very simple. You it's 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 serverside implementation that I trust.
37:31So this is our context 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 har 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 uh 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 cuz 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 cloud 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're they save you an enormous amount of tokens by caching things very very well and this is why to me cloud
38:49code is the greatest harness of all time for now any so let's let's let's explore this what I'm going to do um is I'm going to remove all the caching we'll comment this out yeah uh 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 uh read each file file one by one. Um, especially the PNPM log file. It's a very large file. Um, 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 uh 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.
39:40This 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 um 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 virtual 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 uh 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 uh 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 caching. 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.
40:57and 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 because 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 PNPM 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 because we don't build harnesses, but we do build AI apps. Um and so so caching is is tremendous uh and can save an enormous amount of money. Can anyone do some like head math and tell me what the multiplicator 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 in not that much time so I'm going breeze through the rest. Um but this this was really the fundamentals sub aents part of every coding harness and there's a good reason. There's been
42:29a lot of research from anthropic actually and potato on X who said oh sub aents 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 your agent will almost never succeed. It 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 aents 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. Uh 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 u 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 aents 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.
43:56So, 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 rap 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.
44:35And I'll run our phases thing. And I can do it like this. Two parts. Count the lines in package.json. JSON then count the lines I don't know in T PNPM lock right uh and I'll say use phases and not 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 pmppm him lo 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 and it's very simple. It's just tools.
45:26We'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 work with an enterprise customer and it's super airgapped and they're like you can't use cloud code, you can't use bot, 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 airgapped enterprise infrastructure, we're using 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.
46:16This is literally our own IBM model that we've trained. Granite 4 tiny. Um I'm going to use it via Olama. And you can see I'm totally offline. Uh even tail scale 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] so sad. Um why there? No, there is no called internet. This is um it's talking to 00. Is my lama working? I guess that's the question. Um I love it. I love it when models don't when things don't work. It's 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 Olama with this. My laptop may freeze uh, [laughter] but but granite is small enough. There we go. Look at this. I'm offline, dude.
47:25I'm offline. I'm on Wi-Fi. And it read the file. Um, the package JSON is the Oh, it's not this file. No, no, it's 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. Uh, 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, yo, that's this happened offline 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 train myself. I could go with it's it's all the the the sky is the limit. And this is also, by the way, why you can use other models in cloud code as well. You can just pass an environment variable in your cloud.json and use it. And so, okay, let's try and restore the Wi-Fi here. We're almost done. Uh, we'll wrap we'll uh 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
48:56to say use the same 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 good the good news is we can keep almost all of this we can keep the context management we can keep the caching we can keep the tools have to change and the guardrails too and so um 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 um so I have this file called browser.ts where it can use a browser. Um 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 um you know workspace navigate read text extract act. These are just tools uh 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 move from coding to browser. Look at this diff. Gorgeous, right? And so let's let's run our harness now and um we'll say you know hey any uh 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 um information there. So it's going to
50:22AI.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. Um, we'll see. We'll let this run for some time. Uh, any questions, by the way, so far? Yes. Yes. 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 uh and so I pass 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 um 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 JSON the um 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 exit 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.
51:51Good question. I didn't find any call for papers. That's a shame. Um 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 do. 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. Um, 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. Um, does any of this matter? Maybe a more interesting business question is should we actually build a harness or should we buy one? Uh, because Claude Anthropic has something called Claude managed agents. I don't know if you've seen this. Um, 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. Um, and they do 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." Um, and so, you know, it's kind of on you.
52:56Should we build or should we buy? Just for completion, I'd like to show you that. Um, and then, you know, you make your own decision. 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 man. 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 uh map out the tools and notice it says client.BA beta because this is not fully production ready. And we create literally our harness and we say I want this harness with this model. Um 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. Um, 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 it's ins and outs. I know it's going to save me money. I know it's not going to rim raff everything.
54:10Incredible. For a managed harness that we build or we buy, let's let's talk through this with some real uh decision points. You should consider building um 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 aents phases. you know your business workflows better than any external harness provider. So you're still going to want to build that. And finally, um how much how many tokens should we consume? I'll give you an example. I am actively building outside of my work at IBM um 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 SL product ID question mark, millions of tracking tokens, right? And that's a very unique problem to a to a computer use agent.
55:22And 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. Um, and in fact, I'll just spoiler all of these. Um, 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 where companies like uh Temporal, right? Companies like Inest, 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?
56:02And that's that's that's what you would buy because you can't sue yourself. You just have to be like, "Sorry, it was my bad." And so this is usually the 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 uh also humoring me. Let's wrap up with some takeaways. Um 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 codeex. I use open code. I use, you know, Pi. I I'm I'm 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. Uh and and I hope I've I've really encouraged you to do that today. Um 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. Uh practically though, takeaway number one is you don't always need a bigger model.
57:05the shorter 20-minute version of this talk that I did in March um used I showed how with the right harness you can get the same quality of work done between GPD 3.5 Turbo for basically free um 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 um we looked at this 5x thing past 100k tokens many of you looked surprised from where I'm standing by the way um you need to know when to autocompact 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.
57:45Um before you take steps or your harness takes steps that cannot be undone. For example, deleting.git. Um 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. uh 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.
58:38And 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 um 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 eval 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? Any guesses?
59:16software factories or or factories in general, softwares and brackets. You could just autom 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 in 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 fac uh 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 Chad GPT and Codeex trying to merge and you're like, "This is awkward." And I agree. But the problem is these are two specialized harnesses.
1:00:14Chad GPT great for general use. Codeex great for code, but they're separate harnesses. And they're kind of antithetical to AGI because they're this more two kinds of ASI. For AGI, we would have to have chat GPT and Codex merge. And then the the super harness can choose, oh, you're doing coding. I'm gonna invoke codeex. But without you thinking about coding, right? We want this is the path to AGI. You just have a harness that can um 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 we AGI will be very much uh in view. But that's just I'm not you know I'm not a future I don't I don't have a crystal ball. That's just my predictions for now. Uh I just wanted to say hey thank you so much for coming out. Um you can find more resources on this QR code. Thanks a lot.
1:01:01Thank you.
More talks
- 2026
Frontend After AI: The New UX
FrontKon 2026 - 2026
Building AI Evaluations You Can Actually Trust
DataTalks.Club Podcast - 2026
Evals in AI: A Deep Dive
AI Engineer World's Fair 2026 (Workshop) - 2026
The Critical Advantage With AI
Agent Conf 2026 - 2026
The New UX
CityJS London 2026 - 2026
Frontend after AI: The New UX
Future Frontend 2026
Elsewhere
There is every talk I have given, all 89 of them, ConTejas Code, the podcast, Fluent React, the O'Reilly book on how React works inside, and the workshops I teach for engineering teams.