HomeRoadmapsAgent Memory Day 6
Conversational AI, Agent Memory & Multi-Turn Testing Β· Day 6 Β· 20 min

Idempotency & Compensating Rollback
Conversational AI, Agent Memory & Multi-Turn Testing β€” Day 6

Enforce per-transaction and daily financial limits, guarantee idempotent retries on tool timeouts, and trigger compensating rollbacks when downstream services fail mid-conversation.

⚑ Runtime: Python 3.10+ · Zero External Dependencies (unittest)🧠 Conversational AI & Agent Memory QE Lead
State RollbackIdempotencyTransaction LimitsSaga CompensationTool Failures
About this lab

When a conversational agent executes multi-step financial actions such as issuing a provisional dispute credit and syncing a CRM case, network retries or downstream 503 failures can cause double-credits or corrupted partial state. Today you will test idempotency keys, transaction ceilings, and saga-style compensating rollbacks.

πŸ“¦Sample Codebase & Working Solution (Day 6)Available Now
View on GitHub

The official reference codebase for Day 6 is hosted in the repository. Clone the repository and navigate to day-6-state-rollback/test_day6.py to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/777abhi/agent-memory-testing-roadmap.git
cd agent-memory-testing-roadmap/day-6-state-rollback/test_day6.py
🏭Production Context & Regulated Servicing Implementation
πŸ’‘ Why We Are Doing This: LLM tool-calling loops frequently retry on timeouts; without idempotency keys and compensating rollbacks, a transient CRM error leaves ledger balances out of sync with open dispute cases.
🏒 Real-World Production Usecase: Deterministic transactional agent testing per-transaction limits, daily caps, duplicate replay suppression, and clean pre-transaction state restoration on downstream exceptions.
βš™οΈ How Implemented in Production: AccountState, ActionResult, and TransactionalConversationAgent in memlab/rollback.py.
Phase 1

Run Transactional Limits & Rollback Tests

Execute the Day 6 transactional conversation test suite.

Step 1.1: Run Day 6 Rollback Tests
Terminal β€” Run Day 6
npm run test:day6
Step 1.2: Compensating Rollback on Downstream 503
memlab/rollback.py
res = agent.issue_provisional_credit(
    "idem-rollback-1", "DSP-301", 150.0, notify_downstream=broken_crm_sync
)
assert res.status == "ROLLED_BACK" and res.compensated
assert acct.balance == 750.0  # Exact pre-transaction state restored
Day 6 Key Learnings
  • Prevented duplicate provisional credits across repeated agent tool retries via idempotency keys.
  • Enforced per-transaction and daily financial policy ceilings before mutating account state.
  • Verified compensating rollbacks restore exact balance, daily usage, and open case lists when downstream tools fail.

🧠 Knowledge Check

What should a transactional conversational agent do when a ledger credit succeeds but the downstream case-sync tool throws a 503 error?