Temporal for durable AI agents and workflows
Agents and business processes that survive crashes, wait for approvals and run for days without losing state.

How we use Temporal
Temporal records every step of a workflow, so code resumes exactly where it stopped after a crash, a deploy or a week-long wait. For AI agents, each model call and tool call becomes a retryable activity, and human approvals become signals the workflow waits for.
What we build with it
- Long-running agents with approval steps
- Document and onboarding pipelines with human review
- Order, payment and fulfilment processes with retries
- Scheduled and event-driven AI jobs
Temporal, running on our machines
Real screenshots and the exact code behind them, from a run on our own machines.

"""Durable refund workflow on Temporal, used for the vithupro.in Temporal page.
Each LLM/tool call is an activity with its own retries; the workflow waits for a human approval signal
for up to 3 days before escalating. Run against `temporal server start-dev`."""
import asyncio
from datetime import timedelta
from temporalio import activity, workflow
from temporalio.client import Client
from temporalio.common import RetryPolicy
from temporalio.worker import Worker
RETRY = RetryPolicy(initial_interval=timedelta(seconds=2), maximum_attempts=5)
@activity.defn
async def classify_request(text: str) -> str:
return "refund_request" # LLM call in production
@activity.defn
async def get_order(order_id: str) -> dict:
return {"id": order_id, "status": "delivered", "damaged": True, "amount": 2499} # MCP tool in production
@activity.defn
async def check_policy(order: dict) -> str:
return "Damaged on arrival: full refund within 7 days [policy.pdf p.3]" # GraphRAG lookup in production
@activity.defn
async def issue_refund(order_id: str) -> str:
return f"refund-{order_id}-ok" # payment API in production
@workflow.defn
class RefundWorkflow:
def __init__(self) -> None:
self.decision: str | None = None
@workflow.signal
def review(self, decision: str) -> None:
self.decision = decision
@workflow.query
def status(self) -> str:
return self.decision or "waiting for approval"
@workflow.run
async def run(self, order_id: str, text: str) -> str:
opts = dict(start_to_close_timeout=timedelta(seconds=30), retry_policy=RETRY)
await workflow.execute_activity(classify_request, text, **opts)
order = await workflow.execute_activity(get_order, order_id, **opts)
await workflow.execute_activity(check_policy, order, **opts)
try: # durable wait: survives worker restarts and deploys
await workflow.wait_condition(lambda: self.decision is not None, timeout=timedelta(days=3))
except asyncio.TimeoutError:
return "escalated to support lead"
if self.decision != "approve":
return "refund rejected by reviewer"
return await workflow.execute_activity(issue_refund, order_id, **opts)
async def main() -> None:
client = await Client.connect("localhost:7233")
activities = [classify_request, get_order, check_policy, issue_refund]
async with Worker(client, task_queue="support", workflows=[RefundWorkflow], activities=activities):
done = await client.start_workflow(RefundWorkflow.run, args=["4821", "Order #4821 arrived damaged."], id="refund-order-4821", task_queue="support")
await asyncio.sleep(2)
await done.signal(RefundWorkflow.review, "approve")
print("4821:", await done.result())
for oid in ("4907", "5133"): # left waiting for a reviewer
await client.start_workflow(RefundWorkflow.run, args=[oid, f"Order #{oid} arrived damaged."], id=f"refund-order-{oid}", task_queue="support")
await asyncio.sleep(4)
h = client.get_workflow_handle("refund-order-4907")
print("4907:", await h.query(RefundWorkflow.status))
if __name__ == "__main__":
asyncio.run(main())4821: refund-4821-ok 4907: waiting for approval
Patterns we rely on
Workflows versus activities
Deterministic orchestration in workflows, all side effects (LLM calls, APIs, databases) in activities with their own retries and timeouts.
Signals, queries and updates
Humans approve, reject or edit a running workflow; your UI reads its live state.
Durable timers
Reminders, escalations and follow-ups that wait hours or weeks without a cron job.
Versioning
Code changes rolled out safely while older workflows are still running.
Our production checklist
What we put in place before a Temporal system goes live.
- Idempotent activities
- Retry and timeout policy per activity
- Heartbeats for long activities
- Worker scaling per task queue
- Workflow versioning strategy
- Self-hosted cluster or Temporal Cloud setup
Questions
Self-hosted or Temporal Cloud?
Temporal Cloud removes the operations work. Self-hosting on Kubernetes makes sense when data must stay in your environment. We set up either.
Does Temporal replace LangGraph?
No. LangGraph handles the reasoning loop of an agent; Temporal makes the overall process durable. They work well together.
Often used together with:
Need Temporal engineers?
Tell us what it needs to do. We reply within one business day with questions, a rough plan and the next step.
- Free 30-minute architecture call
- NDA before you share details
- You own all code and IP
- Reply within one business day