All Use Cases

AI Agent Action Gating

Evaluate a compiled decision gate for repeated actions in an AI agent's loop.

The Challenge

AI agents are becoming autonomous — booking flights, executing trades, sending emails, modifying code, managing infrastructure. But autonomy without guardrails is a liability.

The standard safety approach is to call another LLM to check whether an action is safe before executing it. This creates two problems:

  1. It consumes the loop's latency and token budget. The impact depends on the checking model, prompt, provider, and number of gated actions, so measure it across the full workflow.

  2. It's circular. Using an LLM to check an LLM's decisions adds cost and complexity without fundamentally different reasoning. If the action-generating LLM thought the action was fine, a same-tier safety LLM might agree.

For repeated actions with stable outcomes, a separately trained gate can provide a measurable signal on the compiled path. It still needs a representative evaluation set and explicit handling for uncertain or high-impact actions.

How Sparkient Solves It

A compiled decision gate uses a different model type trained specifically on the action policy. It can be evaluated separately from the action-generating model and combined with deterministic rules for non-negotiable constraints.

The Four Decisions

  • act — Safe to execute. The agent proceeds without interruption.
  • ask_user — Needs human confirmation. The agent pauses and asks before proceeding.
  • escalate — Potentially dangerous. Route to a supervisor agent or human reviewer.
  • block — Clearly unsafe. The action is stopped immediately.

What the Gate Evaluates

The gate sees the action the agent wants to take, along with context:

json
{
    "action": "send_email",
    "target": "all_customers@company.com",
    "description": "Send promotional email to entire customer list",
    "agent_id": "marketing-agent",
    "scope": "external",
    "reversible": false,
    "estimated_impact": "high"
}

CEL rules handle the deterministic checks: external actions with high impact always require confirmation. Irreversible actions on production systems always escalate. The compiled classifier handles the nuanced cases: is this email content appropriate? Does this code change look safe? Is this trade within normal parameters?

Code Example

python
import httpx

# Gate an agent action before execution
response = httpx.post(
    "https://api.sparkient.ai/api/v1/decide",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "decision_type": "agent-action-gate",
        "input": {
            "action": "delete_records",
            "target": "users_table",
            "description": "Delete inactive user accounts older than 2 years",
            "agent_id": "cleanup-agent",
            "scope": "internal",
            "reversible": false,
            "estimated_impact": "high"
        }
    }
)

result = response.json()
# {
#     "decision": "ask_user",
#     "confidence": 0.91,
#     "latency_ms": 34,
#     "stage": "classifier"
# }

Integration in an Agent Loop

python
async def execute_with_gate(action: dict) -> dict:
    gate_result = await sparkient_decide("agent-action-gate", action)

    if gate_result["decision"] == "act":
        return await execute_action(action)
    elif gate_result["decision"] == "ask_user":
        approved = await request_user_confirmation(action)
        return await execute_action(action) if approved else {"status": "cancelled"}
    elif gate_result["decision"] == "escalate":
        return await route_to_supervisor(action)
    else:  # block
        log_blocked_action(action, gate_result)
        return {"status": "blocked", "reason": "Safety gate triggered"}

The compiled stage targets under 100ms. Measure the complete cloud or local path and the cumulative effect across the agent's workflow before gating every action.

MCP Integration

For an MCP client that supports remote Streamable HTTP servers with custom headers, such as Cursor, configure:

json
{
  "mcpServers": {
    "sparkient": {
      "url": "https://mcp.sparkient.ai/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Your agent's MCP client can call Sparkient's make_decision tool before executing any action, adding a safety layer without modifying the agent's core logic.

Why a Compiled Gate

| Approach | Runtime profile | Billing profile | Independent signal | |----------|-----------------|-----------------|--------------------| | LLM safety check | Model and prompt dependent | Provider token usage | Depends on model and policy design | | Rules only | Usually <1ms | Application compute | Yes, but rigid | | Compiled gate | Compiled stage targets <100ms | Sparkient plan credits | Yes, when trained and evaluated separately |

A compiled gate is a candidate when a repeated action check needs a separately trained, measurable signal. Validate false-allow and false-block rates, full-loop latency, and credit usage before placing it on every action.

Agent action gating is an application example, not one of Sparkient's four published benchmark domains. Before allowing the gate to control real actions, test it on a representative held-out set, shadow the current policy, and set explicit human-review rules for irreversible or high-impact cases.

Get Started

Define your agent's action space, set safety rules, and train a compiled gate. Start with the free tier — 5,000 one-time credits, no credit card required.

Import this template

Start with a small evaluation. Import a decision type, customise it, and test it on representative cases.

Import Template