Building my first ReAct agent from scratch

Hero Image

Published: August 12th 2025

While everyone it talking about how bad ChatGPT5 is

I am building out my first ReAct Agent

"A simple agent that runs in a loop"

is how I have heard it described.

(ReAct stands for a "reasoning and acting agent")

Well let me tell you, it took some time to get my head around

I think there is something about recursion that is just hard to visualise

I got a basic setup working though, and that defo makes it more concrete

You basically need to keep a track of all user and assistant messages, and tool calls and results from each loop, and then feed that back into the next loop so that the agent knows what to do next

Am building it all from scratch using the anthropic API

No frameworks thank you

I think building from scratch is actually really important, so you actually know it works.

More importantly you have control of each step (see 12 factor agents from Dexter Horthy)

Also, framework agents can add a lot of bloat, where you might be able to get away with somthing much more simple.

I just discovered while building this that the Anthropic API accepts ToolUse and ToolResult messages, similar to User and Assistant Messages. That was a major discovery that made everything much more clear.

So you pass this sequence of events (messages and tool calls/results) from the previous loop into its context window on the new run so it know's what has happened so far and what to do next.