Orply.

The Agent Loop Is Reusable; Its Tools and Rules Are Domain-Specific

Tejas KumarAI EngineerThursday, December 3, 202614 min read

Tejas Kumar of IBM argues that a coding agent is not a model with coding ability bolted on, but a loop that gives the model tools, manages its context and sets limits on what it can do. In his workshop, he builds that harness from a minimal chat program, adding file access, permission gates, usage budgets and task phases. The loop can carry across models and applications, he says, but the tools and rules must be designed for the domain.

The model speaks; the harness makes it act

A language model answers a request by generating language. The harness does everything else: supplies context, exposes tools, runs the tools the model asks for, returns their results, and decides when the process must stop. That distinction is Tejas Kumar’s starting point for building a coding agent. The agent is not a model with coding abilities added to it; it is a loop around a model, plus the machinery and rules that let it work on a task.

Kumar, who works in AI research and development at IBM and says the company builds the coding agent Bob and trains its own Granite models, reduces a harness to three components: tools, context management, and guardrails. Earlier, he says, he had described six components, including verification steps. In this workshop, he groups the pieces differently: tools let a model act; context management determines what the model sees and what that costs; and guardrails set limits on the loop and determine when a person must approve an action.

The categories depend on the application. A coding harness might read and edit files, run Bash commands and tests, and require user approval before pushing changes. A computer-use harness might take screenshots, click, and type, with a rule to stop before an action that cannot be undone. A financial application might access a ledger or transfer money, with two keys required for each payment. An errands agent might use a logged-in browser and ask before making consequential choices.

The loop can be reused across these cases, Kumar argues, but the tool registry and rules belong to the domain. A model with access to a file system should not inherit the same permissions as one that can move money or operate a browser. In his formulation, the model answers one request; the harness supplies the broader process that turns a sequence of requests and actions into an application.

A chat loop is not yet a coding agent

Kumar begins with a command-line program that keeps an array of messages, asks the user for input, sends the accumulated conversation to a language model, and prints the text in the response. It is a few lines of TypeScript, but it exposes what an agent harness must solve.

The model has no persistent state of its own in this setup. The message array is the memory. If the program closes and starts again, the model does not know that the user previously gave their name. More immediately, when Kumar asks what the project’s package.json says, the model replies that it cannot see the repository. The program can converse, but it has no access to the files that would make its answers useful for coding.

A tool supplies that missing capability. Kumar defines a read_file tool with a name, a description, and an input schema specifying a path. Separately, the program implements the code that reads the file. The model receives the tool definition and can request its use; it does not directly touch the disk. The harness interprets the request, runs the implementation, and returns the result.

That division is central to the design. A tool definition tells the model what it may ask for. The implementation determines what actually happens. The model’s tool call is not execution by itself. In Kumar’s example, the definition tells the model that read_file accepts a path relative to the project root, while the harness’s runTool function dispatches the request to the actual file-reading code. A larger application can add more tools without giving the model direct control of the underlying system.

Kumar then separates the outer command-line loop from the inner agent loop. The outer loop accepts a user message and calls runAgent. Inside, the agent sends the conversation and available tools to the model. It appends the complete assistant response to the message history, including non-text content such as tool-use blocks, and prints any text for the user.

The inner loop ends when the model stops for a reason other than requesting a tool. If the model requests a tool, the harness runs it and appends a corresponding tool result to the conversation before calling the model again. In the API pattern Kumar demonstrates, each tool_use needs a matching tool_result, and the result must be added to the conversation before the next model call. The exchange continues—assistant tool call, tool result, another call or a final answer—until the model finishes.

The implementation also returns tool errors to the model as results, marked as errors, rather than letting them disappear outside the conversation. That gives the model information it can use to recover or ask for another approach. Kumar’s code gathers results for tool-use blocks into one user message; the essential requirement is that each request has a corresponding result in the message history.

That structure turns the first file-reading tool into something that can answer questions about the project. Asked what package.json contains, the agent reads it. Asked what the project is, it reads README.md and gives an explanation based on the file. But the next request, to add an AGENTS.md, shows the boundary of the toolset: an agent that can only read files cannot create one. It can offer draft text, but cannot perform the requested edit.

The fix is not to add more instructions to the prompt. It is to give the harness another tool. As the toolset grows, Kumar moves from a single conditional to a registry: an array of tools, each with a name, description, arguments, and execution function. The dispatcher finds the requested tool by name and runs its implementation. Adding list_files, write_file, and other operations makes the agent more capable without changing the basic agent loop.

With writing available, the agent can create an AGENTS.md after asking Kumar for permission. Its ability to offer the action in the first place is also informative: once the tool definitions are passed to the model, the model can take those capabilities into account when responding. The same loop has become more useful because the application has changed what it exposes.

