2026 · Human-in-the-loop agent on Temporal
Durable Approval Agent
- Agents
- Human-in-the-loop
- Temporal
A purchase-request agent for a fictional pump and gearbox maker. A LangGraph agent checks the supplier and budget, then starts a Temporal workflow that holds the approval state: manager approval, finance approval above $5,000, and an idempotent purchase-order write. Approvers answer in a chat UI, and a request survives absent approvers, restarts and worker crashes.
- 1Plain-language request
- 2Supplier and budget check
- 3Manager, then finance approval
- 4Exactly-once PO write
Survives worker crashes and absent approvers
- My role
- Solo build
- Team
- Fictional customer, synthetic data
- Result
- 1 PO after two hard worker kills, one mid-approval and one mid-write
- Status
- Public · 26 tests passing
- Tools and methods
- Python, LangGraph, Temporal, agent-chat-ui (Next.js), SQLite, Any OpenAI-compatible LLM, pytest, Docker
The problem
Purchase requests need a manager's sign-off, and finance's above a threshold. They get lost when an approver is away or a system restarts, and a retried write can create a second purchase order for the same request.
How it works
- The LLM only extracts the request and calls tools: supplier lookup, budget lookup, submit, status and review. Everything after a submit is deterministic.
- The Temporal workflow validates the request, waits for the manager, adds finance above $5,000 or for a supplier on probation, writes the PO, then notifies. It sends a reminder at 24 hours and expires the request at 72.
- Approvals appear in the chat UI as interrupts, and each answer becomes a signal to the workflow. Decisions from the wrong person, for a step that isn't pending, or sent twice are dropped and recorded.
- The PO write is idempotent, one row per request, so a retried activity returns the existing PO number instead of a duplicate.
- The chat UI is LangChain's open-source agent-chat-ui. The agent, the workflow and the tests are mine.
How it's tested
- 26 tests on Temporal's time-skipping server: approve, reject, the finance threshold, reminder and expiry, invalid requests, ignored signals, and exactly-once PO creation after a simulated crash.
- A scripted demo kills the worker while it waits for finance, and again right after the ERP commit. Two consecutive runs finished with one PO row and one notice.
- One full conversation on a local CPU-only model took 223 s from message to approval prompt. Each approval click reaches the workflow in about 1.3 s.
What I don't claim
- No single sign-on yet: the chat user acts as the assigned approver.
- SQLite stands in for the ERP, and notifications go to an outbox table, not email.
- I ran one full conversation with the model, not an evaluation over many prompts.