Examples

Each example is a small runnable package that shows part of the Kassette API. The examples live in examples/. Each one is a separate pnpm workspace package.

Install dependencies once from the repository root:

pnpm install

Most examples call an LLM through the AI SDK. Set one provider key before you run them:

export OPENAI_API_KEY=...
# or export ANTHROPIC_API_KEY=...
# or export GOOGLE_GENERATIVE_AI_API_KEY=...

By default, the examples choose a provider and model automatically. To choose them yourself, set LLM_PROVIDER and LLM_MODEL.

Workflow API examples

These examples use the high-level workflow API: kassette(), ctx.step, ctx.suspend, ctx.parallel, ctx.sleep, fork().

ExampleRunShows
agent-looppnpm --filter example-agent-loop demoA durable think, act, observe loop. LLM turns and tool calls are separate steps, and flaky tools retry without re-running prior LLM work.
loan-underwritingpnpm --filter example-loan-underwriting demoParallel credit and appraisal branches, independent human review suspends, and a final decision fork that reuses upstream journaled work.
coding-agentpnpm --filter example-coding-agent demoSpeculative branching with fork(). Reuse one memoized plan for several implementations, then backtrack from the plan step if needed.
deploy-assistantpnpm --filter example-deploy-assistant demoA webhook-driven deployment assistant. Resume coordinates ride inside outbound messages, so inbound replies route directly to the waiter.

The deploy assistant starts a local webhook server at http://localhost:8000/webhook. Send an email.received payload to start a run.

curl -X POST http://localhost:8000/webhook \
  -H 'content-type: application/json' \
  -d '{"type":"email.received","email":{"from":"ops@example.com","to":"deploy@example.com","subject":"deploy prod","body":"Deploy the latest approved commit","messageId":"m1"}}'

Framework middleware

examples/vercel-ai-sdk/ uses @usekassette/core directly instead of using the workflow wrapper. It records AI SDK calls inside middleware.

CommandShows
pnpm --filter example-vercel-ai-sdk demoNon-streaming generateText replay. The first run calls the provider, the second run returns recorded outputs from the journal.
pnpm --filter example-vercel-ai-sdk demo:streamStreaming streamText replay. The first run records chunks, and the second run pumps the recorded stream without calling the provider.

Cloudflare examples

These next examples run in Cloudflare Workers. They store journals in R2 through RemoteStorage.

ExampleRunShows
cloudflare-workerpnpm --filter example-cloudflare-worker devSynchronous HTTP start and resume routes. A later request can resume the same run in a different isolate because R2 is the handoff.
cloudflare-queuepnpm --filter example-cloudflare-queue devFire-and-forget submission through a queue. Visibility-timeout redelivery is the crash detector, and replay resumes from the R2 journal.

For the queue example, use the local and deployment walkthrough in examples/cloudflare-queue/README.md. It includes Miniflare setup, R2 and Queue bindings, resume events, and the crash-recovery demo.

Choosing one

  • Start with agent-loop for the smallest durable agent loop.
  • Use loan-underwriting to see parallel(), multiple human review steps, and fork() in one workflow.
  • Use coding-agent to see speculative branches and backtracking.
  • Use deploy-assistant when webhooks need to resume suspended work.
  • Use vercel-ai-sdk when you want to add durability inside an AI SDK integration instead of wrapping a whole workflow.
  • Use cloudflare-worker when HTTP requests start and resume work in Cloudflare Workers.
  • Use cloudflare-queue when queue redelivery should handle crash recovery.