Permissions and budgets keep capability from becoming exposure

More tools create more ways for the system to cause damage. During a live test, Kumar jokingly asks the agent to rewrite the project in Python. The model begins reading files and running Bash commands. In another test, a request to delete the project results in a command that would remove almost everything in the working directory. Kumar restores the files from Git, but treats the demonstration as evidence of a real design failure: a model that can act without asking may take a request literally, misunderstand its scope, or continue after the user’s intent has changed.

His guardrails cover two different risks. A usage budget limits how long or expensively the agent can run. A permission gate pauses before selected tool calls.

The workshop’s example budget sets a maximum of 25 model calls per task and 300,000 combined input and output tokens. The harness counts calls and tokens and stops when either limit is reached. These are illustrative settings, not universal thresholds; the point is that the loop needs a defined stopping condition. Without one, repeated requests can consume time and money indefinitely. Kumar’s code creates a fresh budget for an invocation, increments its counters as calls are made, and checks whether the task has reached either limit.

The permission gate is keyed to tool names. In the example, write_file, edit_file, and bash require approval. When the model asks to run a Bash command, the harness shows the command and asks the user to allow it. If the user refuses, the harness returns that refusal as a tool error. The model can then see that the action was denied and ask what to do next, rather than treating the tool call as successful.

Kumar tests the gate against the destructive request. The agent proposes a command to remove files, and the harness displays it before execution. The user can say no. In a separate usage-budget demonstration, Kumar asks the agent to read files sequentially and encounters a model that issues many file reads at once and keeps attempting actions he does not want. The live test is untidy, but it underlines why permissions and stopping rules are enforced by the harness rather than entrusted to the model’s judgment.

The broader rule is to put a gate wherever an action is consequential or hard to undo. For code, that can mean asking before a destructive command or a push. In computer use, it can mean pausing before an irreversible action. In financial workflows, it may mean requiring approval or a second key before a transfer. The user must be able to overrule the agent.

Context management is both a reliability problem and a cost control

The message array that provides memory also creates a scaling problem. On every model request, the basic harness resends the system prompt and accumulated conversation, including tool calls and tool results. As a task progresses, the history grows. Kumar argues that sending the whole history without caching makes repeated work unnecessarily expensive.

He adds several context controls. One limits the size of tool results, which can otherwise overwhelm the conversation: a file-reading tool could return an enormous document, or another tool could inject a large body of text. When a result exceeds the configured limit, the harness truncates it and tells the model to request a smaller part. That makes the harness’s response to oversized output part of the agent’s workflow, rather than silently passing an unmanageable result onward.

Another control is automatic compaction. In the demonstrated configuration, the threshold is 90,000 input tokens. Kumar’s stated reason is that, for the Haiku pricing he is using, prompts above 100,000 tokens cost five times as much. Waiting until the context window is nearly full would mean crossing the price step before compacting. A large context window is not, by itself, a reason to let every task approach its limit.

Kumar also demonstrates prompt caching through Anthropic’s API. In his account, caching lets a later request refer to previously processed conversation history rather than paying to process that history as entirely new input each time. He distinguishes the client configuration shown in the code from the cache implementation: the harness sets the relevant options, while Anthropic handles the cache on its backend. He notes that a system using its own models would need to implement comparable mechanisms itself.

To show the cost difference, he runs the same file-reading task with and without caching, using the same model and prompt. In the uncached run, the final log shows 28,339 prompt tokens, none cached, and an accumulated cost of $0.0212. In the cached run, the agent processes 28,830 prompt tokens, with 26,210 cached, and the accumulated cost is $0.0082.

$0.0082
cached run cost, versus $0.0212 without caching

The cached run handles slightly more prompt tokens but costs substantially less in this demonstration. Kumar describes the saving as roughly two to three times and argues that caching is essential in a coding harness that repeatedly carries forward a growing history. The comparison is specific to the model, API, and task; its design point is that context policy affects not just what the model can remember, but what each additional step costs.

Long tasks benefit from phases, not just a longer loop

A longer context and a larger step budget do not necessarily make an agent reliable on a long task. Kumar reports a result from his own research on a 120-step task: one continuous loop succeeded about 29% of the time, while dividing the work into ten phases raised success to 85%. He says both approaches used the same model and had a 99% success rate per step; in his account, the harness structure changed.

Kumar describes the phased design as a lead agent that plans parts of a job and hands each one to a phase with a specific task. Each phase starts with the information it needs and returns a concise note—up to five lines in the example—about what it did, what it found, and what remains. The lead checks those notes before moving to the next phase. This passes information between agents in a deliberate form instead of carrying one uninterrupted conversation through the entire task.

