A minimal local coding agent in Go — a faithful port of Sebastian Raschka's mini-coding-agent, with no LLM framework.
English | 简体中文
Two variants of the same agent. This repo is the framework-free port — faithful to the Python original down to the code structure and agent flow. Its sibling mini-coding-agent-eino rebuilds the same agent on eino's ADK (
ChatModelAgent+ native tool-calling).
This repo contains a small standalone coding agent:
- code: a single
mainpackage (mini_agent.go,tools.go,model.go, ...) - CLI:
mini-coding-agent-go
It is a minimal local agent loop with:
- workspace snapshot collection
- stable prompt plus turn state
- structured tools
- approval handling for risky tools
- transcript and memory persistence
- bounded delegation
The model backend is currently based on Ollama.
The detailed tutorial: Components of a Coding Agent — this port follows the Python original component by component.
The Go port keeps the agent's internals — the custom <tool>/<final> text protocol, the
ask() loop, the six components below — and only adjusts the surroundings:
- CLI shape: the root command starts the interactive REPL; a one-shot prompt goes
through a
promptsubcommand (aliasp) instead of a root-level positional argument. - No runtime framework: resty for Ollama's raw
/api/generateendpoint,urfave/clifor the CLI,aferofor file IO. No LLM framework, no Ollama SDK. --max-new-tokensdefaults to 4096 (the Python default of 512 truncates whole-filewrite_filecalls).- Debug log: model request/response traffic is appended to
.mini-coding-agent/agent.logunder the workspace root. - Sessions, working memory, approval gates, the seven tools, and the REPL slash commands match the original.
This coding harness is organized around six practical building blocks:
- Live repo context The agent collects stable workspace facts upfront, such as repo layout, instructions, and git state.
- Prompt shape and cache reuse A stable prompt prefix, which is separate from the changing request, transcript, and memory so repeated model calls can reuse the static parts efficiently.
- Structured tools, validation, and permissions The model works through named tools with checked inputs, workspace path validation, and approval gates instead of free-form arbitrary actions.
- Context reduction and output management Long outputs are clipped, repeated reads are deduplicated, and older transcript entries are compressed to keep prompt size under control.
- Transcripts, memory, and resumption The runtime keeps both a full durable transcript and a smaller working memory so sessions can be resumed while preserving important state via working memory.
- Delegation and bounded subagents Scoped subtasks can be delegated to helper agents that inherit enough context to help (but operate within limits).
You need:
- Go 1.27+
- Ollama installed
- an Ollama model pulled locally
Install Ollama on your machine so the ollama command is available in your shell.
Official installation link: ollama.com/download
Then verify:
ollama --helpStart the server:
ollama serveIn another terminal, pull the default model used by this project:
ollama pull gemma4:cloudThe agent just sends prompts to Ollama's /api/generate endpoint, so it also works with
any other model exposed by your Ollama instance.
Clone the repo or your fork and change into it:
git clone https://github.com/aiongo/mini-coding-agent-go.git
cd mini-coding-agent-goBuild the binary:
go build # produces ./mini-coding-agent-goOr install it directly into your GOBIN:
go install github.com/aiongo/mini-coding-agent-go@latest
Start the interactive REPL:
./mini-coding-agent-goRun a single prompt without entering the REPL:
./mini-coding-agent-go prompt "Inspect this repo and summarize the layout"(prompt has the alias p.)
By default it uses:
- model:
gemma4:cloud - approval:
ask
For a concrete usage example, see EXAMPLE.md.
Risky tools such as shell commands and file writes are gated by approval.
--approval askprompts before risky actions (default and recommended)--approval autoallows risky actions automatically, including arbitrary command execution and file writes by the model; use only with trusted prompts and trusted repositories--approval neverdenies risky actions
Example:
./mini-coding-agent-go --approval auto
The agent saves sessions under the target workspace root in:
.mini-coding-agent/sessions/
Resume the latest session:
./mini-coding-agent-go --resume latestResume a specific session:
./mini-coding-agent-go --resume 20260401-144025-2dd0aa
Inside the REPL, slash commands are handled directly by the agent instead of being sent to the model as a normal task.
/helpshows the list of available interactive commands/memoryprints the distilled session memory, including the current task, tracked files, and notes/sessionprints the path to the current saved session JSON file/resetclears the current session history and distilled memory but keeps you in the REPL/exitexits the interactive session/quitexits the interactive session; alias for/exit
./mini-coding-agent-go --helpCLI flags are passed before the agent starts. Use them to choose the workspace, model connection, resume behavior, approval mode, and generation limits.
Important flags:
--cwdsets the workspace directory the agent should inspect and modify; default:.(current directory)--modelselects the Ollama model name; default:gemma4:cloud--hostpoints the agent at the Ollama server URL (usually not needed); default:http://127.0.0.1:11434--ollama-timeoutcontrols how long the client waits for an Ollama response (usually not needed); default:300seconds--resumeresumes a saved session by id or useslatest; default: start a new session--approvalcontrols how risky tools are handled:ask,auto, ornever; default:ask--max-stepslimits how many model and tool turns are allowed for one user request; default:6--max-new-tokenscaps the model output length for each step; default:4096--temperaturecontrols sampling randomness; default:0.2--top-pcontrols nucleus sampling for generation; default:0.9
See EXAMPLE.md
- The agent expects the model to emit either
<tool>...</tool>or<final>...</final>. - Different Ollama models will follow those instructions with different reliability.
- If the model does not follow the format well, use a stronger instruction-following model.
- The agent is intentionally small and optimized for readability, not robustness.
- Debug traffic (prompts and raw responses) is appended to
.mini-coding-agent/agent.logunder the workspace root.
The code in this repository is licensed under the MIT License.
It is a Go port of rasbt/mini-coding-agent, which is licensed under Apache 2.0; that license is retained in LICENSE-APACHE for the portions derived from the original.
- Original Python implementation and design write-up: Sebastian Raschka — Components of a Coding Agent
- Original repo: rasbt/mini-coding-agent