The Reality Check
We need to talk about the elephant in the room: AI Agents are incredibly fragile.
We see the demos agents booking flights, writing code, and ordering pizza. But in production, the reality is messy. APIs time out, LLMs hallucinate arguments, and Node.js processes crash.
When you chain five unreliable steps together, you don’t get an agent; you get a probability multiplier for failure. If Step 4 fails, what happens to the database records created in Step 1? What about the API charge in Step 2?
Most developers wrap it in a try/catch and hope for the best. That is not engineering; that is gambling.
I spent the last few weeks trying to build a complex "Ops Dashboard" for agents, only to realise I was solving the wrong problem. We don’t need better dashboards…
The Reality Check
We need to talk about the elephant in the room: AI Agents are incredibly fragile.
We see the demos agents booking flights, writing code, and ordering pizza. But in production, the reality is messy. APIs time out, LLMs hallucinate arguments, and Node.js processes crash.
When you chain five unreliable steps together, you don’t get an agent; you get a probability multiplier for failure. If Step 4 fails, what happens to the database records created in Step 1? What about the API charge in Step 2?
Most developers wrap it in a try/catch and hope for the best. That is not engineering; that is gambling.
I spent the last few weeks trying to build a complex "Ops Dashboard" for agents, only to realise I was solving the wrong problem. We don’t need better dashboards; we need better primitives.
So I pivoted. I stripped everything down and built Transactional AI.
What is transactional-ai?
transactional-ai is a lightweight, headless reliability library for TypeScript/Node.js. It brings the Saga Pattern to AI agents.
It does three specific things that standard code doesn’t:
Automatic Rollbacks:If a step fails, it automatically runs "compensation" (undo) logic for previous steps in reverse order. 1.
Process Persistence: It saves state to Redis (or files) after every step. If your server crashes, the agent remembers exactly where it left off. 1.
Resumability: When you restart the process, it skips completed steps and resumes execution seamlessly.
It turns "hope-based" workflows into ACID-like transactions.
Real-World Scenarios: Why You Need This
If you are building simple chatbots, you don’t need this. But if your agents interact with the real world (APIs, Databases, File Systems), transactional-ai is your insurance policy.
1. The "Travel Agent" (Financial Safety)
The Workflow: Your agent books a flight ($500), reserves a hotel ($300), and buys a museum ticket ($20).
The Failure: The flight and hotel succeed, but the museum ticket API is down. The agent crashes.
Without Transactional AI: You are left with a non-refundable flight and hotel booking for a trip the user might not want anymore. You have to manually intervene.
With Transactional AI: The library catches the failure at step 3 and immediately executes the undo logic for steps 2 and 1. It cancels the hotel and refunds the flight automatically. The system returns to a clean, neutral state.
2. The "Legal Analyst" (Cost & Resumability)
The Workflow: An agent iterates through 10,000 PDF contracts to extract metadata. This process takes 4 hours and costs $50 in LLM tokens.
The Failure: At hour 3.5 (document #9,900), your Node.js process crashes due to an unrelated server update.
Without Transactional AI: The in-memory state is lost. You have to restart from document #1, wasting another 4 hours and $50.
With Transactional AI: The agent persists its cursor to Redis after every step. When the process restarts, it detects the existing transaction ID, skips the first 9,900 completed steps, and resumes instantly at #9,901.
The Code: How it Works
Let’s look at the "Litmus Test." Here is how you define a bulletproof transaction.
We define each step with a do (forward) and an undo (backward) action.
import { Transaction, RedisStorage } from 'transactional-ai';
// 1. Setup Storage (Optional, but recommended for crash recovery)
const storage = new RedisStorage(process.env.REDIS_URL);
const agent = new Transaction('onboarding-saga-v1', storage);
// 2. Run the Saga
await agent.run(async (tx) => {
// Step 1: Create a Resource
const fileId = await tx.step('create-file', {
do: async () => {
const file = await drive.createFile('welcome.txt');
return file.id;
},
undo: async (result) => {
// If any future step fails, this runs automatically.
await drive.deleteFile(result);
console.log('Resource cleaned up.');
}
});
// Step 2: Send Email
await tx.step('send-email', {
do: async () => {
// If this throws, the undo above triggers instantly.
await email.send('dev@example.com', fileId);
},
undo: async () => {
await email.recallLast();
}
});
});
Under the Hood: The "Headless" Pivot
Originally, I planned a massive UI control plane. I realised that was bloat. Developers don’t want to host a separate React app just to debug a cron job.
I stripped the UI and built a CLI Inspector instead. It connects directly to your storage (Redis/File) and renders the transaction state in your terminal.
$ npx tai-inspect onboarding-saga-v1
🔍 Inspecting: onboarding-saga-v1
Source: RedisStorage
STEP NAME | STATUS
------------------------------------
├── create-file | ✅ completed
│ └-> Result: "file_xyz"
├── send-email | ❌ failed
└── (undo) create-f..| ✅ completed
Roadmap & Limitations
We are building in the open. Here is the reality of v0.1 vs what is coming.
Where we are (v0.1.1): This release is a single-process MVP. It is designed for individual agents, cron jobs, or single-worker queues. It relies on Redis or the File System for persistence, but it does not yet implement distributed locking.
Where we are going (v0.2.0): We are actively working on the "Enterprise Tier" features:
- Concurrency Control: Distributed locking (Redlock) to safely handle multiple workers processing the same transaction ID.
- SQL Adapters: Native support for Postgres/MySQL for teams that need relational data integrity.
If you are building an Agent today, v0.1.0 is the reliability layer you need. If you are scaling to 10,000 concurrent agents, v0.2.0 is coming for you.
Links
GitHub: https://github.com/Grafikui/Transactional-ai
NPM: npmjs.com/package/transactional-ai