Skip to main content

BlueClaw

Understand, debug, and control AI agent behavior.
Structured tracing, context management, and reproducible runs — all from the terminal.

Quickstart · Features · Models · Configuration · Roadmap · Contributing · License

PyPI Version License Python Version GitHub Issues CI Downloads Awesome Strands Agents


  • Structured traces — every run writes a queryable JSON trace plus a per-turn event stream, all from the terminal
  • Regression testing — define expected behavior in YAML and run it as CI (TAP/JUnit, Wilson CI scoring)
  • Context management — observation masking keeps token cost low across long sessions without losing quality
  • HTTP API — blueclaw serve exposes the agent with bearer auth, SSE streaming, stateful conversations, and file uploads
  • Telegram bridge — talk to the agent from your phone; per-chat workspaces, allowlist-enforced
  • Extensible & model-agnostic — package behavior as SKILL.md directories, isolate the whole process in Docker, run Claude / Ollama / OpenAI / Gemini

Quickstart

pip install blueclaw
blueclaw init
echo "ANTHROPIC_API_KEY=sk-ant-..." > .env
blueclaw

Install the extra for the model provider you want:

pip install "blueclaw[anthropic]"  # Claude (default)
pip install "blueclaw[ollama]"     # local models via Ollama
pip install "blueclaw[openai]"     # OpenAI
pip install "blueclaw[gemini]"     # Google Gemini (via LiteLLM)

Attach a file in one shot — @<path> or a bare absolute/quoted path both work:

blueclaw run "@~/Downloads/screenshot.png what is this?"
blueclaw run "'/Users/me/notes.pdf' summarize this"

Features

Tracing & Observability — docs/tracing.md

Every turn produces a structured JSON trace plus a per-turn events.jsonl (tool calls, model invocations, context masking, lesson injection). Ten CLI commands inspect, compare, and replay runs; blueclaw trace ui opens a conversation-first browser dashboard (with optional --live streaming) on the same data.

$ blueclaw trace graph 20260315-054426

search for Python 3.13 new features
├── web_search (1ms) ✓  query: Python 3.13 new features
├── web_search (1ms) ✓  query: Python 3.13 new features list 2024
└── http_request (366ms) ✓  url: https://docs.python.org/3.13/whatsnew/3.13.html

trace list · show · graph · timeline · diff · explain · replay · stats · ui · purge. All accept --chat <id> to target one Telegram chat, and (where union makes sense) --all-chats.

Regression Testing — docs/testing.md

Define expected behavior in YAML, run it as a CI test suite with TAP or JUnit output; multi-run Wilson CI scoring handles non-determinism. 12 deterministic assertions cover tools called, output content, file existence, cost, step count, duration, and tool order.

blueclaw test spec.yaml
blueclaw test spec.yaml --format junit -o results.xml

Context Management

Tool outputs from older turns are automatically masked to keep token cost low across long sessions without losing model reasoning quality. Hybrid mode can also summarize after a long tool-heavy conversation; mask mode summarizes on context overflow, while context.strategy: summarize uses Strands' overflow summarization directly. When summarization runs, a shared task-continuation prompt carries forward corrections, pending work, next actions, and saved-output references. This working summary stays separate from durable CONTEXT.md memory. See docs/testing.md for the real-turn compaction check.

HTTP API — docs/api.md

blueclaw serve exposes the agent over HTTP with bearer auth (BLUECLAW_API_KEY), body/timeout caps, and a configurable concurrency semaphore. POST /message returns a reply; POST /message/stream emits SSE token deltas; POST /upload attaches files (PDF, text, images with native vision) referenced by file_id. Per-conversation_id history persists via FileSessionManager, and every request writes a trace. A single-page chat UI ships at GET /playground.

blueclaw serve                          # http://127.0.0.1:8420
curl -X POST http://127.0.0.1:8420/message \
  -d '{"message": "what is in the workspace?"}' | jq .

Telegram Bridge — docs/bridges/telegram.md

Talk to blueclaw from your phone. Allowlist-enforced; each chat gets its own workspace under ~/blueclaw/chats/<chat_id>/ with its own CONTEXT.md and history.jsonl. Long-polling by default (no public URL needed); webhook mode opt-in.

