Building my AI harness in 2026 A developer building a personal AI coding harness in late 2026, released as the terminal user interface Rhema Code on a modular Rust framework called Rhema, found the work harder than expected after discovering how model APIs and tool calling function. The harness sends the full conversation and tool results to an OpenAI-compatible POST /v1/chat/completions endpoint on every turn, gives the model only a bash tool, and skips compaction by progressively blurring older parts of the conversation, since most large coding models now support context windows of 1M tokens. I am building my own AI harness in late 2026. At first, I thought "This is just giving read, edit and commands to an AI model, right? How hard could it be?". Well, nowadays there are a lot of smart techniques implemented in most harnesses. And it is definitely a lot harder than I thought. Along the way, I discovered how model APIs and tool calling worked, decided to give the model only bash , and chose to skip compaction altogether by progressively blurring the older parts of the conversation instead. At its core, an AI harness is composed of three things: The interaction with the agent continues in a user-feedback loop: the user sends an initial prompt, the agent calls all the tools it needs to understand and fulfill the prompt, then gives a last message to the user, who can send another prompt in response, in a conversational manner. That user loop continues until either the user is satisfied, or the context window of the model is full. A model calling tools in Rhema Code. Every time the conversation grows and the user sends a new prompt or a tool call result , the whole conversation and tool results are re-sent to the model. After reading multiple files and spending multiple turns, this can become a large amount of data. Each model can only support a limited amount of data as input: its context window. It is measured in tokens , which is basically the "letters" or "words" representation of the model technically, tokens depend on the tokenizer that the model uses, but you can think of it as 4-characters groups . Nowadays most big coding models can support 1M tokens as context window. This means that context management is an important job for a harness. As the conversation gets bigger, it costs a lot more money. If it gets too big, it will just abruptly stop. I have made a terminal user interface TUI called Rhema Code, and the underlying harness is a Rust framework divided into multiple "crates", modular, called Rhema. The rhema-host-agent crate implements the harness, wiring rhema-xxx dependencies together, with each dependency providing specific features. Let's take an example to see what talking to a provider really looks like under the hood. OpenAI, but also DeepSeek, OpenRouter, llama.cpp local models and many others implement an "OpenAI-compatible" API. Usually, this means a chat completion endpoint: POST /v1/chat/completions Here is an example of a full JSON payload for an initial message at the start of a new session: { "model": "your-model-here", "messages": { "role": "system", "content": "Full system prompt of the harness goes here : " }, { "role": "user", "content": "First user message of the session." } , "tools": { "type": "function", "function": { "name": "bash", "description": "Run a bash command", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": "The bash command to run." } }, "required": "command" } } } } As you can see, the API is pretty simple. One thing to notice is that tool calls have become so common that we are not just asking the model in the system prompt to "pretty please use tools using X custom format", instead the API natively encodes tool calling and tool results using JSON schema to describe tools themselves. So, once we have a way to do tool calls and speak to models, we need to provide actual tools to the model. A minimal set of tools, like the set provided by the Pi coding agent https://pi.dev , consists of: read , reads the content of a file write , writes content to a file edit , precise targeted text replacements bash , execute bash commands As you can see, this is quite an arbitrary set of tools. This one seems to come from the idea that a coding agent will mostly do two things: operate on text files read, write, edit and run terminal commands. Using a single bash tool alone allows models to read, write and edit files as well using tools like cat , grep , sed , echo , etc. . In fact, in my own harness, I only provide bash . More on that later. As you can see, choosing the set of tools is not an exact science, and it comes down to what models will prefer. Providing too many, too specific tools to a model is pointless because the model will just use bash commands everywhere instead of the fancy tool. Some harnesses provide a grep tool that is a bit more optimized, but it has been seen that most models ended up ignoring it to directly use the grep executable through bash, which led to a line in the system prompt steering the model to not use grep through bash. What if you need more tools? You may want your coding agent to help you build PCBs in KiCad https://jlcpcb.com/blog/kicad-mcp-how-to-design-a-pcb-with-claude-code , design 3D models with Blender https://www.blender.org/lab/mcp-server/ , draw Excalidraw diagrams https://github.com/excalidraw/excalidraw-mcp , etc. You can't possibly bake all tools inside the harness by default. Users want to plug their tools in. The first answer for this could be "easy, my harness gives a full shell access to the model, I'll just ask the model to use the CLI". This is a very correct answer for when you actually have a good CLI. For example, if you want your model to write GitHub PRs for you, follow your GitHub notifications, create repos, and other GitHub-related things: just use the GitHub CLI gh , and potentially a SKILL.md file teaching the model how to use it. However, for the examples that I gave, like KiCad PCB building, Blender model design or Excalidraw drawing, there is no CLI that could help. Fortunately, we have another solution. MCP, for Model Context Protocol , allows extending the toolset of a harness with custom tools. This way, an MCP server in KiCad exposes specific tools and optionally prompts and resources via JSON-RPC. The MCP client in your harness can connect to it and directly add all of the advertised tools to its native toolset. This way, users can natively extend and customize the toolset of a harness without modifying it. However, MCP as-is presents a big problem. It is easy for users to start adding around 10 MCP servers, each providing around 5 native tools, which results in exposing 50+ tools to the model. In reality, the GitHub MCP has around 90 tools on its own. Providing many tools is detrimental for models. Models can struggle to choose the right tool when presented with such variety. That slows down their thinking and bloats the context. Presenting each tool separately also does not allow composition of multiple tools: sometimes the individual output of each tool is not useful for the model, and it would want to write a "script" chaining multiple tools and only looking at the final output. This is the idea behind code mode . It was first introduced by Cloudflare in Code Mode: the better way to use MCP https://blog.cloudflare.com/code-mode/ . Cloudflare thought of code mode as a TypeScript API to expose MCP server calls instead of the raw MCP tools . This has multiple benefits: So instead of exposing each tool individually in the tool list, the harness exposes a generic codemode tool that takes TypeScript code as its argument. The TypeScript API would be dynamically exposed and resolved by the harness itself, backed by its MCP connections. This needs the harness to programmatically build an API definition, but also to ship a sandboxed runtime in order to run codemode and be able to resolve in that sandbox its specific API. TypeScript here was just Cloudflare's example: in theory, any language could work. Different approaches have been taken: Pi uses QuickJS https://pi.dev/docs/latest/codemode , OpenCode built their own interpreter for a JS-like language https://github.com/anomalyco/opencode/blob/dev/packages/codemode/README.md , and the field is evolving. I told you before that I only provided bash in my harness. For basic tools like edit , read , grep but also "web fetch" i.e., curl , bash already has the composability benefits of code mode: curl https://api.api/query | jq '.field.description' | grep 'something' MCP servers go through bash, through one command: mcp . The client is an independent CLI, mcp-cli https://github.com/vhaudiquet/mcp-cli . Rhema runs mcp prompt at session start and puts the output in the system prompt: MCP servers installed: - vectorcraft: draw and edit diagrams The model discovers the rest from the command: bash $ mcp vectorcraft --list {"name":"draw","description":"Draw a diagram from a prompt"}, {"name":"export","description":"Export the current diagram"} $ mcp vectorcraft draw --help --prompt