Architecture
The update loop, the view function, the provider, and the subprocess model.
This page explains how agentty's code fits together. There are three core pieces: a pure update loop, one render function, and a fixed set of effects.
The update loop
All state changes go through one pure function: (Model, Msg) → (Model, Cmd). Every message is handled, and you can inspect each transition. IDs have their own types (ToolCallId, ThreadId, OAuthCode, PkceVerifier), so passing two arguments in the wrong order is a compile error.
Msg → reducer (one std::visit over a closed event sum) → (Model, Cmd)
Cmd → runtime executes side effects → new Msg eventsThe view
Rendering is one function, Model → Element. agentty fills in widget Configs from the Model. maya, a sister TUI engine that is mostly headers, draws them: every glyph, layout choice and animation. agentty never builds Elements itself.
The provider
The Anthropic provider talks HTTP/2 + SSE directly, using its own nghttp2 + OpenSSL stack. OAuth (PKCE) and API keys both go through auth::cmd_login. Incoming text is shown at ⅛ of the buffer per tick, so server batching doesn't make it jumpy.
There are four transports in total:
- Anthropic (above).
- OpenAI Chat Completions covers every OpenAI-compatible backend: OpenAI, DeepSeek, Kimi, Google Gemini, xAI Grok, Mistral, Groq, OpenRouter, Together, Cerebras, Fireworks, GitHub Copilot and local Ollama. The differences are just config (base URL, auth header, model id).
- Ollama's native
/api/chatalso rescues tool calls that weaker local models leak as raw JSON, so they can still use every tool. - OpenAI's Responses API is used for ChatGPT/Codex sign-in.
Code the transports share lives in one helper each, so a fix can't drift between copies. That covers stream framing, the end-of-stream event, Retry-After backoff, UTF-8 cleanup, the leaked-tool-call detector, token-usage parsing, OpenAI-family auth headers, the tool-schema encoder, the SSE anti-buffering headers and the reasoning-effort tier.
Reasoning works the same everywhere. Each wire format spells effort its own way (thinking.budget_tokens / reasoning.effort / reasoning_effort), but the value comes from one place. Streamed thinking (Anthropic thinking, DeepSeek/Grok/Gemini reasoning_content) arrives as the same event, so it looks the same on every provider. You pick the provider per session and can switch it live. See Providers & Models.
Background summaries and read-only task roles (explorer, reviewer) run on the cheapest capable model of the active provider, not the model you chat with. Auto-compaction triggers based on the model's real context window, not a fixed token margin. See Providers & Models and the Compaction depth command.
The subprocess model
On POSIX, subprocesses use posix_spawn + poll(2), and agentty enforces deadlines itself (SIGTERM → SIGKILL). On Windows they use CreateProcessW + a reader thread. agentty doesn't need GNU timeout and doesn't use popen, so there are no quoting problems. File writes are atomic: write + fsync/_commit + rename/MoveFileExW.
The permission matrix
The permission policy is a constexpr matrix checked by static_asserts. Each tool declares its effects at compile time. If you change a cell in a way that weakens a guarantee, the build fails.