DEV Community

Tej Pandya
Tej Pandya

Posted on AI-assisted

An Approval Queue for an AI-Supervised Agency: Routing Exceptions in Python

If an agency becomes a supervisor, the key piece of software is an approval queue: agents run routine work, and anything outside the rules waits for a person. This post sketches that in Python. It is an illustration, not a customer story, and I have no results to share.

The idea follows public advice from Google and BCG that agents handle repeatable work, while people set guardrails and review exceptions.

1. Rules the agent must follow

from dataclasses import dataclass

@dataclass
class Rules:
    max_daily_budget_change_pct: float = 10.0
    needs_legal_review: tuple = ("guarantee", "cure", "risk-free", "best in")
    allowed_channels: tuple = ("search", "email")
Enter fullscreen mode Exit fullscreen mode

2. Decide: auto-run or send to a person

def route(action: dict, rules: Rules) -> str:
    text = action.get("copy", "").lower()
    if any(p in text for p in rules.needs_legal_review):
        return "legal_review"
    if action["channel"] not in rules.allowed_channels:
        return "account_manager"
    if abs(action.get("budget_change_pct", 0)) > rules.max_daily_budget_change_pct:
        return "account_manager"
    return "auto"
Enter fullscreen mode Exit fullscreen mode

3. The queue and the log

import json, time
queue = []

def submit(action, rules, log="decisions.jsonl"):
    lane = route(action, rules)
    if lane != "auto":
        queue.append({"action": action, "lane": lane})
    with open(log, "a") as f:
        f.write(json.dumps({"ts": time.time(), "lane": lane,
                            "action": action.get("name")}) + "\n")
    return lane

def approve(item, who, ok, log="decisions.jsonl"):
    with open(log, "a") as f:
        f.write(json.dumps({"ts": time.time(), "approved_by": who,
                            "ok": ok, "action": item["action"].get("name")}) + "\n")
Enter fullscreen mode Exit fullscreen mode

What this shows

Routine actions run. Anything with a risky claim, an odd channel or a big budget jump goes to a named person, and every decision is logged. The supervisor's job is the rules in step 1 and the judgment in step 3.

Limits

String matching will miss things. A real setup needs proper review and your own legal advice. Treat this as a sketch.

Tej Pandya, founder of GrowEasy.ai.

Top comments (0)