pip install -e ".[telegram]"
export TELEGRAM_BOT_TOKEN=123456:abc...
blueclaw telegram                       # starts long-polling
blueclaw telegram --echo --allow 12345  # smoke test, no model calls

Commands: /whoami, /start, /reset (clears history), /forget (wipes both). Inspect per-chat history from the host with blueclaw history --chat <id> or --all-chats.

Kampung (peer messaging)

The interactive blueclaw session can join Kampung and exchange messages with agent sessions on other machines. It is off by default. It needs kampung-mcp setup --server <url> run once on the machine, and a kampung-mcp client that has --version and --agent other (kampung-mcp 0.12.0 or later).

kampung:
  enabled: true
  # defaults, shown for reference:
  # command: "kampung-mcp adapter --agent other"
  # mailbox: blueclaw-agent
  # wake_turn_timeout_minutes: 20

The session is addressed as <machine>/blueclaw-agent; KAMPUNG_NAME=<name> blueclaw names it. Only the interactive REPL joins (not serve, telegram, test, or Docker sandbox mode).

  • An idle prompt wakes within a few seconds of new mail. A half-typed line waits until 60 s without a keystroke, then is restored after the turn.
  • After a typed turn, one follow-up turn runs if new mail arrived.
  • A wake turn that does not read the inbox gets one retry, then a printed report.
  • Wake turns cannot block on approval prompts (unlisted domains are refused) and stop after wake_turn_timeout_minutes.
  • Wake-turn trace goals name the sender and message id, and lessons from past runs are matched against the message text.

Unattended agent-to-agent conversations are bounded by the Kampung server's loop guard. By default a pair of agents gets 9 wakes in a row (one comes back every 10 minutes), and a mailbox gets 30 wakes until someone types. Once a single line is typed in the REPL, blueclaw's mailbox is on the "until someone types" rule. To let long unattended runs continue (still capped), set KAMPUNG_PAIR_WAKE_SIZE=100, KAMPUNG_PAIR_WAKE_REFILL_MINUTES=1 and KAMPUNG_MAILBOX_WAKE_BUDGET=1000 in the Kampung server's environment and restart it. When a limit is hit, mail is held and does not wake the session later; the REPL prints [kampung] reply stored without waking .... Refill from the dashboard or type a message to recover.

Skills — docs/skills.md

