Skip to content

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 ​

CapabilityWhat you get
Execution loopMulti-step tool calling with a configurable iteration budget, automatic retries and backoff, and auto-compaction of long conversations.
ToolsPlain Python functions become tools: signature + docstring → JSON schema. 8 built-in tool sets (fs, patch, cmd, search, browser, system, framework, diagnostic).
DisplaysOne event-driven interface with console, web and silent implementations; custom displays need two methods.
Structured outputPydantic models as the return type of a run, validated and typed.
Sub-agentsSpawn isolated workers (blocking or backgrounded) to keep the parent context clean.
Entrypointsxun (terminal), xuns (web), xunc (Docker sandbox), xunx (multi-user gateway), xune (extension CLI).
ExtensionsDrop 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 xun in a repository to edit code, or xuns/xunc to get a browser UI with file browsing, previews and a managed browser.
  • As a runtime for a service: mount several WebDisplays in one WebDisplayService behind one token, or multiplex per-user containers with xunx.
  • 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 no async ceremony to learn. I/O is still threaded internally, and the bottleneck of an agent run is the model call anyway.
  • Type-state lifecycle. Agent is 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: the module is imported once per process, its setup_extension runs again on every agent initialization, and a failure only warns — startup never blocks.

How the pieces fit ​

ChapterAnswers
InstallationGetting the package, building from source, building the Docker image.
Session EntrypointsEvery flag of xun, xuns, xunc, xunx, xune, and the built-in slash commands.
API OverviewHow the API is organized and how to read the rest of this documentation.
Extension DevelopmentWriting drop-in extensions once the API is not enough.
ChangelogWhat changed in each release.

Xun 1.4.3 (source 5f35bd8, 2026-10-18) documentation, generated from the source tree.