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.
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.
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.
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:
python3 code/main.pyYou 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.
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.
Ship It
outputs/skill-runtime-shape.md picks a runtime shape for a task and wires in its observability requirements.
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
- Port your Lesson 01 ReAct loop to all six shapes in your stack. Which shape fits which product surface?
- Add a DLQ to the queue-based demo. Simulate 10% job failure and surface the DLQ size.
- Write a cron-triggered eval agent that runs nightly against your top 20 traces from the day.
- Implement streaming with backpressure: if the client is slow, pause the agent. How does this interact with a turn budget?
- Read the Claude Managed Agents docs. When would you move a self-hosted long-horizon agent to managed?
Key Terms
| Term | What people say | What 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
- LangGraph overview: durable execution details
- Claude Managed Agents overview: hosted long-running async
- Anthropic, Introducing computer use: "dozens-to-hundreds of steps per task"
- AutoGen v0.4 (Microsoft Research): actor-model fault isolation
Code
- main.py (python, 145 lines)