A TypeScript Monorepo Builds a Coding Agent from an Empty Directory, No Frameworks
Hello everyone, I'm Xiaoyue. It's been a while since I wrote a column series tutorial — the last time I wrote a column was, well, last time. I recently left my job, so I have some free time, and I'm taking this opportunity to write a column: Developing a Coding Agent from Scratch. Agent is one of the hottest directions right now. While learning myself, I'm also sharing with everyone, and we can discuss related knowledge together.
This column will take you from an empty directory to gradually developing a truly runnable Coding Agent. We won't just wrap a single large model API request; instead, we will fully implement core capabilities such as model interfaces, Agent Loop, tool invocation, file operations, command execution, session storage, context compression, terminal UI, extension systems, and RPC.
The project uses TypeScript, Node.js, npm workspaces, Vitest, and Biome. It adopts an npm workspaces monorepo (single repository, multiple packages) architecture, splitting the system into four software packages with clear responsibilities:
ai: Defines unified contracts for models, messages, tools, and streaming events, and adapts different large model Providers.agent: Implements the Agent Loop, responsible for model invocation, tool execution, state transitions, error propagation, and cancellation.coding-agent: Combines CLI, file tools, command execution, session management, and different running modes.tui: Provides independent, reusable terminal input, components, and differential rendering capabilities.
The tutorial adopts a progressive development approach: first, use a faux provider to build deterministic tests that don't depend on an API Key, then connect to a real large model Provider; first, complete the smallest command-line loop, then gradually add file tools, session recovery, and an interactive terminal interface. This project will not integrate third-party libraries like LangChain or LangGraph for now. I think before learning third-party frameworks, one should first become familiar with how the Agent itself is developed.
After completing the project, you will not only have a Coding Agent that can read and modify code, execute commands, and maintain continuous conversations, but you will also understand how a user prompt sequentially passes through the CLI, Agent Loop, Provider, tool system, session storage, and terminal interface.
If you are also interested in Agent development, welcome to like, bookmark, and follow. Column: Developing a Coding Agent from Scratch - Dongfang Xiaoyue's Column - Juejin
Top 1 of 2 from juejin.cn, machine-translated. The original thread is authoritative.
1. Why not use pnpm to manage the monorepo?
2. npm workspaces are already sufficient.