Xun
A mini LLM agent framework with function-based tools and sub-agent spawning.
The core codebase is compact: about 3000 lines in src/xun/*.py (mostly hand written), with comprehensive type hints.
Quick Start
Requires Python 3.12+ (PEP 695)
# 1. Install the package
pip install xun-agent
# 2. Install Playwright browsers (if using the default browser tools)
playwright install
# 3. Configure environment variables (see `Configuration` section below)
vim .env
# 4. Run the agent in interactive mode
xun
# (OR) Run the agent in web mode
xuns .
xuns accepts at most one workspace directory: every session shares it,
or each session gets its own temporary workspace if omitted.
Use xuns --no-initial-agent to browse the documentation without configuring an LLM.
Installation from source
git clone https://github.com/MenxLi/xun.git
cd xun
make build-web
pip install .
Documentation is included in PyPI releases. Start
xuns/xunc/xunxto browse the bilingual site at/docs/. Need a refresh? Let Xun write its own bilingual manual; see Building Documentation.
Session Entrypoints
| Command | Form | Use case |
|---|---|---|
xun |
Terminal session | Work interactively in the current directory. |
xuns |
Web service | Use the managed browser experience. |
xunc |
Container session | Run xuns in an isolated Docker container. |
xunx |
Multiplexed service | Proxy persistent per-user containers through one server. |
API
Basic: Quickly set up an agent with plain functions as tools — no decorators, no classes needed.
from xun import setup_agent
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
agent = setup_agent(tools = [add])
agent.instruct("Add 2 and 3.").execute()
Advanced: The framework is flexible and extensible. Additional features are shown in demo.ipynb, including:
Agentconfiguration- Display extension
- Output validation
- Tool attributes
- Context injection
- Type-state transition
- Sub-agent spawning
- Lifecycle hooks
- ...
Do check out demo.ipynb for detailed examples.
CLI
Run xun in your terminal to start an interactive session.
You can also pass a prompt as an argument to begin with a specific instruction.
xun "Write a hello world python script and save it to hello.py"
Image attachments are supported in the format of [image:path_or_url]. For example:
>>> [image:cat.png image:https://example.com/dog.png] compare them.
Input /help to see the full list of commands.
Web
web_session starts the same managed web experience available through xuns:
from xun import web_session
web_session(workdir=".", base_path="/xun", manage_sessions=True)
Docker
# first clone the repository
git clone https://github.com/MenxLi/xun.git
cd xun
make build-docker # builds the web frontend, then the `xun` image
xunc # sandbox: temporary workspace inside the container
xunc . # bind mount the current directory as /workspace
xunc --copy . # copy the current directory into /workspace instead
xunx uses the same image to run one persistent container per user behind a
single gateway:
xunx user-add alice
xunx serve --host 0.0.0.0 --port 18960
Pause a user's container without discarding its state, then resume it later:
xunx pause alice
xunx resume alice
Frontend development
The frontend development command starts both the backend and Vite with Vue DevTools:cd web
npm install
npm run dev
Open http://127.0.0.1:5173. Build a production bundle with npm run build. See web/README.md for connecting the UI to a separately managed backend.
Configuration
xun reads optional configuration from .xun/config.json (override the location with XUN_HOME); missing fields fall back to built-in defaults. Include only the fields you want to change, for example to override the model:
{
"model": {
"name": "my-model"
}
}
The config supports ${XUN_...} placeholders which are substituted from environment variables (e.g. ${XUN_OPENAI_API_KEY}), so secrets can live in a .env file instead.
| Config field | Environment variable | Description |
|---|---|---|
provider.openai_base_url |
${XUN_OPENAI_BASE_URL} |
OpenAI-compatible API endpoint. |
provider.openai_api_key |
${XUN_OPENAI_API_KEY} |
API key. |
model.name |
${XUN_OPENAI_MODEL} (empty) |
Model identifier. If the resolved value is empty, available models are auto-detected from the API. |
auto_confirm |
${XUN_AUTO_CONFIRM} |
Automatically confirm actions without prompting. |
More configuration options are available; see the source code at src/xun/config.py.
Extensions
Drop a Python file under $XUN_HOME/extensions/ and every agent picks up its effects (tools, hooks, commands, config tweaks) at initialization — no wiring needed. Extensions are trusted code, like a shell rc file.
"""Log every tool call.""" # extensions/<name>.py
from xun import ExtensionContext
def setup_extension(ctx: ExtensionContext) -> None:
ctx.agent.hooks.before_tool_call.add(lambda args: print(args.tool_calls))
See extensions/README.md for the full mechanics.
Metadata
Release files for xun-agent 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xun_agent-1.1.1.tar.gz | 1.4 MB | Without provenance | Details for xun_agent-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xun_agent-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for xun_agent-1.1.1-py3-none-any.whl |
Total release size: 2.9 MB
Release files / xun_agent-1.1.1.tar.gz
| Download URL | xun_agent-1.1.1.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28c4e4625ac66922e4fd55cbc6dadbcca28069e31f7ee6010368fb723e3d1fd8
|
|
BLAKE2b-256 checksum How to use checksums |
88799503299f71e469791b742e07f817601f6a01d5fc179bb6317e5f73dfc432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / xun_agent-1.1.1-py3-none-any.whl
| Download URL | xun_agent-1.1.1-py3-none-any.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62e12ba9d036f6d796aad4ec344f06366fedde2fe7caa76f42c4a43d9478125b
|
|
BLAKE2b-256 checksum How to use checksums |
6197f7b975e8e4063a2f5841a18c23268f2c51afd2612d72a44161388de77163
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for xun-agent 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.