Getting started
Local dev loop, common commands, and a first scenario run.
Prerequisites
- Python 3.11+ (matches
pyproject.toml'srequires-python). uv(recommended) orpip.
That's it — the AITP SDK installs from PyPI (see below), so no Rust toolchain is needed for normal development.
Prefer Docker? Skip to docker.md —
docker compose -f docker-compose.test.yml up --build --abort-on-container-exitruns the service plus the e2e suite end-to-end with no host toolchain.
The SDK
The AITP SDK is a regular dependency: distribution name aitp-sdk
on PyPI, import name aitp. It ships prebuilt manylinux/macOS
wheels, so uv sync (or pip install -e .) installs it like any other
package — no maturin, no local build.
You only build from source when developing against unreleased SDK
changes in the sibling aitp-rs checkout. In that case add a path
override (requires a local Rust toolchain):
# pyproject.toml
[tool.uv.sources]
aitp-sdk = { path = "../aitp-rs/bindings/aitp-py" }or build the extension into your active venv directly with
maturin develop --release from ../aitp-rs/bindings/aitp-py — build
details (features, wheels) are the SDK's own docs:
aitp-py README
and sdk-python.md § Build.
See the comments in pyproject.toml for the authoritative story — the floor pin there
records every wire-breaking aitp-sdk bump with a rationale bullet (from the pre-0.3
aitp/0.1 incompatibility through the 0.11.0 pinned-key proof encoding fix, plus routine
floor tracking). Read pyproject.toml directly rather than trusting a version number
restated here; it drifts. Since 0.17 the floor is the aitp/0.3 wire
protocol, so a control plane you point this at must run aitp >= 0.17 too.
The SDK's own release history is in the
aitp-rs CHANGELOG.
Install the service
cd aitp-playground
uv sync # or: pip install -e .Verify the SDK is importable:
uv run python -c "import importlib.metadata as md; import aitp; print(md.version('aitp-sdk'))"Optional agent extras (only needed if you want real LangChain/CrewAI/LangGraph running on the host):
pip install -e ".[all-agents]" # crewai + langchain + langgraph + LLM clients
# or per agent:
pip install -e ".[researcher]"
pip install -e ".[writer]"
pip install -e ".[analyzer]"Without the extras the agents fall back to deterministic stubs — handshakes and TCTs still happen, only the LLM output is canned. Great for fast iteration on the runner.
Configure
If you have access to the Doppler project aitp-playground, use its dev
config instead of a .env file. Run doppler setup -p aitp-playground -c dev
once in the repo, then start things under doppler run --, for example
doppler run -- uv run uvicorn aitp_playground.main:app --reload --port 8000.
That puts every variable in the real process environment, so agent
subprocesses see the LLM keys too (see the note below). The hosted
deployment's values live in the prd config; deployment.md
covers how they reach Railway. dev holds a subset of .env.example's keys and
no PLAYGROUND_API_KEY, so set that one yourself (with doppler run, export it or
add a personal override in dev_personal). Doppler covers native runs only: docker
compose reads .env (env_file: .env), so a compose run still needs the file.
Without Doppler, copy .env.example → .env and edit. The only key the service strictly
needs for real LLM output is OPENAI_API_KEY (or ANTHROPIC_API_KEY if
you set LLM_PROVIDER=anthropic). Everything else has a sensible default.
.envand native runs. The service reads.envthrough its pydanticSettingsonly; nothing copies it into the process environment. Agent subprocesses inherit the service's real environment and readOPENAI_API_KEY/LLM_PROVIDER/*_MODELstraight from it. So for a nativeuvicornrun, export the LLM variables in your shell (or useset -a; source .env; set +a) — a key present only in.envis invisible to the agents and they silently use the stub.docker-compose.ymlanddocker-compose.test.ymluseenv_file: .env, which puts them in the container environment, so those just work (docker-compose.dev.ymldoes not load.env; pass the variables through your shell).
| Var | Default | Purpose |
|---|---|---|
PORT | 8000 | uvicorn bind port |
HOST | 0.0.0.0 | uvicorn bind host |
SCENARIOS_DIR | ./scenarios | Where the registry walks |
REGISTRY_CACHE_TTL_MS | 0 | 0 = reload every lookup (hot reload while authoring) |
AGENT_BASE_PORT | 8100 | First port handed to spawned agents |
AGENT_PYTHON | python3 | Interpreter for agent subprocesses |
PLAYGROUND_BASE_URL | http://localhost:8000 | This service's public origin: the CP webhook URL it subscribes and the CLI's default target |
PLAYGROUND_INTERNAL_URL | http://127.0.0.1:8000 | Where this service's own agents reach it (telemetry, LLM quota). Must be loopback: /internal/* only trusts direct loopback peers |
CP_BASE_URL | (empty) | Optional Control Plane base URL (control-plane.md) |
CP_API_KEY | (empty) | Optional CP bearer |
CP_READ_API_KEY | (empty) | Optional CP bearer used only by GET /cp-proxy/* (a read-only CP key). Falls back to CP_API_KEY |
CP_PROXY_TIMEOUT_SECONDS | 10 | Per-request timeout for GET /cp-proxy/* (connect and each read; the event stream has no read timeout) |
CP_TIMEOUT_MS | 5000 | Per-request timeout for CP calls |
CP_WEBHOOK_TEARDOWN_GRACE_SECS | 120 | How long after a run ends (and its events are ingested) its CP webhook subscription is deleted |
REVOCATION_FAIL_MODE | fail_closed | Axis B: what to do about the absence of a fresh verified list. With CP_BASE_URL set, each agent verifies its own signed list against its own AID. fail_closed refuses capability calls while degraded (the spec's own default); soft_fail serves on the last verified deny-set. Never governs authenticity — an unverifiable list is discarded either way. |
REVOCATION_MAX_STALENESS_SECS | 300 | Axis B: how long since the last successful pull before the posture is "degraded" |
REVOCATION_POLL_SECS | 60 | Cadence for the background pull, re-sign and verify of each agent's own revocation list |
REVOCATION_LIST_TTL_SECS | 3600 | Lifetime (expires_at) of each agent's own signed revocation list. Re-signed every poll; if the CP is unreachable the agent serves its last list until this runs out, then answers 503 rather than an empty list |
PUBLIC_HOST / PUBLIC_SCHEME | (empty) / https | Public origin this service advertises for agents it hosts via POST /hosted-agents (federated/cross-domain demos). Empty PUBLIC_HOST means "no public origin", and POST /hosted-agents needs one in its body. |
INSECURE_LOCALHOST_DANGEROUS | false | Local/test only. Scenario agents serve plain http://localhost instead of TLS on loopback, and SDK calls pass insecure_localhost_dangerous. Any non-loopback http:// endpoint is refused either way. The service refuses to start with this on a Railway deployment. |
LLM_PROVIDER | openai | openai or anthropic |
OPENAI_API_KEY / ANTHROPIC_API_KEY | (empty) | Required for real LLM output |
OPENAI_MODEL | gpt-4o-mini | Override |
ANTHROPIC_MODEL | claude-sonnet-4-6 | Override |
RUN_HISTORY_DB | (empty) | When set, persist runs + events to this SQLite file so they survive a restart. Empty = in-memory only. |
PLAYGROUND_API_KEY | (empty) | Key(s) for every authenticated route (see the endpoint table), sent as x-api-key or Authorization: Bearer. Comma-separated to overlap a rotation. Empty fails closed: those routes answer 503. |
AITP_PLAYGROUND_REQUIRE_API_KEY | false | true puts every path except /healthz, the CP webhook and loopback /internal/* behind the key, static listings included. The service refuses to start if this is true and PLAYGROUND_API_KEY is empty. See SECURITY.md |
RATE_LIMIT_PER_MINUTE / RATE_LIMIT_BURST | 10 / 5 | Token bucket on POST /runs and POST /hosted-agents/{id}/invoke, applied per client IP and per API key |
MAX_RUNS_PER_HOUR | 30 | Global cap on run creations plus hosted invokes in any rolling hour; the next one gets 429 before any agent starts |
RUN_RATE_LIMIT_PER_IP | 5 | Run launches (POST /runs) and hosted invokes per trusted client IP (X-AITP-Client-IP with a valid key) in RUN_RATE_LIMIT_WINDOW_SECONDS; the next gets 429 run_rate_limited. Keyless and header-less callers are not per-IP limited |
RUN_RATE_LIMIT_WINDOW_SECONDS | 600 | Sliding window for RUN_RATE_LIMIT_PER_IP |
MAX_CONCURRENT_RUNS | 3 | Runs in progress at once, service-wide; the next launch gets 429 max_concurrent_runs with Retry-After: 10. A slot frees when the run ends (success, failure, cancel or deadline) |
RUN_DEADLINE_SECONDS | 900 | A run still going after this ends failed with code: run_deadline_exceeded, its agents torn down |
LLM_QUOTA_PER_IP_PER_DAY | 30 | Real LLM call units per trusted client IP (X-AITP-Client-IP) per UTC day. Over quota, the agent answers with its deterministic mock. 0 refuses every real call |
LLM_QUOTA_PER_IP_PER_MONTH | 300 | The same, per UTC calendar month |
LLM_QUOTA_GLOBAL_PER_DAY | 1000 | Real LLM call units across every caller per UTC day |
LLM_QUOTA_GLOBAL_PER_MONTH | 10000 | The same, per UTC calendar month |
LLM_QUOTA_STORE | auto | Where the quota counters live: postgres, memory, unavailable (refuse every real call), or auto: postgres when DATABASE_URL is set, else memory locally and unavailable on Railway |
DATABASE_URL | unset | The dedicated playground Postgres for the quota counters (a Railway reference variable in prod, not a Doppler key). The table playground_llm_usage is created on first connect. Never logged |
RUN_TOKEN_BUDGET | 40000 | Output-token budget per run, split across the run's agents and enforced in each agent before every provider call (429 once spent). A hosted agent gets the whole budget for its lifetime. |
LLM_MAX_TOKENS_PER_CALL | 1024 | max_tokens cap on every single provider call |
LOG_LEVEL | INFO | Standard logging level |
Provider selection is process-wide, not per-scenario: LLM_PROVIDER picks
openai or anthropic, and if the matching API key is missing the agent
falls back to its deterministic stub rather than erroring. There is
deliberately no cross-provider failover — silently swapping providers
behind your back would make debugging harder, and the point of the demo is
to show the real path running. Look for llm.started / llm.complete in
the run's event log to confirm a real provider call happened rather than a
stub. A key that is present but fails at call time (expired, wrong scope,
quota, unreachable) does not fall back to the stub: the agent emits
llm.failed (with the provider's error text) and answers HTTP 502, and the
run fails with a message of the form <agent> self-execute <capability> failed: status=502 detail=….
Before a real call the agent also asks the playground's LLM quota
(LLM_QUOTA_* above). Over quota, the capability answers with its stub and
the run is flagged rather than failed; see
observability.md § LLM quota.
Run the service
uv run uvicorn aitp_playground.main:app --reload --port 8000Hit health to confirm:
curl -s http://localhost:8000/healthz
# {"status":"ok"}First scenario run
curl -s -X POST http://localhost:8000/runs \
-H "Authorization: Bearer $PLAYGROUND_API_KEY" \
-H "Content-Type: application/json" \
-d '{"scenario_ref":"intra-org/research-and-write@1.0.0",
"inputs":{"topic":"AI agent identity"}}'
# {"run_id":"<uuid>","status":"pending","scenario_ref":"intra-org/research-and-write@1.0.0"}Watch it run:
# Poll the final state:
curl -s -H "Authorization: Bearer $PLAYGROUND_API_KEY" http://localhost:8000/runs/<uuid> | jq .
# Or stream events live (SSE):
curl -N -H "Authorization: Bearer $PLAYGROUND_API_KEY" http://localhost:8000/runs/<uuid>/eventsCancel a stuck run:
curl -s -X POST -H "Authorization: Bearer $PLAYGROUND_API_KEY" http://localhost:8000/runs/<uuid>/cancelUseful endpoints
Only the static routes are public: /healthz, /capabilities, /packs,
/scenarios*, the /dashboard HTML shell and the OpenAPI docs. Every other
route needs the key, as x-api-key: $PLAYGROUND_API_KEY or
Authorization: Bearer $PLAYGROUND_API_KEY (401 without it, 503 when the
service has no key configured). With AITP_PLAYGROUND_REQUIRE_API_KEY=true
the static routes need it too; only /healthz stays open. POST /webhooks/cp/{run_id}
is verified by the CP's HMAC instead, and POST /internal/telemetry by a
per-process token only the playground's own agents hold. See
SECURITY.md.
| Endpoint | What |
|---|---|
GET /healthz | Liveness |
GET /capabilities | Installed aitp wheel + which optional features it exposes (capabilities.md) |
GET /packs | List loaded scenario packs |
GET /scenarios | List all scenarios with refs, plus sdk_features_required / sdk_available |
GET /scenarios/{pack}/{scenario}@{version} | Full scenario YAML, parsed (+ template list); same SDK fields, per template too |
POST /runs | Start a run (async; returns run_id immediately). Body accepts template to run a variant and an optional free-form run_label (echoed back in the create/list/get responses). |
GET /runs | List recent runs (in-memory by default; RUN_HISTORY_DB makes them durable) |
GET /runs/{id} | Full run record incl. outputs and events, and the LLM quota flag (llm_quota_exceeded, llm_quota.resets_at, llm_calls_on_mock; observability.md) |
GET /runs/{id}/status | Just status + event count |
GET /runs/{id}/events | SSE event stream (replay + live) |
GET /runs/{id}/narrate | Human-readable narration of the event log (text/plain) |
GET /runs/{id}/cp-audit | Audit events the CP recorded for this run (control-plane.md) |
GET /runs/{id}/cp-sessions | Handshake sessions the CP observed for this run |
GET /runs/{id}/cp-deliveries | CP webhook deliveries this run has received (requires a prior cp_subscribe_webhook step) |
POST /webhooks/cp/{run_id} | Receiver Control Plane POSTs to during webhook fan-out (HMAC-verified, including the signed X-Aitp-Timestamp, which must be within 5 minutes; a repeated deliveryId is not recorded twice) |
POST /runs/{id}/cancel | Mark cancelled, then kill agent subprocesses (this order closes the D-16 race: a concurrent dispatch failure that lands after the mark sees status=cancelled already, never a stale running) |
GET /agents | List currently-running agent processes |
GET /metrics | Prometheus metrics (observability.md) |
GET /dashboard | Single-page trust console (HTML). The shell is public; its data calls need the key, so it is a local-dev view |
GET /cp/* | Read-only Control Plane observability projections (control-plane.md) |
GET /cp-proxy/* | Key-gated passthrough to an allowlist of Control Plane reads, for the console (control-plane.md) |
POST /internal/telemetry | Sink for agents — not for external use |
POST /internal/llm-quota | The LLM quota check agents make before a real call; loopback only, agent token (SECURITY.md) |
OpenAPI is at http://localhost:8000/docs while the server runs.
The endpoints above all belong to the intra-org /runs flow. A separate
/hosted-agents surface spawns a long-lived agent and drives a
cross-domain handshake/invoke against a peer hosted by a different
playground instance — see architecture.md
for the full route list.
Scenario authoring CLI
For dev work without spinning up the API:
uv run python -m aitp_playground.cli list
uv run python -m aitp_playground.cli validate
uv run python -m aitp_playground.cli validate scenarios/intra-org/research-and-write
uv run python -m aitp_playground.cli dry-run intra-org/research-and-write@1.0.0 \
--inputs '{"topic":"test"}'dry-run validates the inputs against the scenario schema and prints
the trust mode, agent list, and workflow steps without spawning
anything. Useful for catching typos before you wait for spawns.
The CLI has a few more subcommands:
uv run python -m aitp_playground.cli new intra-org/my-scenario@1.0.0 # scaffold on disk
uv run python -m aitp_playground.cli lint # cross-scenario refs + step graph
uv run python -m aitp_playground.cli trace intra-org/research-and-write@1.0.0 \
--inputs '{"topic":"AI agents"}' # run against a live server + narrate
uv run python -m aitp_playground.cli conformance # RFC fixture catalog + wheel readinesstrace drives a run against a running playground and streams the
narration; conformance is covered in capabilities.md.
Common dev loops
| You're working on… | Run |
|---|---|
| Scenario YAML | Edit + dry-run; if good, hit POST /runs. REGISTRY_CACHE_TTL_MS=0 so no restart needed. |
| Runner engine | uv run pytest tests/unit/ for the fast loop; AITP_E2E=1 uv run pytest tests/integration/test_runner.py -v to drive real subprocesses (stub LLMs, no keys). |
| Agent worker | Restart the uvicorn server so it re-spawns subprocesses with your changes. |
| Real LLM behavior | Set OPENAI_API_KEY and either run a scenario or AITP_LLM_E2E=1 uv run pytest tests/integration/test_llm_e2e.py. |
Development & testing
The test suite is tiered; each tier past the default is gated behind an
env var so pytest stays fast by default.
| Tier | Command | Gate | What it needs |
|---|---|---|---|
| Unit | uv run pytest tests/unit/ | none (default) | Nothing — fast, in-process. |
| Scenario packs | uv run pytest tests/scenarios/ | none (default) | Validates every YAML pack on disk. |
| Runner integration | uv run pytest tests/integration/test_runner.py -v | AITP_E2E=1 | Spawns real agent subprocesses; deterministic stubs, no LLM keys. |
| Protocol e2e | uv run pytest tests/integration/test_protocol_e2e.py -v | AITP_PROTOCOL_E2E=1 | Delegation/revocation/rotation under real trust. Designed to run inside the docker-compose.test.yml stack (real Control Plane + Postgres). |
| LLM e2e | uv run pytest tests/integration/test_llm_e2e.py -v | AITP_LLM_E2E=1 | Real provider calls — needs OPENAI_API_KEY. Also run by the Docker test stack. |
Linting is ruff (configured in pyproject.toml; ruff format exists
but formatting is not CI-enforced):
uv run ruff check src agents tests # what CI runsHow CI maps onto these (.github/workflows/):
ci.yml— on every PR tomain(plus a weekly scheduled run; not on push, because strict branch protection means a PR run already tested the merged tree): a ruff lint job; the unit + scenario suites with two separate coverage gates (src/*≥88%,agents/base/*≥54% — kept separate so a regression in one can't hide behind the other's floor) on a Python 3.11/3.13 matrix, run againstuv sync --locked(which installsaitp-sdkfrom PyPI, so the SDK-dependent tests run rather than skip). That job also clonesaitp-verifier-pyso the vendored JCS canonicalizer's drift guard is a real gate rather than a skip. A separateAITP_E2E=1integration job (no ordering dependency on the test job) runstest_runner.pyand the in-processtest_federated_handshake.py.docker.yml— builds the playground image on PRs; onmainandv*tags it pushes toghcr.io(with theall-agentsLLM extras baked in). It runs the fulldocker-compose.test.ymle2e stack (protocol e2e + LLM e2e when theOPENAI_API_KEYsecret is set) onmain, and also on PRs that touchuv.lock,Dockerfile,Dockerfile.cp-e2eordocker-compose.test.yml, so an SDK-pin or base-image bump is exercised before it merges.bump-aitp.yml/auto-merge.yml— the event-drivenaitp-sdklock bump (dispatched when aitp-rs publishes) and the auto-merge of green routine bumps; both call shared workflows fromaitp-ci.notify-website.yml— pings the docs site to re-sync whendocs/**orREADME.mdchange onmain.
The suite is laid out in four directories:
tests/
├── conftest.py # sets PYTHONPATH and SCENARIOS_DIR
├── unit/ # fast, in-process, no subprocesses (default target)
├── integration/ # test_runner.py, test_protocol_e2e.py, test_llm_e2e.py,
│ # test_federated_handshake.py — gated by AITP_E2E / AITP_PROTOCOL_E2E / AITP_LLM_E2E
├── e2e_federated/ # two-service federated stack, gated by AITP_FEDERATED_E2E (see federated/README.md)
└── scenarios/ # offline registry consistency checks (no spawn, no LLM)| Suite | Trigger | Needs OpenAI key? | Needs spawn? | Wall time |
|---|---|---|---|---|
tests/unit/ | default | no | no | seconds |
tests/scenarios/ | default | no | no | seconds |
tests/integration/test_runner.py | AITP_E2E=1 | no (stubs) | yes | ~30-45s |
tests/integration/test_protocol_e2e.py | AITP_PROTOCOL_E2E=1 | no (stubs) | yes (Docker recommended) | minutes |
tests/integration/test_llm_e2e.py | AITP_LLM_E2E=1 | yes | yes (Docker recommended) | minutes |
test_federated_handshake.py shares the AITP_E2E gate with test_runner.py and
needs no Docker stack (an in-process TestClient over two real loopback ports; it still
spawns agent subprocesses). The
tests/e2e_federated/ suite needs the Docker stack from federated/ up first.
Protocol e2e and LLM e2e are designed to run inside the
docker-compose.test.yml stack, where the gates and service URLs are
pre-wired — see docker.md for the one-command recipe.
Troubleshooting
AITP_BOOTSTRAP_FILE not set— an agent is being launched without the env var. Almost always means you ran an agent script directly instead of letting the supervisor spawn it.- Subprocess exits before
AITP_AGENT_READY— supervisor prints the child's stderr. Most common cause: missing optional dep or broken import in the agent'screw.py/chain.py/graph.py. tct rejected: ...— the SDK'sverify_tctfailed. Look in the event log for the priortrust.establishedto confirm the jti/grants the caller actually holds.- Run hangs in
runningforever — usually an agent didn't bind its port withinstartupTimeoutMs(default 30s). Check the playground logs for the captured stdout/stderr from the child. /runs/{id}returnsoutputs: {}— the run failed before reaching any workflow step. Checkerrorand the event log; the failing step is usually right beforerun.failed.
When in doubt, the event log is authoritative — every state change in
the runner produces a RunEvent.