Implement a single-tool Python agent loop

Overview: what you’re building

You’re going to build agent_single_tool.py: a tiny ReAct-style Python agent that:

  • Talks to an LLM in a loop
  • Lets the LLM choose to call one safe tool (a calculator)
  • Keeps a text history of thoughts, actions, and observations
  • Stops when the model gives a final answer or hits a max number of steps
  • Logs everything so you can see what’s going on

This is the same core loop you see in ReAct examples like Peter Roelants’ simple ReAct agent and Simon Willison’s Python ReAct pattern, just trimmed down to a single safe tool.

We’ll do this in small pieces; you can paste everything into a single file and run it.

1 / 7