Building a coding agent from scratch

Reddit r/AI_Agents Tools

Summary

作者从零实现了一个极简编码智能体,详细讲解了其架构:包含异步事件驱动的 ReAct 代理循环、带沙箱的 read/write/edit/bash 工具、支持分支与回溯的 JSONL 会话存储,以及用 TypeScript 编写并通过 stdin/stdout JSON 通信的 TUI。

I wanted to understand how coding agents work, so I built a minimal one from scratch, inspired by pi. I wrote a detailed breakdown of its architecture (link in the comments). The blog starts with a simple ReAct agent loop and then covers the concepts needed to build the plumbing around it, until it becomes a coding agent. In short: Agent loop: the loop publishes events at different checkpoints (turn start, message update, tool execution, etc.), and any consumer (TUI, CLI, RPC) can subscribe to them. It is async, so abort and steering messages are handled while the LLM is responding. Tools: read, write, edit and bash, with a sandbox (bubblewrap for bash). Tools use an operations interface, so they can run on a remote machine too. Sessions: stored as append-only JSONL, where each entry stores its parent id, so a single file holds multiple branches and rewind just moves a pointer. TUI: written in TypeScript, spawns Python as a subprocess, and the two talk over stdin/stdout with JSON lines.
Original Article

Similar Articles

@Huahuazo: I want to understand how to build an Agent from scratch, not just call APIs—I've looked through many resources, and they're either too abstract or just hand you a finished product to tweak parameters, leaving the 'why design this way' part basically blank. LangChain's official Agents From Scratch...

X AI KOLs Timeline

LangChain's official Agents From Scratch tutorial provides a detailed guide on how to build an AI agent from scratch with human-in-the-loop and memory capabilities, covering four parts: basic setup, evaluation system, human-in-the-loop (HITL), and long-term memory.

@XAMTO_AI: Want to write a coding agent yourself? You've read plenty of articles about the principles, but you get stuck at the first line when you actually start. Recently I found the Chinese tutorial *Hands-On Pi*, which starts with a real offline agent log and takes you through all 15 levels from the beginning. Truly build a complete coding agent from scratch—every step has runnable code...

X AI KOLs Timeline

Introduces the Chinese tutorial *Hands-On Pi*, covering the step-by-step implementation of a Pi-style coding agent from scratch through 15 runnable checkpoints, including protocols, tool loops, conversation tree storage, context compression, and evaluation. Each chapter comes with the main text, a corresponding commit, tests, and failure experiments.

@GitHub_Daily: Many tutorials teach AI Agent development by jumping straight into frameworks — you install it and it runs, but you don't really understand what's going on underneath. ai-agents-from-scratch takes the opposite approach, starting from the most basic model call and gradually building up core patterns like tool calling, memory, and ReAct loops. It uses local models throughout…

X AI KOLs Timeline

GitHub_Daily recommends an open-source project called ai-agents-from-scratch. It starts from zero and uses local models to gradually implement core patterns such as tool calling, memory, and ReAct loops, helping developers understand the underlying principles of AI Agents without directly using frameworks.