A Minimal 9-Line Python Implementation of an LLM Coding Agent
A developer has shared a minimal, 9-line Python script that implements an LLM coding agent capable of executing shell commands. The implementation relies solely on the Python standard library and works with OpenAI-compatible APIs. This project serves as an educational resource, demonstrating how agentic workflows and tool-use capabilities can be built from scratch without heavy frameworks. It lowers the barrier to understanding how AI agents interact with external environments. The script features context window usage tracking, session-based caching, and a single shell execution tool. It uses a custom tools API, though users can modify it to use standard function calling for broader compatibility with local inference endpoints.
## BACKGROUND
Coding agents like Anthropic's Claude Code are terminal-based AI tools that can autonomously write code, run commands, and debug errors. Typically, building these agents involves complex frameworks and libraries to manage state, tool calling, and API communication. This project strips away those abstractions to show the underlying HTTP requests and subprocess execution.