Durable Refund Agent: An LLM Agent That Moves Money Safely by Mohsin SheikhaniDurable Refund Agent: An LLM Agent That Moves Money Safely by Mohsin Sheikhani

Durable Refund Agent: An LLM Agent That Moves Money Safely

Portfolio project
Mohsin Sheikhani
An LLM agent with the authority to issue refunds, built to survive what breaks agents in production: a crash mid-payout, a retry that would pay twice, an approval that arrives the next morning, and a worker restart in the middle of a run.

The problem

Deciding a refund amount is the easy part. A refund paid twice is lost money, one paid without sign-off is a control failure, and a run that dies halfway leaves the customer told the wrong thing.

What I built

A LangGraph flow (classify, look up order, draft amount, route, pay, notify, record outcome) where every node runs as a Temporal activity with its own timeout and retry policy
An idempotency ledger keyed on the workflow id, so a retried payout does nothing. Verified by crashing the worker right after the money moved: N runs left exactly N ledger rows
A human approval gate for refunds over 100 USD that can wait 48 hours, costs nothing while waiting and survives worker restarts. A timeout still notifies the customer and writes the outcome
Refund rules kept in code with a hard cap at the order total, so the model can't decide what it shouldn't. Amounts matched the expected result on 15 of 15 test cases
Replay-safe OpenTelemetry tracing into Langfuse, so a workflow that replays ten times still shows up as one trace

What I learned

LangGraph's interrupt() re-runs its node from the first line instead of resuming where it paused. I confirmed this in both the Temporal event history and the Langfuse trace, which is why nothing with a side effect sits above the interrupt call.
This is a reference build: the payment provider is simulated and the dataset is 15 hand-written refund requests. The durability, idempotency, approval gate and tracing are real and run on a Temporal server.

Stack

Python, Temporal, LangGraph, LiteLLM, OpenAI, Pydantic, OpenTelemetry, Langfuse, pytest

0 likes · 0 views · Dec 1, 2026

A LangGraph refund agent on Temporal that survives crashes, never pays twice on retry, and waits up to 48 hours for human approval across worker restarts.

Tags