| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A local-first, autonomous AI coding agent and reference implementation. It plans, edits code, runs commands in a sandbox, evaluates the result with tests, and reflects on failures — all driven by a local model served by Ollama. No code or credentials leave your machine.
New here? Start with the User Guide — install, first run, commands, recipes, the web UI, and troubleshooting.
main has moved beyond the book. Since publication the agent gained a multi-agent architecture, stronger evaluation/reflexion, and many fixes — this branch is the latest working version, and it no longer matches the book's prose file-for-file.
For code that matches the book exactly, use the book-edition tag:
git clone https://github.com/Natarajan-R/local-ai-coding-agent.git cd local-ai-coding-agent git checkout book-edition # the exact code the book walks throughStay on main for the newest, most capable code. The book remains the guided tour of why the architecture is shaped this way.
This repository is the companion code for Building a Local AI Coding Agent — A Hands-On Guide to Building Autonomous, Offline Coding Agents by Natarajan Ramasamy.
Tools like Cursor, Aider, and Claude Code feel like magic. They are not — a coding agent is an architecture you can build yourself. The book explains this entire codebase from first principles, one file at a time: the FSM control loop, the subprocess/Docker sandbox and command guardrails, tree-sitter + LSP perception, a SQLite symbol graph, the token-budget / memory / reflexion reliability layer, and a streaming web dashboard + CLI. Everything runs offline on your own machine — no cloud API, no keys, no per-token cost.
If you want to understand why every line here is the way it is, the book is the guided tour of this repo.
📖 Get it on Amazon Kindle: US · India
cd ai-coding-agent
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements-dev.txt # runtime + tree-sitter + LSP + test/lint
pip install -e . # install the `agent`/`ai-agent` CLIOr simply make setup. Tree-sitter grammars and python-lsp-server are included in requirements*.txt; the agent degrades gracefully if any are absent.
# Installed console script:
ai-agent run "Create a hello.py that prints Hello, World!"
# Options: model / workspace / non-interactive / custom test command:
ai-agent run "Make the tests pass" --model qwen2.5:7b -w workspace --auto \
--test-command "npm test"
# Docker sandbox (build the image once):
ai-agent build-sandbox
ai-agent run "..." --sandbox docker --network # --network allows pip/npm install
# Without installing (from a checkout):
python run.py run "Add a factorial function to math_utils.py"
# Benchmarks:
ai-agent bench
# Web dashboard (needs the [web] extra; requirements-dev already includes it):
ai-agent serve --workspace workspace --port 8765 # then open http://127.0.0.1:8765The dashboard streams the plan, tokens, tool calls, and evaluation live, and (in interactive mode) prompts you to approve or deny each command before it runs. A VS Code extension (see vscode-extension/) is a second client of the same server, with native Approve/Deny and hint dialogs.
Key options: --workspace/-w, --model/-m, --host, --interactive/--auto, --sandbox auto|docker|local, --network/--no-network, --test-command, --max-retries, --max-steps, --model-retries, --num-ctx, --stream/--no-stream, --json-logs, --audit-dir, --log-level. Most also read an AI_AGENT_* environment variable.
With --stream (default) the plan and tool calls print live. Every run ends with a summary of model calls, tokens, time and throughput (also in logs/audit.jsonl).
The default is qwen2.5:7b. In a head-to-head evaluation on this agent's own task loop (6 coding tasks × 2 passes, local sandbox), qwen2.5:7b solved 12/12 while qwen2.5-coder:7b solved 10/12 — the coder model reliably looped on the edit-an-existing-file task. The coder model is faster on greenfield "create a file" work (--model qwen2.5-coder:7b). Any Ollama chat model works.
| Area | What |
|---|---|
| Control | FSM loop; no-progress detection; bounded retries; --max-steps; human escalation gate (hint on exhausted retries) |
| Model | Async Ollama client; streaming; tool schemas; health check |
| Tools | read (line ranges) / write / fuzzy search_replace / list / search_text / outline / find_symbol / find_importers / run_command / finish |
| Perception | Python AST; tree-sitter for Java, JS, TS/TSX, Go, Shell, PowerShell, C#, Rust, Ruby, C, C++; AST edit validation; adaptive repo map + on-demand exploration; symbol graph (SQLite defs/imports) |
| Semantics | Polymorphic LSP: find_definition / find_references / get_diagnostics, routing each file to its server (pylsp / gopls / typescript-language-server / rust-analyzer / clangd) when installed |
| Sandbox | Local + Docker; CPU/mem limits; command timeouts; non-blocking exec; build-sandbox |
| Evaluation | Project-type detection (pytest/npm/go/cargo/maven/gradle) + --test-command; reflexion |
| Guardrails | Path confinement; regex + AST (bashlex) command guard (resolves $VAR, blocks unresolved-variable destructive commands); secret redaction; approval; audit trail |
| Reliability | Circuit breaker; backoff retries; defensive perception; context/token-budget trimming (--num-ctx) |
| Memory | Persistent per-project memory (.ai-agent/memory.jsonl): remember tool + escalation hints, recalled into the next run's context |
| Observability | run_id correlation; plain/JSON logs; token/time telemetry |
| Interfaces | CLI; ai-agent serve WebSocket dashboard (token-authenticated, auto free-port) + VS Code extension; native/browser approval & hint gating |
| Tooling | Typer CLI; env-var config; benchmarks; pytest suite; ruff; GitHub Actions CI |
See expert_review.md for a deep analysis and rationale, and ARCHITECTURE.md for the design.
make test # pytest (unit tests need neither Ollama nor Docker)
make lint # ruffTests that need Ollama, Docker, or pylsp skip automatically when those aren't available. CI (GitHub Actions) runs ruff + pytest on Python 3.11 and 3.12.
Each one is a hands-on build with its code in the open.
| Book | Amazon | Code |
|---|---|---|
| Enterprise AI Workflow Automation | US · IN | auto-sre-graph |
| Agentic AI — A Hands-On Guide | US · IN | agentic-ai-book |
| GraphRAG: Building an Intelligent Research Assistant | US · IN | graphrag-book-code |
All titles → Amazon author page
MIT
| Back | FazBrowse Home | New Git URL |