← back

coding-agent

A coding agent built from scratch in Python, on Gemini.

built
April 2026
stack
Python, Gemini (google-genai), Textual
size
about 1,600 lines, 6 tools, CLI and terminal UI
code
github.com/ismajl-ramadani/coding-agent

Why

I use coding agents every day, and I wanted to know what actually happens inside one. Not the prompt, the machinery: how tool calls go back and forth, how you stream the model's reasoning separately from its answer, how you stop it from wandering outside the project, and how you let a human approve a plan before anything gets written. The fastest way to find out was to build one without a framework.

The loop

The agent loop: a prompt goes to the model; if it answers with text the loop ends, if it asks for tools they run in a sandbox and the results go back to the model, up to 50 times. prompt or saved plan model Gemini, streaming answer streamed markdown thinking shown separately tools sandboxed to the project text tool calls results repeats until the model answers, max 50 turns

The model either answers in text, which ends the turn, or asks for tools. Tool results go back into the conversation and the model goes again. Getting the conversation history exactly right (the model's tool calls on its side, the results on the user's side) is most of the work; get it wrong and the model loses track of what it did.

Tools

Keeping it on a leash

Plan first, then execute

/plan <task> runs the agent with read-only tools and a prompt that asks for a structured plan: goal, steps, files to change, risks. Writes are blocked in this mode, and the model is told so, so it doesn't crash. The plan is saved to disk; /plans lists them and /run executes one and marks it done. It's the "approve before acting" flow I rely on in other tools, but the plan survives across sessions.

Sessions and the terminal UI

What I took away

The model is the easy part. The hard parts are the boring ones: exact edit semantics, sandboxing, a history format the model can follow, and good feedback when something fails. Those are also what I now look at first when I evaluate any AI tool.