Temporal is a durable execution platform: it persists the state of your running code so that workflows survive crashes, retries, and worker restarts without losing progress. This workshop uses theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/temporalio/edu-ai-workshop-openai-agents-sdk/llms.txt
Use this file to discover all available pages before exploring further.
temporalio Python SDK. This page walks through every Temporal primitive you will encounter in Exercises 2, 3, and 4, with real code from the solution notebooks.
The Four Core Primitives
Workflow
Orchestration layer. Declares what should happen and in what order. Must be deterministic.
Activity
Unit of work. Where side-effects like API calls and database writes live. Can fail and be retried automatically.
Worker
A long-running process that polls a task queue and executes workflows and activities.
Client
Connects to the Temporal server. Used to start workflow executions and query their state.
Workflows
A workflow is decorated with@workflow.defn. The method that drives execution is decorated with @workflow.run. Workflows must be deterministic—they cannot perform I/O, generate random numbers, or depend on the current wall-clock time directly. All side-effects belong in activities.
workflow.execute_activity()
This is how a workflow delegates work to an activity. The key parameter is start_to_close_timeout, which sets the maximum time allowed for a single activity attempt:
Every
workflow.execute_activity() call must include a start_to_close_timeout. Temporal uses this to detect stuck activities and trigger retries. A common workshop pitfall is setting this too low for GPT-4 calls — 30 seconds is a safe minimum.workflow.sleep() — Durable Timers
workflow.sleep() pauses the workflow for a specified duration. Unlike asyncio.sleep(), this timer is durable: if the worker process crashes while waiting, the timer continues tracking on the Temporal server and the workflow resumes correctly when a worker comes back online.
Activities
An activity is any Python function decorated with@activity.defn. Activities are where your code interacts with the outside world—HTTP requests, database writes, file I/O. They can fail, and Temporal will automatically retry them according to the configured retry policy.
Named Activities
You can give an activity an explicit name that differs from its function name. Exercise 3 uses this pattern:name parameter controls what appears in the Temporal UI execution history.
Workers
A Worker is a process that:- Connects to the Temporal server
- Declares which workflows and activities it can execute
- Polls a named task queue for new work
- Executes tasks and reports results back to the server
Task Queues
The task queue is just a string name. The worker and the workflow starter must use the same string—this is how Temporal routes work to the right worker. Exercises 2 and 3 use separate queue names to avoid collisions:| Exercise | Task Queue Name |
|---|---|
| Exercise 2 | "hello-temporal-task-queue" |
| Exercise 3 | "agents-sdk-queue" |
| Exercise 4 | "routing-workflow-queue" |
UnsandboxedWorkflowRunner
Temporal normally runs workflows inside a sandbox that restricts imports to guarantee determinism. Inside a Jupyter notebook the sandbox causes import errors, so the workshop uses UnsandboxedWorkflowRunner to bypass it:
The Temporal Client
Client.connect() returns a client object used to start workflows, query their state, and send signals. In Exercise 2, the starter code uses it like this:
client.start_workflow() returns a handle immediately. Call await handle.result() to block until the workflow finishes and get the return value.
Architecture: How the Pieces Connect
The Temporal Web UI
The Temporal dev server exposes a Web UI on port 8233. In GitHub Codespaces, open the Ports tab in VS Code, find port8233, and click the Globe icon to open it in your browser.
The UI shows:
- Workflow execution list — every started workflow with its status (Running / Completed / Failed)
- Execution history — a detailed event log for each workflow: when activities were scheduled, started, completed, or retried
- Activity retry events — each failed and retried attempt with the error message and backoff timing
- Input/output payloads — the arguments and return values for every workflow and activity
Running the Worker in Jupyter
Exercises 2 and 3 run the worker as a background async task within the notebook so you can start workflows from subsequent cells:worker.py process instead—a production-style pattern where the worker and starter are independent OS processes communicating only through the Temporal server.
Exercise 2: Temporal Hello World
Write your first workflow and activity, observe retries in the Temporal UI, and start workflows from a client.
Durable AI Agents
See how wrapping LLM calls in Temporal activities gives your agents automatic crash recovery and an audit trail.