Skills are directories containing a SKILL.md (YAML frontmatter + markdown body) that the agent loads on demand, built on the AgentSkills.io standard. Install from a local path, git URL (with optional #subdir), or direct HTTPS to raw SKILL.md. Per-project skills under <project>/.blueclaw/skills/ take precedence over user-global skills under ~/blueclaw/skills/.

blueclaw skill install ./my-skill
blueclaw skill install https://github.com/u/repo.git#sub
blueclaw skill list

Docker Sandbox — docs/sandbox.md

Opt-in container isolation for the entire agent process. With sandbox.mode: docker in blueclaw.yaml, blueclaw transparently re-execs into a short-lived container with the workspace bind-mounted, read-only root FS, no-new-privileges, all capabilities dropped, and configurable CPU / memory / pid caps. TTY and signals pass through; it falls back to in-process when Docker is unavailable. See the docs for image builds, network modes, and secret composition.

blueclaw sandbox build      # build the runtime image
blueclaw sandbox doctor     # diagnose docker + image state

Model Support — docs/models.md

blueclaw                                    # Anthropic (default)
blueclaw --model ollama/llama3.1:8b         # Ollama (local)
blueclaw --model openai/gpt-4.1-mini       # OpenAI
blueclaw --model litellm/gemini/gemini-2.0-flash  # Gemini via LiteLLM

Set API keys in .env (ANTHROPIC_API_KEY, OPENAI_API_KEY, …).

Configuration

blueclaw.yaml in your project root:

model:
  provider: anthropic
  model_id: claude-sonnet-4-6

workspace:
  path: ~/blueclaw/workspace/
  trace_retention_days: 30

tools:
  - web
  - shell
  - pdf
  - mcp:http://localhost:8080/sse        # SSE MCP server (use mcp:<command> for stdio)

allowlist_domains:
  - github.com
  - docs.python.org

Drop a SOUL.md into your workspace to define the agent's persona and communication style — separate from CONTEXT.md (factual memory). blueclaw init writes a default template; edits are picked up on the next turn.

Architecture

BlueClaw Architecture

Module Purpose
cli.py Typer entrypoints, welcome banner, trace tooling
runner.py Unified agent runner — single owner of agent construction, invocation, capture, and MCP cleanup (runner_session, run_turn)
session.py Config, model + agent factory (create_agent), chat loop, background context updater
server.py HTTP API gateway — /message, /message/stream, /upload, /playground, bearer auth, per-conversation locks
bridges/ Messenger bridges — platform-agnostic router + python-telegram-bot adapter; per-chat workspaces
workspace.py Sandbox enforcement; context/history/trace I/O; multi-workspace resolver
observer.py Structured tool tracing + output truncation
context.py Observation masking and hybrid summarization
skills.py Skill discovery — project + global scope resolution
lessons.py Behavioral hints extracted from past traces, injected into the system prompt
models.py Pydantic models, trace schema, cost calculation, error classification
launcher.py Docker sandbox decision — env composition, argv assembly, execvp into docker run
testing.py Test spec loading, eval orchestration, assertions, TAP/JUnit formatters
tools/ Web, shell, MCP wiring (factory pattern)
approval.py Shell command + domain allowlist hooks

Built on Strands Agents SDK.

Roadmap

See docs/roadmap.md for the full roadmap with milestone details.

Contributing

pip install -e ".[dev]"
pip install pre-commit && pre-commit install   # mirrors CI lint locally
pytest
flake8 blueclaw/ tests/
black --check blueclaw/ tests/

Bug reports and pull requests are welcome. See docs/contributing.md for the full guide.

License

MIT

The Building Blueclaw Series

The story behind the releases. Building blueclaw keeps surprising me: masking that cut token costs 21%, behavioral contracts that beat LLM-as-a-judge, a fetch pipeline that cut page tokens 90%. I write about that thinking in The Dispatch. Come along if that's your kind of thing.

Every major feature in this README has a post behind it covering the design decisions, benchmarks, and failure modes that shaped it:

  1. AI Agent Observability Without a Dashboard: why structured tracing lives in the terminal, not a hosted service
  2. I Cut My AI Agent's Token Costs 21% Without Changing the Model: the benchmarks behind the ObservationMaskingManager
  3. How I Debug AI Agents Like Code (Not Guesswork): a walkthrough of the 10 trace CLI commands
  4. I Built CI for My AI Agent (It Catches What You Miss): why behavioral contracts beat LLM-as-a-judge for agent CI
  5. How to Evaluate LLM Agents: 5 Patterns That Catch Failures: the eval patterns behind blueclaw test
  6. AI Agent Cloudflare 403: Two Libraries That Fix It and Cut Tokens 90%: the curl_cffi + trafilatura fetch-extract pipeline behind the http_request tool

New posts land at blog.jztan.com when there's something worth writing up.

Metadata

Release files for blueclaw 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blueclaw 3.1.0
File Size Uploaded Provenance Actions
blueclaw-3.1.0.tar.gz 456.1 kB Without provenance Details for blueclaw-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for blueclaw 3.1.0
File Interpreter ABI Platform Actions
blueclaw-3.1.0-py3-none-any.whl Python 3 none any Details for blueclaw-3.1.0-py3-none-any.whl

Total release size: 793.9 kB

Release files / blueclaw-3.1.0.tar.gz

Download URL blueclaw-3.1.0.tar.gz
Size 456.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e336ccc837d2b9cf72dd286ad4e8ff31590a7c4151d8c1081c94e63e7915459d
BLAKE2b-256 checksum
How to use checksums
1fe008467ade3202a2ead04dcda2a2868def25fcd8817bfc5df40194d88ec1d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / blueclaw-3.1.0-py3-none-any.whl

Download URL blueclaw-3.1.0-py3-none-any.whl
Size 337.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01f97eca409dced9b2c895766d9f628ff0c6cdcb2f9dc86325a3ace141609bec
BLAKE2b-256 checksum
How to use checksums
684787e8c5dcdf31f288e49c0b81ff145288b9f2b1a54c9a289cf9d8e7fe47a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for blueclaw 3.1.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page