Rafiki is a Cloudflare-first agent harness for running stateful OpenAI Agents workflows with secure Modal execution. Cloudflare Workers + Durable Objects provide the public control plane, while Modal runs the internal execution backend for the current runtime. The harness remains the stable system boundary even if the underlying agent loop changes. This project was inspired by Ramp's blog post, Why we built our background agent.
LangSmith is part of Rafiki because agent runs need trace-level observability beyond raw logs. When enabled, it gives developers correlated OpenAI Agents execution traces across local debugging, deployed operations, and incident triage.
- Python 3.11+
uv- Modal account +
uv run modal setup - Node.js 20+ and Wrangler only if you need the Cloudflare control plane
- Sync the repo and set a local
INTERNAL_AUTH_SECRET. - Create the default Modal secrets.
- Run a local Modal smoke check.
- When you need real client traffic, switch to the Cloudflare-first runbook.
cp .env.example .env
# edit .env and set INTERNAL_AUTH_SECRET to a non-empty value
uv sync --extra dev
source .venv/bin/activate
uv run modal setup
uv run modal secret create openai-secret OPENAI_API_KEY=<your-key>
uv run modal secret create internal-auth-secret INTERNAL_AUTH_SECRET=<same-as-.env>
uv run modal secret create modal-auth-secret \
SANDBOX_MODAL_TOKEN_ID=<token-id> \
SANDBOX_MODAL_TOKEN_SECRET=<token-secret>
# Optional: only if you want LangSmith tracing
uv run modal secret create langsmith-secret \
LANGSMITH_API_KEY=<your-langsmith-key> \
LANGSMITH_PROJECT=<your-project>If you do not want tracing yet, leave ENABLE_LANGSMITH_TRACING=false in .env.
| Surface | Required by default | Name | Notes |
|---|---|---|---|
Local .env |
Yes | INTERNAL_AUTH_SECRET |
Required at settings load time for local Modal runs. Match the Modal and Worker value when using the Cloudflare path. |
| Modal secret | Yes | openai-secret |
Contains OPENAI_API_KEY. |
| Modal secret | Yes | internal-auth-secret |
Contains INTERNAL_AUTH_SECRET for Worker -> Modal auth and function runtime auth. |
| Modal secret | Yes | modal-auth-secret |
Contains SANDBOX_MODAL_TOKEN_ID and SANDBOX_MODAL_TOKEN_SECRET. Required by default because ENABLE_MODAL_AUTH_SECRET=true. |
| Modal secret | Optional | langsmith-secret |
Contains LANGSMITH_API_KEY and optionally LANGSMITH_PROJECT. Create it only when you enable tracing. |
| Worker secret | Yes for canonical public ingress | INTERNAL_AUTH_SECRET |
Must match Modal internal-auth-secret. |
| Worker secret | Yes for canonical public ingress | SESSION_SIGNING_SECRET |
Used to sign session tokens for client auth. |
uv run modal run -m modal_backend.main
uv run modal run -m modal_backend.main::run_agent_remote --question "Explain REST vs gRPC"uv run modal serve -m modal_backend.main
# or
make serveuv run modal deploy -m modal_backend.deployUse this only when you need the supported public client path. Cloudflare Worker
- Durable Objects are the canonical ingress for client traffic.
cd edge-control-plane
npm install
wrangler login
wrangler secret put INTERNAL_AUTH_SECRET
wrangler secret put SESSION_SIGNING_SECRET
wrangler kv:namespace create SESSION_CACHE
npm run deployThe Worker depends on the same shared internal auth secret used by Modal, plus a
session-signing secret for client tokens. Worker-side MODAL_TOKEN_ID and
MODAL_TOKEN_SECRET are not part of the canonical public request path.
For the canonical setup and verification flow, start with docs/references/runbooks/cloudflare-modal-e2e.md and edge-control-plane/README.md.
# Terminate background sandbox
uv run modal run -m modal_backend.main::terminate_service_sandbox
# Snapshot service filesystem
uv run modal run -m modal_backend.main::snapshot_service
# Run tests
uv run python -m pytestdocs/references/configuration.md- full secret and runtime configuration contractdocs/references/runbooks/cloudflare-modal-e2e.md- canonical Cloudflare <-> Modal setup and verification flowdocs/references/troubleshooting.md- startup and auth failure triagedocs/design-docs/cloudflare-hybrid-architecture.md- public control-plane architecture
