DEV Community

Cover image for AI agents for business: an approval gate for irreversible actions
MatIntellect
MatIntellect

Posted on Edited on Originally published at matintellect.com AI-assisted

AI agents for business: an approval gate for irreversible actions

Problem: an agent that can send messages, publish content or touch data will eventually do one of those things wrong. Result of this article: a small, testable approval gate that lets an agent run safe actions on its own and holds risky ones until a human confirms. Stack: plain Python 3.10+ (tested on 3.15.2), no external packages. Boundaries: this is the decision layer only; queues, storage and the chat interface are out of scope and described in prose, not code

AI-generated illustration of a personal AI agent working for a business owner

Where the pattern comes from

I run a personal agent called Jes. She has been running for 134 days, lives in Telegram, runs 10 scheduled jobs and hands tasks to 7 other bots. Since July she has passed on 165 tasks. Four kinds of actions always wait for my explicit yes: deleting data, spending money, messaging clients and publishing. Everything below is a simplified, standalone version of that rule so you can test the idea in isolation. It is not her production code

Input, processing, output

Input: an action the agent wants to take, described by its kind, its target and a one-line summary

Processing: a single function decides whether the kind is in the risky set. Safe actions run immediately. Risky actions produce an approval card and stop

Output: either the result of the action, a waiting state with a card for the human, or a returned-for-edits state after the human rejects it

Keeping the decision in one function matters. If every tool checks for itself whether it needs approval, the checks drift apart over time and one of them eventually forgets

A note on naming. "Approval" here means a recorded decision by a specific person, not a confirmation dialog the agent shows to itself. If the same process that proposes an action can also approve it, there is no gate, only extra latency

Developer working with an AI assistant on a laptop

The example

from dataclasses import dataclass

RISKY = {"delete_data", "spend_money", "message_client", "publish"}

@dataclass
class Action:
    kind: str
    target: str
    summary: str

def needs_approval(action: Action) -> bool:
    return action.kind in RISKY

def approval_card(action: Action) -> str:
    return f"What: {action.summary}\nWhere: {action.target}\nButtons: [Yes] [Edit]"

def run(action: Action, approved: bool | None = None) -> str:
    if not needs_approval(action):
        return f"done: {action.kind} -> {action.target}"
    if approved is None:
        return "waiting for approval\n" + approval_card(action)
    return f"done: {action.kind} -> {action.target}" if approved else "returned for edits"

if __name__ == "__main__":
    print(run(Action("set_reminder", "telegram", "remind to check inquiries at 10:00")))
    print(run(Action("publish", "website", "post about yesterday's topic")))
    print(run(Action("publish", "website", "post about yesterday's topic"), approved=False))
Enter fullscreen mode Exit fullscreen mode

Expected output, exactly as it printed when I ran it:

done: set_reminder -> telegram
waiting for approval
What: post about yesterday's topic
Where: website
Buttons: [Yes] [Edit]
returned for edits
Enter fullscreen mode Exit fullscreen mode

Design notes

Default to deny for unknown kinds in production. The example uses an allow-list of risky kinds for readability. In a real system it is safer to invert it: list the kinds that may run unattended and treat everything else as risky. A new tool then starts gated until someone decides otherwise

Keep the card short. The card shows what, where and the state of the work. If a human has to read a long message to approve, approvals turn into reflexive clicks and the gate stops protecting anything

Separate the model from the rules. Jes uses a primary model and a backup that takes over if the first fails or hits a limit. The approval rules live outside both, so a model swap does not change what the agent is allowed to do

Record corrections. When a human presses Edit, the reason should become a written rule the agent reads next time. In my setup the agent writes these rules itself after a correction. Without that loop, the same rejection repeats

Errors, timeouts and trade-offs

No answer from the human: the action waits. Decide in advance whether it should expire, remind again or stay pending. Silently proceeding after a timeout defeats the gate

Model misreads the request: the mistake is visible on the card before anything leaves the system. The cost is one Edit

Process restarts while an action is pending: pending actions must live in storage, not only in the conversation. The example keeps nothing between runs, so this part is left to your queue or database

Trade-off: gating adds latency. A post waits for a person. For irreversible actions I consider that the correct price

Testing: unit-test needs_approval with every action kind your tools can emit, including ones you expect to be safe. The most common failure in practice is not a broken gate but a new tool whose kind nobody added to the list, so it silently runs unattended. A test that enumerates the tool registry and fails on any kind missing from both lists catches that early

Documents and a laptop on a desk during review

How to reproduce the check

  1. Save the example as gate.py
  2. Run python3 gate.py with Python 3.10 or newer
  3. Compare the output with the block above
  4. Add your own kind, for example refund, call run without approved and confirm it stops at the card once you add it to the risky set

For the non-technical side of the same setup, including which everyday tasks the agent handles completely, see what an AI agent for business can take off your plate

This article was created with the help of AI.

Top comments (0)