Show HN: Agent_acid – ACID rollbacks and dry-run guardrails for AI agents

waqasai1231 pts0 comments

GitHub - muhammadwaqasai/agent_acid: ACID-style rollback and session-memory guardrails for autonomous AI agents · GitHub

/" data-turbo-transient="true" />

Skip to content

Type / to search

Sign in<br>Sign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

muhammadwaqasai

agent_acid

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>2 Commits<br>2 Commits

agent_acid

agent_acid

examples

examples

tests

tests

.gitignore

.gitignore

README.md

README.md

pyproject.toml

pyproject.toml

requirements.txt

requirements.txt

View all files

Repository files navigation

agent_acid

ACID-style transaction guarantees for autonomous AI agents.

AI agents that take real-world actions (charging cards, writing to databases, sending emails, calling APIs) have no standard way to "undo" a partially-completed task, and most guardrail systems only validate one action at a time — with no memory of the session. agent_acid closes both gaps:

Automatic rollback — if any step in a multi-step agent plan fails, every completed step before it is automatically undone, in reverse order.

Guardrails — hard, code-level rules (not prompts) that block bad AI outputs even when nothing "crashes."

Stateful (session-wide) guardrails — catch multi-step manipulation, like an attacker or a manipulated AI splitting one large forbidden action into several small, individually-legal ones ("salami slicing").

This isn't a theoretical framework — every claim below is backed by a runnable test or live demo in this repo.

Why this exists

Salami-slicing–style attacks against AI agents are an actively studied problem: guardrails that only judge one tool call at a time are "memoryless," letting an attacker spread a forbidden action across many small steps where no single step trips the alarm. agent_acid's stateful guardrails are built specifically to close this gap.

Quick start

pip install -r requirements.txt # or just: pip install openai pytest

Run the automated test suite (no API key needed, proves the core engine works):

pytest tests/test_core.py -v

Run the basic rollback demo (no API key needed):

python examples/basic_rollback.py

Run the guardrail demo (no API key needed):

python examples/guardrail_demo.py

Run the real AI-agent demos (requires an OpenAI API key):

export OPENAI_API_KEY="sk-..." # Mac/Linux<br>$env:OPENAI_API_KEY = "sk-..." # Windows PowerShell

python examples/llm_agent_demo.py<br>python examples/attack_test_prompt_injection.py<br>python examples/attack_test_salami_slicing.py<br>python examples/comparison_naive_agent.py

The core idea

blocked & fully refunded<br>])">from agent_acid.core import ReversibleTool, TransactionContext, AgentTransactionEngine<br>from agent_acid.guardrails import max_value, cumulative_max

charge_tool = ReversibleTool(<br>name="charge_card",<br>description="Charges a customer's card",<br>execute=lambda kwargs: real_payment_api.charge(kwargs),<br>compensate=lambda kwargs, result: real_payment_api.refund(result["charge_id"]),<br>guardrails=[max_value("amount", limit=500)],<br>stateful_guardrails=[cumulative_max("charge_card", "amount", session_limit=1000)],

engine = AgentTransactionEngine()<br>ctx = TransactionContext()<br>engine.execute_plan(ctx, [<br>(charge_tool, {"user_id": "u1", "amount": 400}),<br>(charge_tool, {"user_id": "u1", "amount": 400}),<br>(charge_tool, {"user_id": "u1", "amount": 400}), # total now 1200 -> blocked & fully refunded<br>])

Proven results

Attack 1: Prompt injection (hidden instruction overriding a spending limit)

A "customer ticket" contains a fake administrator note trying to convince the AI to charge $75,000 instead of following the $500 limit. The AI gets fooled and attempts the charge — agent_acid's guardrail blocks it and fully reverses the account creation and the charge.

Attack 2: Salami slicing (splitting one large charge into several small ones)

The AI is instructed to charge $1,200 as three separate $400 charges specifically to stay under a $500 per-step limit. Each individual charge passes the per-step check. agent_acid's cumulative guardrail tracks the running total across the whole session and blocks the third charge once the total crosses $1,000 — then rolls back all three charges and the account.

Head-to-head comparison

The same salami-slicing attack was run against a naive agent using only a per-step check (representative of how most simple guardrail integrations work):

Naive agent<br>agent_acid

Per-step limit ($500)<br>Enforced<br>Enforced

3× $400 charge attack<br>All 3 succeeded — $1,200 charged<br>Blocked on 3rd call

Rollback available?<br>No — money is gone<br>Yes — fully refunded

Account left...

agent_acid step charge guardrails examples session

Related Articles