LLMs & Agents

An LLM Agent From Scratch

A tool-calling agent in plain Python. No frameworks.

100%

golden-task accuracy

−60%

tokens

The agent loop: the LLM calls tools, results flow back into the context, and the context feeds the next LLM call.

Problem

Agent frameworks hide what actually happens between the model and its tools. I wanted to understand every step, so I built a tool-calling agent in plain Python, with no frameworks at all.

Approach

The model calls tools through JSON: a calculator, file operations and bash. When it produces bad JSON, the agent retries. Bash runs sandboxed inside Docker, and the agent can spawn sub-agents to work on subtasks in parallel.

Most of the work went into context engineering. The agent offloads large content to files, keeps a todo plan, and summarizes as it goes. I also laid out the prompt so it stays KV-cache friendly.

To know whether it actually works, I evaluated it on a set of golden tasks scored by an LLM judge.

Result

The agent reached 100% accuracy on the golden tasks, and context engineering cut token usage by 60%.

Tech: Python · JSON tool calling · Docker sandbox · sub-agents · LLM-as-judge evaluation