Violin: A Zig-Powered Coding Agent That Lays Bare the While-Loop at AI's Core
Most coding agents ship as opaque monoliths inside editors. Violin's layered, language-split design and its insistence that every agent type collapses into one loop gives engineers a concrete blueprint for building or debugging their own agent systems, especially in performance-sensitive environments where a garbage-collected runtime is a liability.
Violin is a toy coding agent built from scratch in Zig, deeply modeled on the open-source Pi agent's three-layer architecture: model adaptation, agent runtime, and product layer. The engine runs as a Zig daemon that communicates with a Python TUI client over TCP and JSON-lines, a deliberate split that lets each language handle what it does best—Zig for the performance-sensitive loop and memory management, Python for rapid terminal UI development. The project adapts both OpenAI and Anthropic APIs behind a unified Model.complete() interface, implements a tool registry with six built-in tools, and adds session persistence via JSONL with tree-structured message history that supports branching and rollback.
Context-window management falls to a compaction system that summarizes old messages when tokens exceed a 100K threshold, keeping the most recent 10 messages intact. A Lua plugin system hooks into EventBus callbacks for agent start, tool execution, and session compaction, letting users intercept dangerous commands or inject system instructions without touching the core loop. Resources like AGENTS.md project rules and SKILL.md skill files are parsed from the filesystem and formatted as XML injected into the system prompt.
The project's explicit goal is pedagogical: by building a coding agent from zero, the author demonstrates that customer-service agents, data-analysis agents, and workflow orchestrators are all just variations of the same ask-model-then-execute-tools loop. Several gaps remain—tool definitions aren't serialized into the model request yet, Lua plugins run without permission isolation, and the ACP protocol is unimplemented—but the architecture is complete enough to validate the central claim.
Violin's most useful contribution is demystifying the agent: the architecture diagram and code walkthrough make explicit what commercial agents obscure behind polished UIs.
Choosing Zig over TypeScript for the engine is a bet that memory control and predictable performance matter more than ecosystem convenience for the agent loop itself—a tradeoff most agent builders haven't explored.
The decision to split the engine (Zig) from the client (Python) over a network socket, rather than embedding everything in one process, is architecturally cleaner but introduces latency and serialization overhead that a production agent would need to measure.
Using Lua for plugins is a pragmatic minimum-viable choice—500KB runtime, decades of embedding precedent—but the lack of sandboxing means the plugin system is currently a security hole, not a feature.
The compaction strategy (character-count/4 as a token estimate, 100K threshold, keep-last-10) is deliberately crude; the author explicitly calls out that precision isn't needed for compaction decisions, which is a refreshingly honest engineering tradeoff.
Violin inherits Pi's tree-structured sessions but doesn't yet expose branching in the UI, leaving a powerful capability latent in the data model.
The project validates a specific claim: that understanding one coding agent's internals transfers directly to customer-service, data-analysis, and workflow agents because they all share the same loop structure.