Technology Sep 05, 2026 · 4 min read

From generating files to using tools: a code agent's ReAct loop

So far in this series, the agent generated the whole solution in a single call: you gave it the spec and the tests, and the model returned the entire function. That works when the whole task fits in a prompt. But in a real repository you don't know in advance which files you'll need, and you can't f...

DE
DEV Community
by Ramón Chancay 👨🏻‍💻
From generating files to using tools: a code agent's ReAct loop

So far in this series, the agent generated the whole solution in a single call: you gave it the spec and the tests, and the model returned the entire function. That works when the whole task fits in a prompt. But in a real repository you don't know in advance which files you'll need, and you can't fit thousands of them into the context window. The leap in this post is to give the agent tools so it can get that context itself: read, search, edit, and run commands. That pattern—reason, act with a tool, observe the result, and repeat—is called ReAct, it's the "action" component the first post promised to open, and it's where a toy loop starts to look like Claude Code.

TL;DR

  • The shift is from "generate the whole function" to "read, search, edit, run". The model stops emitting the solution and starts emitting tool calls; the program runs them and hands the result back.
  • The agent builds its own context. Instead of you cramming the repo into the prompt, it reads and searches only what it needs, when it needs it. The context is the result of its observations, not something you preload.
  • It's the ReAct loop: reason, act, observe. The same loop, evaluator, and sandbox from earlier posts, but the action is no longer single—it's a choice among several tools—and that choice is what makes it feel like a real code agent.

Why generating the whole file stops working

In the write-test-fix loop the agent's action was a single one: "write the function". The model received everything it needed in the prompt—the spec and the tests—and returned the complete solution in one block. It worked because the example fit entirely in the prompt: a small function, a few tests, nothing more.

That condition breaks the moment you leave the toy case. A real task—"fix the 500 the users endpoint returns", "add a field to this model"—lives in a repository of thousands of files. You can't put the whole repo in the prompt: it doesn't fit in the context window, and even if it did, you'd pay a fortune to send thousands of irrelevant files on every call. And there's a problem before that one: you don't know in advance which files you need. That's exactly the part you wanted the agent to solve.

The way out isn't to give it more context in the prompt, but to give it the ability to get it itself. Instead of a single action that produces the solution, you give it a set of actions—read a file, search for a pattern, write, run a command—and let the model pick which one to use each turn. The change is exactly this:

WRITE-TEST-FIX (post 2)            ReAct with tools (this post)

single action:                     many actions; the model picks:
"write the whole function"           read · search · write · run

context goes in the prompt         the agent assembles its context:
(spec + tests, all at once)          reads and searches only what it needs

The loop underneath is the same as the first post: state, action, observation, stop condition. The only thing that changes is what the "action" is. Before it was writing code; now it's picking and calling a tool. But that seemingly small change is what separates a function generator from an agent that operates on a repo.

Keep reading

Illustration of the ReAct loop: an agent picks among four tools—read, search, write, run—and builds its own context with each observation

That is the first half. The full walkthrough — with the rest of the implementation, the trade-offs and the things that only show up in production — is on my blog:

Read the full post on ramonchancay.me →

Originally published at www.ramonchancay.me/blog/react-loop-agent-tools.

DE
Source

This article was originally published by DEV Community and written by Ramón Chancay 👨🏻‍💻.

Read original article on DEV Community
Back to Discover

Reading List