The arithmetic helps explain the intuition. If a task requires many successive steps, even a high chance of success on each step compounds into a much lower chance of completing the whole chain. Kumar’s slide illustrates the compounding with 0.99 raised to the 120th power, approximately 29%; a shorter sequence of steps has a higher chance of completing successfully. The reported result is more specific than that arithmetic alone: his test compares a single 120-step loop with ten phases of 12 tasks each.

In code, run_phase is another tool in the registry, not a wholly separate agent architecture. The lead can call it with a phase’s instructions, and the phase runs with a prompt describing its limited role and the note it must return. In a small demonstration, Kumar asks for the line count of package.json and a misspelled lockfile name. The phase responsible for the second count discovers that the named file does not exist, finds pnpm-lock.yaml, and reports the result with the correction. The orchestration is modest; the important change is that a long job can be divided into smaller units with explicit outputs between them.

The 29% and 85% figures are Kumar’s reported research results, not a universal guarantee for phased agents. For workflows with many dependent steps, his results suggest that restarting a subtask with focused context may outperform keeping one conversation alive throughout.

The same harness can run on a local model—or serve another domain

Once the harness’s model calls, tools, context controls, and guardrails are separated, changing models does not require rebuilding the whole application. Kumar switches the workshop project to IBM’s Granite 4 Tiny through Ollama and runs it offline. The model initially struggles with what he means by asking for package.json, then reads the file after he clarifies. It also creates a Markdown file from its own weights.

The demonstration is not presented as evidence that the small model matches a larger one. Kumar calls it a tiny model and acknowledges its limitations. The point is that the harness can retain its tool loop and application structure while the model endpoint changes. A local model can operate without a live internet connection, provided the harness is configured to call it and the relevant tools remain available.

He makes a similar argument about changing the application domain. In a browser-based version, the coding tools are replaced by tools such as workspace, navigate, find, read_text, extract, and act. The same general harness—including its context management and caching—can support a task such as searching a website for an open call for papers. The browser and its logged-in state belong to that application’s setup; the reusable part is the surrounding machinery.

This is not a claim that all harnesses are interchangeable. The loop and context infrastructure can travel, but the tools, permissions, and business rules must change with the task. A coding agent needs file and command-line tools; a browser agent needs navigation and interaction tools. A different domain also needs different rules about what may happen without approval.

Build the domain rules; consider buying durable execution

After demonstrating a home-built harness, Kumar frames the practical choice as what to build and what to buy. He includes in the build column the tool registry, permission gates, phases, checkpoints, and budgets. These encode the application’s workflow and risk tolerance. An external provider cannot decide what tools a particular business should expose or which of its actions require approval.

He puts the generic execution infrastructure in the buy column: the loop itself, caching and compaction, sessions that survive a deployment, and streams that can resume. These are problems of durability—keeping a process working across failures, network interruptions, or long-running execution. Kumar points to companies such as Temporal, Inngest, and Restate as businesses focused on this kind of execution infrastructure.

He also shows an Anthropic managed-agent API as a way to hand off more of the harness operation to a provider. The service creates an agent and an environment, takes the model, system prompt, and tools, and runs the loop on the provider’s infrastructure. Kumar characterizes this as essentially the harness he built, but operated elsewhere and under someone else’s control. Whether that tradeoff makes sense depends on the application and the value of controlling the runtime.

His proposed division is not a rule that every team must follow. It separates the part that expresses the business from the infrastructure that keeps a process running. Teams may choose to buy durable execution, caching, and session infrastructure rather than maintain it themselves.

The product is the domain logic, not the model alone

Kumar’s closing advice is that a bigger model is not always the first remedy for a weak agent. He argues that a well-designed harness can improve the outcomes a model produces, and recalls an earlier demonstration comparing work done with GPT-3.5 Turbo and Claude Opus. The workshop’s own model choices make a related point: the capabilities and limits of the model matter, but they do not replace good tools, context management, and permissions.

He also warns against compacting context only when the window is nearly full. If pricing changes sharply beyond a threshold, compact before crossing it. And before allowing an action that cannot be undone, make the harness yield to the user.

For reliability, Kumar says evaluation should come before deployment: teams need to check whether their agents behave as intended before users depend on them. He then sketches a possible next step. If agents and harnesses become reliable enough to run with little supervision, software factories could automate parts of software production; a “super-harness” might select among specialized harnesses or create them as needed. He presents this as a prediction, not a certainty.

The frontier, in your inbox tomorrow at 9:00.

Sign up free. A Brief lands every morning and every evening at 9:00 Eastern. No credit card.

Sign up free