English
Overview
Xun is a mini LLM agent runtime: a Python library that turns a model plus a set of functions into an autonomous session — a loop that plans, calls tools, reads results and answers. The core is deliberately small (~5k typed lines in src/xun/*.py); everything that is optional — extra tools, web UI, container workflows, third-party protocols — is built on top of the same public API.
What it does
| Capability | What you get |
|---|---|
| Execution loop | Multi-step tool calling with a configurable iteration budget, automatic retries and backoff, and auto-compaction of long conversations. |
| Tools | Plain Python functions become tools: signature + docstring → JSON schema. 8 built-in tool sets (fs, patch, cmd, search, browser, system, framework, diagnostic). |
| Displays | One event-driven interface with console, web and silent implementations; custom displays need two methods. |
| Structured output | Pydantic models as the return type of a run, validated and typed. |
| Sub-agents | Spawn isolated workers (blocking or backgrounded) to keep the parent context clean. |
| Entrypoints | xun (terminal), xuns (web), xunc (Docker sandbox), xunx (multi-user gateway), xune (extension CLI). |
| Extensions | Drop a file into $XUN_HOME/extensions/ and every agent picks up its tools, hooks, commands and settings. |
When to use it
- As an application: run
xunin a repository to edit code, orxuns/xuncto get a browser UI with file browsing, previews and a managed browser. - As a runtime for a service: mount several
WebDisplays in oneWebDisplayServicebehind one token, or multiplex per-user containers withxunx. - As a library: build your own agent — a batch job, a validation step, a pipeline stage — and get typed answers via structured output, with sub-agents for parallel work.
Design characteristics
- Synchronous API. Calls block and return
Result; there is noasyncceremony to learn. I/O is still threaded internally, and the bottleneck of an agent run is the model call anyway. - Type-state lifecycle.
Agentis generic over its lifecycle (Uninit → Init → Final), so misuse such as executing an uninitialized agent is a lint-time error, not a runtime surprise. See Lifecycle & Type State. - Events, not print statements. The agent emits typed display events; the display decides what to render, store or forward. See Display Extension.
- Cooperative, chained cancellation. Cancelling a parent cancels its sub-agents, and the signal outlives the run so stragglers observe it at their next checkpoint.
- Extensions are trusted code. Like a shell rc file: they run at import time, are cached per process, and never block startup when they fail.
How the pieces fit
Where to read next
| Chapter | Answers |
|---|---|
| Installation | Getting the package, building from source, building the Docker image. |
| Session Entrypoints | Every flag of xun, xuns, xunc, xunx, xune, and the built-in slash commands. |
| API Overview | How the API is organized and how to read the rest of this documentation. |
| Extension Development | Writing drop-in extensions once the API is not enough. |
| Changelog | What changed in each release. |