TAI BUI
Back to curriculum
LearnPython

Production Runtimes: Queue, Event, Cron

Production agents run on six runtime shapes: request-response, streaming, durable execution, queue-based background, event-driven, and scheduled. Pick the shape before you pick the framework. Observability is load-bearing at every shape.

TIME: ~60 minutesPREREQUISITES: Phase 14 · 13 (LangGraph), Phase 14 · 22 (Voice)

Learning Objectives

  • Name the six production runtime shapes and match each to a framework / product pattern.
  • Explain why durable execution (LangGraph) matters for long-horizon tasks.
  • Describe the event-driven runtime and when Claude Managed Agents fits.
  • Explain the observability-as-load-bearing claim for multi-step agents.

The Problem

A notebook hides the failures that production exposes: a network timeout at step 37, a user who hangs up mid-voice call, a cron job that dies when the machine reboots, a background worker that runs out of memory. Which of those you survive depends on the runtime shape you chose.

Warm-up0/4
1. An agent task takes five minutes, and the user's browser waits on one plain HTTP request for it. What is the most likely result?Warm-up
2. In a voice call (Lesson 22), why does the agent send audio back in small pieces as it is generated?Warm-up
3. A LangGraph run (Lesson 13) fails at step 37 of 40. What would you most want from the framework?Warm-up
4. What does a cron job on a server do?Warm-up

The Concept

A runtime shape is the outer shell around the agent loop: how work arrives, how long it runs, and how results get back out. The agent logic stays the same. The shell decides what a failure costs you. There are six shapes.

Request-response

Synchronous HTTP. The user waits for the task to finish, so this only works for short tasks (<30s).

  • Stacks: Agno (Python + FastAPI), Mastra (TypeScript + Express/Hono/Fastify/Koa).
  • Observability: standard HTTP access logs plus OTel spans.

Streaming

SSE or WebSocket carries progressive output to the client. LiveKit extends the idea to WebRTC for voice and video (Lesson 22).

  • Stacks: any framework with streaming support, paired with a frontend that handles SSE or WS.
  • Observability: per-chunk timing, first-token latency, tail latency.

Durable execution

State is checkpointed after every step, and the run resumes automatically on failure. Reach for it when the step count is unknown and recovery is expensive.

  • LangGraph's core differentiator (Lesson 13).
  • The AutoGen v0.4 actor model takes a different angle and isolates failures to one agent (Lesson 14).

Queue-based / background

A job enters a queue, workers pick it up, and results flow back through webhooks or pub/sub. This is the shape for long-horizon agents, which run dozens to hundreds of steps per task according to Anthropic's computer use announcement.

  • Stacks: Celery (Python), BullMQ (Node), SQS + Lambda (AWS), or custom.
  • Observability: queue depth, per-job latency distribution, DLQ size.

Event-driven

Agents subscribe to triggers: a new email, an opened PR, a cron fire.

  • Claude Managed Agents covers this out of the box (Lesson 17).
  • CrewAI Flows structures event-driven deterministic workflows (Lesson 15).
  • Observability: trigger source, event-to-start latency, agent latency.

Scheduled

Cron-shaped agents that run on a period. Pair them with durable execution so a failing nightly run resumes on the next tick.

  • Stacks: Kubernetes CronJob plus a durable framework, or hosted cron (Render, Vercel).

2026 deployment patterns

  • CrewAI Flows for event-driven production.
  • Agno stateless FastAPI for Python microservices.
  • Mastra server adapters (Express, Hono, Fastify, Koa) for embedding.
  • Pipecat Cloud / LiveKit Cloud for managed voice (Lesson 22).
  • Claude Managed Agents for hosted long-running async.

Observability is load-bearing

If you don't have OpenTelemetry GenAI spans (Lesson 23) feeding a Langfuse, Phoenix, or Opik backend (Lesson 24), you can't debug a multi-step agent that failed at step 40. Treat it as a production requirement. It's what separates "we debug fast" from "we replay from scratch with more logging."

Where production runtimes fail

  • Wrong shape choice. Request-response on a 5-minute task: users hang up, workers pile up, retries compound.
  • No DLQ. Queue workers without a dead-letter queue lose failed jobs without a trace.
  • Opaque background work. A background agent with no trace export fails invisibly until a user reports it.
  • Skipping durable state. Any run over 30 seconds that you can't afford to restart needs durable execution.
