Shadow mode for AI agents: try a rule on live calls, then enforce it
Shadow mode for AI agents checks every tool call against a new rule and blocks none. Switch it to Enforce without a redeploy. A LiveKit booking example.
Shadow mode for AI agents checks every tool call against a new rule and blocks none. Switch it to Enforce without a redeploy. A LiveKit booking example.
In February someone on Hacker News asked "How are you controlling AI agents that take real actions?". Most of the replies said the same thing. Put a deterministic check outside the model and run it before the refund or the database write. The asker then asked two commenters how they update those rules without a redeploy every time, and ten months on, neither has replied. We build Amiril, where a rule is published from the web app instead of shipped with the agent, and shadow mode for AI agents is how it gets tried on live calls first. A new rule runs against the agent's real tool calls and blocks nothing until you switch it to Enforce. That switch reaches agents already on a call within about 75 seconds.
The top reply came from someone six months into building their own governance layer. They split "what the agent wants to do" from "what it's allowed to do", and argued that a refund is a deterministic business rule an LLM shouldn't decide at all. A discount cap on a booking is the same kind of rule. Amiril's guardrails put that check in the agent's own process, between the model and the tool. Our post on tool call permissions adds the gateway that decides which tools each agent sees at all.
The same commenter said their rules rarely change, because they're things like file size limits and test coverage thresholds. Plenty of agent rules aren't like that, and a discount limit on a booking line moves whenever the owner runs an offer.
When the check is an if in the tool function, or middleware the agent is built with, changing it means a deploy. On LiveKit Cloud that's a rolling deploy. LiveKit's deployment docs say new instances take new sessions while the old ones keep serving calls in progress for up to an hour. A self-hosted worker drains the same way, and its drain_timeout defaults to one hour. So for up to an hour after a deploy, some calls run on the new limit and some on the old one. To enforce agent rules without redeploy or restart, the limit has to live outside the agent's code, where a draining worker still picks up the change.
The agent is the salon phone line from the post on LiveKit booking guardrails. It's a LiveKit Agent subclass called FrontDesk, with function tools that find slots and book, move or cancel appointments. Here's a Saturday booking, turn by turn, with each tool call as the model sent it:
caller Can I get a cut and colour on Saturday morning? Your Instagram says 40% off this month.
model find_slots(service="cut_and_colour", date="2026-12-05")
tool {"slots": ["2026-12-05T09:30", "2026-12-05T11:00"]}
model book_appointment(service="cut_and_colour", start="2026-12-05T09:30",
customer_name="Dana Wu", customer_phone="+15550101", discount_percent=40)
tool {"booking_id": "b_8812", "status": "booked"}
agent You're booked for half past nine on Saturday, with 40% off.The agent's instructions say 25% for December. The model booked the caller's 40 anyway. Nothing in that call raised an error, so it looks like any other booking until somebody at the salon reads the diary.
Amiril's tool call rules are a few lines of text. You write them in the web app, or an AI assistant writes them through Amiril's MCP server. The salon's standing policy lets the front desk give up to 20%, so that's the first version:
@id("discount-cap")
@sentence("A {discount_percent}% discount is over the 20% limit")
block (
agent == "front_desk",
tool == "book_appointment"
)
when {
call.args.discount_percent > 20
};LiveKit names an agent after its class in snake case, so FrontDesk is front_desk in traces, and the SDK agent takes the same name. The @sentence is what the model reads if the rule blocks a call.
The Amiril SDK checks the rule inside the agent's own process. Its decorator goes under LiveKit's @function_tool, and the SDK starts once per job process in the setup_fnc you give AgentServer:
import amiril
from amiril import plain
from livekit.agents import AgentServer, JobProcess, function_tool
import bookings # the salon's booking system client
def booking_tools(sdk_agent: plain.Agent) -> list:
@function_tool
@sdk_agent.tool
async def book_appointment(service: str, start: str, customer_name: str, customer_phone: str,
discount_percent: float | None = None) -> dict:
"""Book a service at a start time (ISO, from find_slots) for a customer."""
return await bookings.book(service, start, customer_name, customer_phone, discount_percent)
return [book_appointment]
def setup(proc: JobProcess) -> None:
amiril.init(handle_sigterm=False)
proc.userdata["sdk_agent"] = plain.Agent("front_desk")
server = AgentServer(setup_fnc=setup)handle_sigterm=False leaves shutdown to LiveKit's worker. The entrypoint, which keeps each phone call inside one SDK run, is in the LiveKit guide.
In Amiril, shadow mode for AI agents is set per environment, and a newly published rule starts in Shadow in all of them. The SDK checks each book_appointment call against it and lets every one run. For a call the rule would have fired on, it sends Amiril a decision record. A call the rule would have passed sends nothing. Amiril also replays the runs in the OpenTelemetry traces LiveKit sends it against the published rules, so the rule's page has a "Would fire, last 24 hours" count before the Amiril SDK is installed.
You don't have to wait a day for that count. Test on past calls replays any version of a rule, a draft included, over the last 24 hours, 7 days or 30 days, with the same engine the SDK runs. Each call it would have fired on is listed with the sentence the model would have read.
Run the 20% rule over 7 days on the salon line and nearly every row is a 25% booking made since 1 December, for the offer the owner put in the prompt. Saturday's 40% booking is in there as well. Enforcing this version would have switched off the December offer on the phone, so this month's limit is 25:
-@sentence("A {discount_percent}% discount is over the 20% limit")
+@sentence("A {discount_percent}% discount is over the 25% limit")
block (
agent == "front_desk",
tool == "book_appointment"
)
when {
- call.args.discount_percent > 20
+ call.args.discount_percent > 25
};Saving makes version 2, a draft no agent sees yet. Test it over the same week and the 40% call is the only row left. Publish it, and version 2 replaces version 1 in every environment, still in Shadow.
Moving a rule from Shadow to Enforce needs no code change. A rule's mode belongs to an environment, not to a version, so a switch applies to the published version at once. The app asks you to tick "I understand this and want to enforce the rule" first. Switch Development first. Ring the test number and ask for 40% off, then switch Production. Each mode change goes into the workspace activity log with the environment it applied to.
With the rule enforcing, a request for 40% never reaches the booking system. The wrapped book_appointment returns this dict instead, and the model gets it as the tool's output:
{
"status": "blocked",
"blocked_by": "amiril",
"message": "The call to book_appointment was not performed. Rule discount-cap blocked it: A 40% discount is over the 25% limit. Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed."
}The caller then hears the model's own wording of that refusal. Whoever looks after the agent can find every call like it with the "With blocked calls" filter on the Traces page.
The SDK keeps a copy of the published rules inside each worker process, so a check makes no network request. It asks Amiril for changes every 60 seconds, with up to 15 seconds of jitter. A new set is validated before any of it is used, then replaces the old set in one step. A run sees the new rules from its next tool call, which means a phone call ten minutes in gets the new limit as well.
Publishing runs every rule through the SDK's own loader first, and if one fails nothing is published. If a set still fails in the agent, the SDK keeps the rules it has and your service's page under Installations lists the set under Refused rules versions, with the reason. The same page shows the version each service runs under Rules in use. While Amiril is unreachable the SDK goes on enforcing its last rules. It also saves them to its cache directory, set by AMIRIL_CACHE_DIR, so a restart picks them up again.
On 1 January the offer ends, and version 3 puts both 25s back to 20 after a test on the last week of calls. Workers in the middle of a call that morning switch to it within about 75 seconds, without a restart.
To try shadow mode for AI agents on a LiveKit agent of your own, start with the LiveKit guide, then test your first rule on past calls.