Skip to main content

FairyClaw server-side agent runtime

Project description

FairyClaw

FairyClaw is an async agent runtime for long-running server-side deployments. It separates session scheduling, LLM inference, and capability extension into clear layers so work can run in parallel and resume safely, while keeping a short, observable main execution path.


Quick Start

Install from PyPI

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install fairyclaw

Optional: install from a git checkout

git clone https://github.com/PKULab1806/FairyClaw.git
cd FairyClaw
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

Run

# Matches the profile in config/llm_endpoints.yaml (see FAIRYCLAW_LLM_* / api_key_env)
export OPENAI_API_KEY="your_key_here"

fairyclaw start

fairyclaw start builds the web UI (unless --skip-build), then starts Business + Gateway:

Default
Business http://0.0.0.0:16000 (internal; /healthz, bridge WebSocket)
Gateway + Web UI http://0.0.0.0:8081 — open http://127.0.0.1:8081/app on the same machine
Stale listeners on those ports Stopped automatically unless you pass --no-kill-stale

Config and data

Layout Config directory State root (data, logs, writable capabilities)
PyPI / no ./config in cwd ~/.fairyclaw/config (or $FAIRYCLAW_HOME/config) ~/.fairyclaw/ — paths like ./data and ./capabilities in fairyclaw.env resolve under this tree
Git clone (usual dev) ./config when that folder exists in the current working directory Parent of config/ (often the repo root)

Override config location with FAIRYCLAW_CONFIG_DIR if needed. Defaults for FAIRYCLAW_DATA_DIR, FAIRYCLAW_DATABASE_URL, FAIRYCLAW_CAPABILITIES_DIR, and FAIRYCLAW_LOG_FILE_PATH are derived from that same root (<root>/data, <root>/data/fairyclaw.db, <root>/capabilities, <root>/data/logs/fairyclaw.log).

Set FAIRYCLAW_API_TOKEN before startup if you do not want the default dev token for WebSocket auth.

More deployment options: DEPLOY.md. To embed a fresh frontend in the wheel: python scripts/prepare_web_dist.py then python -m build.


Key features

Event-driven steps Sessions advance on runtime events. The Planner does one inference step → re-wakeup instead of one giant request, so the main path stays short and easy to trace.
Capability groups Capabilities are not a flat tool list. Related tools, Hooks, and extensions ship as a group. Sub-agents cluster similar groups, then route into one bucket and enable that tool set.
Built-in workflows Groups can encode multi-tool pipelines (e.g. SourcedResearch: search → excerpt → citations) so delegated work stays verifiable instead of free-form claims.
Plugins, not core edits Tools, turn Hooks, runtime Hooks, and custom event_types register through manifest + scripts, not hard-coded core.
Two processes Business (runtime + Planner) and Gateway (web /v1/ws, OneBot, etc.) talk over an internal WebSocket bridge so you can scale or swap the Gateway independently.

Updating capability groups

Commands are the same for everyone; where files land depends on how you run FairyClaw.

After pip install (typical user)

With no ./config in your current directory, cold start uses ~/.fairyclaw/config and resolves ./capabilities, ./data, etc. under ~/.fairyclaw/.

# Add missing groups from the installed package seed (skip groups you already changed)
fairyclaw capabilities sync

# Overwrite from the package seed (backups by default; use --dry-run / --group to narrow)
fairyclaw capabilities upgrade

Edit the tree under ~/.fairyclaw/capabilities/ (or the path in FAIRYCLAW_CAPABILITIES_DIR in fairyclaw.env).

Git clone / monorepo (developer)

Point FAIRYCLAW_CAPABILITIES_DIR at the repo seed, e.g. ./fairyclaw/capabilities, in config/fairyclaw.env. Run the same CLI from the repo (or anywhere, if FAIRYCLAW_CONFIG_DIR is set):

fairyclaw capabilities sync
fairyclaw capabilities upgrade --group my_group   # example

Cold start and fairyclaw start still materialize or skip groups per seed rules; see CONTRIBUTING.md for manifest schema and Hook boundaries.


Documentation

Keep AI_SYSTEM_GUIDE.md and this README aligned when you change gateway surfaces, bridge behavior, or control-plane events.

Document Contents
AI_SYSTEM_GUIDE.md Canonical system reference: architecture, events, Hooks, sub-agents, dev conventions
README.md Overview, quick start, capability paths
LAYOUT.md Module map: directories and key files
docs/GATEWAY_ENVELOPE.md Gateway–Business bridge: frames, lifecycle, files
fairyclaw/core/gateway_protocol/GATEWAY_RUNTIME_PROTOCOL.md Control envelopes and web /v1/ws push shapes
DEPLOY.md venv, Docker, systemd, Web UI, OneBot/NapCat
CONTRIBUTING.md Extending capability groups: manifests, Hooks, examples

Extending capabilities

In the repository, seed groups live under fairyclaw/capabilities/. At runtime, the loader reads FAIRYCLAW_CAPABILITIES_DIR (writable tree). Minimal layout:

my_group/
├── manifest.json
└── scripts/
    └── my_tool.py

Details: CONTRIBUTING.md.


Execution loop (diagram)

How a single Planner turn interacts with the bus, LLM, and tools:

sequenceDiagram
  autonumber
  participant Bus as Event Bus
  participant Sched as Scheduler
  participant Plan as Planner
  participant LLM as LLM
  participant Exec as Tool Executor

  Bus->>Sched: Pending event / wakeup
  Sched->>Plan: Single-step turn
  Note over Plan,LLM: Hook: tools_prepared · before_llm_call
  Plan->>LLM: One inference request
  LLM-->>Plan: assistant / tool_calls
  Note over Plan: Hook: after_llm_response
  alt tool_calls present
    Plan->>Exec: Execute sequentially + before/after_tool hooks
    Exec-->>Plan: Results
  else no tools
    Plan->>Plan: Text response · turn closes
  end
  Plan->>Bus: follow-up if needed (new event re-enters the bus)

License

MIT © 2026 FairyClaw contributors, PKU DS Lab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fairyclaw-0.1.29.tar.gz (301.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fairyclaw-0.1.29-py3-none-any.whl (344.9 kB view details)

Uploaded Python 3

File details

Details for the file fairyclaw-0.1.29.tar.gz.

File metadata

  • Download URL: fairyclaw-0.1.29.tar.gz
  • Upload date:
  • Size: 301.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fairyclaw-0.1.29.tar.gz
Algorithm Hash digest
SHA256 fe0ffdbbb5ca1f1703592e803199d6dcc0a7b9c0a4c5a1eb3dab73563cc3766a
MD5 ea4df69aa210641e2c2e7f843c7a5b3b
BLAKE2b-256 3893f5be4bc876949d97ead165b269c2bf3692a47ab3ab601c57e65691ff76fd

See more details on using hashes here.

File details

Details for the file fairyclaw-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: fairyclaw-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 344.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fairyclaw-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 212b8c0478206e2fb8b6f6fe836f57564e480d479e93ef88512a86a1802c7d64
MD5 edacfe09d84560d9641b145c54a38f1f
BLAKE2b-256 53d5dfdf8b9a2cc71f2a10a45c1a9bb2fb0f3536d9924d885fa234d94d255e1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page