Skip to main content
A coding agent is just a tool-calling loop with the right tools. Give the model read_file, write_file, and run_command, then keep calling it: as long as it returns tool calls, you run them and feed the results back. It writes code, runs it, reads the error, fixes it, and goes again until the task is done. Conversation state persists, so follow-up requests build on what it already did.
python app.py

You › Build a fizzbuzz script and run it for n=15.

Tool › write_file(“fizzbuzz.py”)
→ Wrote 545 bytes

Tool › run_command(“python fizzbuzz.py”)
→ /bin/sh: python: command not found

Tool › run_command(“python3 fizzbuzz.py”)
→ 1 · 2 · Fizz · 4 · Buzz · Fizz · 7 · 8 · Fizz · Buzz · 11 · Fizz · 13 · 14 · FizzBuzz

Bot › Done. Wrote fizzbuzz.py, recovered from the missing python, and verified the output for n=15.

You › Now add a test that fizzbuzz(5) ends with “Buzz”, and run it.

Tool › read_file(“fizzbuzz.py”)
→ def fizzbuzz(n): …

Tool › write_file(“test_fizzbuzz.py”)
→ Wrote 184 bytes

Tool › run_command(“python3 -m unittest -v”)
→ Ran 1 test · OK

Bot › Added test_fizzbuzz.py and it passes. fizzbuzz(5) ends with “Buzz”.

Notice the loop adapting: python wasn’t found, so it retried with python3; on the follow-up it read the existing file before writing the test. You don’t script either move, the model reacts to what the tools return.

The agent

Run it:

How it works

  • The model drives the loop. Each turn it either calls tools or returns a final answer. You run the tools, feed the results back, and loop while it keeps calling tools, no fixed step count.
  • It recovers on its own. Tool output (including errors) goes straight back to the model, so it adapts: a failed command, a syntax error, a missing file. You don’t script the recovery.
  • State persists. messages holds the whole history, so a follow-up like “now add a test” builds on the code the agent already wrote.
  • Three tools go a long way. read_file, write_file, and run_command are enough to edit and test a project. Add more (search, git, HTTP) and the agent gets more capable. Swap model for any of the 300+ models without touching the loop.
run_command executes shell commands, so sandbox it before pointing it at anything real: a container, a throwaway directory, or an allowlist of commands. The example keeps everything inside a workspace folder.

What’s next

Tool calling

The tool-use round trip this loop is built on.

Agents SDK

A batteries-included agent framework with tools, streaming, and multi-agent.

Conversations

Message history and multi-turn patterns.

Observe

Score the agent’s runs and catch regressions.