Check: The Concept0/28
1. What is a request-response runtime for an agent?Define
2. What does a streaming runtime add over a plain request-response one?Define
3. Which list names the six runtime shapes for production agents?Define
4. What is durable execution's core property?Define
5. What are the moving parts of a queue-based runtime?Define
6. What starts a run in an event-driven agent runtime?Define
7. What defines a scheduled agent?Define
8. What is a dead-letter queue (DLQ) for?Define
9. What are Claude Managed Agents?Define
10. What does the runtime shape control, as opposed to the agent logic?Explain
11. Why does durable execution matter more as a task's step count grows?Explain
12. How does an event-driven runtime differ from a queue-based one?Explain
13. Which workload does Claude Managed Agents cover out of the box?Explain
14. Why do long-horizon agents that run dozens to hundreds of steps per task fit a queue-based shape?Explain
15. What does the lesson mean by "observability is load-bearing"?Explain
16. What does AutoGen v0.4's actor model provide, per the lesson?Explain
17. In a queue-based runtime, how do results reach the caller once a worker finishes the job?Explain
18. Which set of signals does the lesson pair with a queue-based runtime for observability?Explain
19. Which two questions decide the runtime shape before the framework?Explain
20. What does the lesson recommend pairing cron-shaped agents with?Explain
21. What is the "opaque background work" pitfall the lesson describes?Explain
22. A queue-backed agent drops about 10% of jobs and nobody notices. What is the likely missing piece?Analyze
23. A team serves a five-minute research agent as a plain HTTP endpoint. Users hang up mid-wait, workers pile up, and duplicate runs appear. What is the root cause?Analyze
24. A nightly agent runs from cron. When the machine reboots at 40 percent of the run, the next tick starts over from scratch. Which ingredient was missing?Analyze
25. A 20-minute agent runs as request-response and keeps failing, so the team plans to switch frameworks. Will that fix it, given the lesson's argument?Analyze
26. You must ship a voice assistant where callers hear replies as they are generated, and you do not want to run the media infrastructure. Which approach fits?Design
27. You want agents that react to opened PRs and run for long stretches, and you would rather not operate the infrastructure yourself. Which choice fits?Design
28. Your team wants a nightly agent that runs a long job (an hour or more) and must survive a mid-run crash. Which combination fits?Design

Build It

code/main.py is a stdlib demo that wraps one task in five of the six shells:

  • Request-response endpoint (a plain function).
  • Streaming handler (a generator).
  • Queue-based worker with a DLQ.
  • Event trigger registry.
  • Cron-shaped scheduler.

Run it:

bash
python3 code/main.py

You get five traces, one per shape, from the same agent logic in different outer shells. Durable execution, the sixth shape, is intentionally left to Lesson 13, where LangGraph checkpointing covers it.

Check: Build It0/4
1. In the demo, jobs j001 (long job A), j002 (long job B) and j003 (long job C) are enqueued, and the failure policy fails only job B. Which sequence of results does the worker return?Apply
2. After that worker run finishes, what do the final queue and DLQ lengths print?Apply
3. What does request_response("list project files") return in the demo?Apply
4. The demo calls streaming("review this PR") and prints each chunk. What does the loop show?Apply

Use It

Match the shape to the product surface:

  • Request-response for chat-style UX.
  • Streaming for progressive responses.
  • Durable for long-horizon tasks.
  • Queue for batch, async, and long-running work.
  • Event for agent reactivity.
  • Cron for housekeeping: memory consolidation, evals, cost reports.
Check: Use It0/1
1. Your agent reacts to each new email by triaging it, and nobody is waiting on the result. Which shape fits best?Explain

Ship It

outputs/skill-runtime-shape.md picks a runtime shape for a task and wires in its observability requirements.

Author's Note

I pick the runtime shape before I pick the framework, and I decide it from two questions: how long does the task run, and what does a restart cost. Under 30 seconds, request-response is enough. Past that, with a run I can't afford to restart, I want durable execution. I treat tracing as part of the runtime itself. OTel GenAI spans going to Langfuse, Phoenix, or Opik ship alongside the shape, because a failure at step 40 with no trace means replaying from scratch. My bet is that two of the four failures listed under "Where production runtimes fail" (wrong shape choice and skipping durable state) are shape decisions made too casually, and no framework swap fixes a shape mistake.

Exercises

  1. Port your Lesson 01 ReAct loop to all six shapes in your stack. Which shape fits which product surface?
  2. Add a DLQ to the queue-based demo. Simulate 10% job failure and surface the DLQ size.
  3. Write a cron-triggered eval agent that runs nightly against your top 20 traces from the day.
  4. Implement streaming with backpressure: if the client is slow, pause the agent. How does this interact with a turn budget?
  5. Read the Claude Managed Agents docs. When would you move a self-hosted long-horizon agent to managed?

Key Terms

TermWhat people sayWhat it actually means
Request-response"Synchronous"User waits; short tasks only
Streaming"SSE / WS"Progressive output; better UX; latency observable per chunk
Durable execution"Resume from failure"Checkpointed state; restart at last step
Queue-based"Background jobs"Producer / worker pool / DLQ
Event-driven"Trigger-based"Agent reacts to external events
Scheduled"Cron"Agent runs on a period; pair with durable execution so a failed nightly run resumes on the next tick
DLQ"Dead-letter queue"Parking lot for failed jobs
Claude Managed Agents"Hosted harness"Anthropic-hosted long-running async with caching + compaction

Further Reading

Code

Ships With