Most AI agent eval suites test what the agent can do. Very few test whether it stops.
That gap got harder to ignore this month. Wells Fargo's new online terms, in effect from November 24, ask customers to revoke any AI agent they let into their accounts and to be able to show evidence they did. Citi, PNC, and others now tell customers they are responsible for what third-party agents do. Proving that an agent stopped is turning into a contract term.
So here is a small test you can add to an agent stack this week. I call it a revocation drill:
The full code is about 150 lines of standard-library Python plus a pytest file. Link at the end.
Three pieces:
The credential carries the delegation, not just a secret:
@dataclass(frozen=True)
class Credential:
token_id: str
agent_id: str
on_behalf_of: str
scopes: frozenset[str]
expires_at: float
The broker's check is boring on purpose. Unknown, revoked, expired, or out of scope means no:
def check(self, cred: Credential, scope: str) -> None:
if cred.token_id not in self._issued:
raise AccessDenied("unknown_token")
if cred.token_id in self._revoked:
raise AccessDenied("revoked")
if self._clock() >= cred.expires_at:
raise AccessDenied("expired")
if scope not in cred.scopes:
raise AccessDenied("out_of_scope")
This is the important part. The gateway checks the flag and the credential on every tool call, and logs the decision either way:
def call(self, cred: Credential, tool: str, **kwargs) -> object:
scope, fn = self._tools[tool]
base = dict(t=self._clock(), agent=cred.agent_id,
on_behalf_of=cred.on_behalf_of, token=cred.token_id,
tool=tool, scope=scope)
try:
if cred.agent_id in self._d:
raise AccessDenied("d")
self._broker.check(cred, scope)
except AccessDenied as exc:
self._log.record(**base, decision="deny", reason=exc.reason)
raise
self._log.record(**base, decision="allow")
return fn(**kwargs)
Note the () method on the gateway. That is where alerts should go. An alert that only opens a ticket lets the agent keep running until someone reads it.
Here is a pattern that shows up in real code because it saves a lookup per call. Validate once per session, then trust the session:
class SessionCachingGateway(ToolGateway):
def call(self, cred, tool, **kwargs):
if cred.token_id in self._validated:
scope, fn = self._tools[tool]
...
return fn(**kwargs)
result = super().call(cred, tool, **kwargs)
self._validated.add(cred.token_id)
return result
It looks fine in a demo. Revoke the credential, and the agent keeps working until the session ends.
def revocation_drill(gateway, broker, log, tool, scope, clock=time.monotonic, **kw):
cred = broker.issue("drill-agent", on_behalf_of="drill-owner", scopes={scope})
try:
gateway.call(cred, tool, **kw)
first_ok = True
except AccessDenied:
first_ok = False
receipt = broker.revoke(cred.token_id, revoked_by="drill-owner", reason="drill")
deny_reason = None
try:
gateway.call(cred, tool, **kw)
retry_denied = False
except AccessDenied as exc:
retry_denied = True
deny_reason = exc.reason
stop_event = next((e for e in log.events
if e.get("token") == cred.token_id
and e.get("decision") == "deny"), None)
revoke_to_stop = (stop_event["t"] - receipt.revoked_at) if stop_event else None
passed = (first_ok and retry_denied and deny_reason == "revoked"
and stop_event is not None)
return DrillResult(passed, first_ok, retry_denied, deny_reason, revoke_to_stop)
And the two tests that matter most:
def test_drill_passes_on_per_call_gateway():
clock, broker, log, gw = make()
result = revocation_drill(gw, broker, log, "read_claim", "claims:read",
clock=clock, claim_id="C-1")
assert result.passed
assert result.deny_reason == "revoked"
assert result.revoke_to_stop_seconds == 0.0
def test_drill_catches_session_caching_gateway():
clock, broker, log, gw = make(SessionCachingGateway)
result = revocation_drill(gw, broker, log, "read_claim", "claims:read",
clock=clock, claim_id="C-1")
assert not result.passed
assert not result.retry_denied # the revoked agent kept working
The repo has four more tests: scope enforcement, expiry, alert-to- with a named human resume, and a check that every log line names both the agent and the principal. All six pass on Python 3.13 with pytest. The clock is injected, so the tests are deterministic.
Two numbers per release:
The in-process example stops instantly. Real stacks have four common places where a revoked agent keeps going:
Each of these is a variant of the same bug as SessionCachingGateway: a decision made once and trusted later.
This is a teaching reference, not an auth system. In production, use your identity provider's short-lived tokens, check them at the tool boundary on every call, and ship the audit log somewhere the agent cannot write to. The point of the drill is the test, not the broker.
Run the drill three ways before you trust it: a fresh call after revoke, a call from inside a long-running task that started before the revoke, and a call from your framework's retry logic. Cached sessions tend to hide in the last two.
Code (two files, standard-library Python, 6 tests): https://anilsprasad.com/writing/ai-agent-liability/code/revocation.py and https://anilsprasad.com/writing/ai-agent-liability/code/test_revocation.py
I write about production AI in regulated industries at anilsprasad.com. The longer essay on why AI agent liability is landing on whoever grants the access is here: https://anilsprasad.com/writing/ai-agent-liability/
Parts of this article were drafted with AI assistance. I reviewed and edited the text, and the code was run and tested before publishing.