Module 0: Setup & orientation#
You are in the CPEX tutorial. This module gets you oriented and checks your setup. It changes nothing on your system.
Goal: understand what CPEX is, confirm your toolchain, and know which modules need the IdP.
What CPEX is#
CPEX is a policy enforcement runtime for AI agents. It is a deterministic reference monitor between an agent and every capability it invokes: tools, prompts, resources, inference providers. Each capability defines its own enforcement pipeline (authorization, delegation, redaction, information-flow control, audit), written declaratively in APL and run at the boundary.
You are the host: the process that embeds CPEX and drives the loop of resolving identity, running policy, calling the backend, and running policy again on the result. The tutorial harness wraps that loop in a single mediate() call so you can focus on policy. Module 9 opens mediate() up and shows the real dispatch API underneath.
Get the code#
The tutorial runs from a clone of the CPEX repository (not from a published crate), so you can edit the policies and examples as you go.
- Install Rust 1.96 or newer with rustup (gives you
rustcandcargo). - Clone the repo and move into it:
git clone https://github.com/contextforge-org/cpex.git cd cpex - Run every
cargo run -p cpex-tutorial ...command from the repository root.
Check your setup#
cargo run -p cpex-tutorial --example m00_setupThe crate builds, and you are told whether the IdP is up:
=== Module 0: Setup & orientation ===
...
Checking the tutorial IdP (Keycloak) ... not running
Modules 0–1 work without it. For module 2 onward, start it:
docker compose -f examples/tutorial/idp/docker-compose.yml up -dThe IdP#
From module 2 on, the tutorial resolves real JWTs from a Keycloak realm. Identity, token exchange, and JWKS validation are core to what CPEX enforces, so mocking them would teach a fake shape of the problem. Starting it is one command:
docker compose -f examples/tutorial/idp/docker-compose.yml up -d # about 30s on first bootThe realm is imported on start and lives only in the container. docker compose ... down wipes it, which is also your reset button. Every credential in it is tutorial-only. Never reuse them. See idp/README.md for the personas.
You do not need it yet. Modules 0 and 1 run on Rust alone.
Checkpoint#
Who runs the enforcement loop, CPEX or your application?
Why a real Keycloak instead of a mock?
Next#
Module 1: Hello, enforcement: the smallest CPEX host, and your first allow and deny.