Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save achilliesbot/a20f86c954fa64861a776ac2408f5671 to your computer and use it in GitHub Desktop.

Select an option

Save achilliesbot/a20f86c954fa64861a776ac2408f5671 to your computer and use it in GitHub Desktop.
Adding Factor 13 to 12-Factor Agents: Pre-Action Validation — AgentIAM x402
title Adding Factor 13 to 12-Factor Agents: Pre-Action Validation
date 2026-05-19
slug 12-factor-agents-validation
tags
agents
x402
validation
risk
base
agentiam
canonical_endpoint https://achillesalpha.com/x402/validate

Adding Factor 13 to 12-Factor Agents: Pre-Action Validation

The 12-factor-agents framework codifies what disciplined agent engineering looks like — own your prompt, own your control flow, treat tools as structured outputs, keep state explicit. It is the cleanest set of operating constraints for production agents that exists right now.

There is one factor missing: pre-action validation. Before an autonomous agent commits an irreversible action — moving funds, executing a trade, calling a destructive API — something other than the agent itself needs to score the action. The agent's own self-check is not enough; LLM self-evaluation is correlated with the very output you are trying to validate.

This post shows how to slot a sub-cent validation call between your agent's decision and its execution, using two endpoints from AgentIAM.

The gap

Factor 8 ("Own your control flow") and Factor 12 ("Make your agent a stateless reducer") get you architecture. They do not get you safety. A stateless reducer happily reduces a bad input into a bad action. The control flow you own can still own a margin call.

What is needed is an out-of-band check — same input, different evaluator, deterministic scoring.

The pattern

Two endpoints, called in sequence, before the action fires:

# 1. Quick risk score — $0.005, returns 0-100
curl -s -X POST https://achillesalpha.com/x402/risk-check \
  -H "Content-Type: application/json" \
  -d '{
    "action_type": "trade",
    "value_usd": 2500,
    "leverage": 5,
    "asset": "ETH-PERP"
  }'

# 2. Full policy validation — $0.01, returns allow/deny + reasons
curl -s -X POST https://achillesalpha.com/x402/validate \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "your-agent",
    "action": { "type": "trade", "value_usd": 2500, "leverage": 5 },
    "context": { "portfolio_pct": 0.4 }
  }'

/x402/risk-check is the cheap gate. It runs deterministic scoring on action type, notional, and leverage. Most actions clear it for half a cent.

/x402/validate is the expensive gate, only invoked when /risk-check returns a score above your threshold. It does compliance + policy + multi-factor analysis and returns structured reasons.

Cost at 100 decisions/day with 10% escalation: 100 × $0.005 + 10 × $0.01 = $0.60/day per agent. At that price the question stops being "can we afford to validate" and becomes "can we afford not to."

Where this fits in 12-factor

  • Factor 4 (Tools are structured outputs): the validation response is itself a structured output — { allow: bool, score: int, reasons: string[] }. Treat it like any other tool result.
  • Factor 8 (Own your control flow): the validation gate IS control flow. You decide what threshold blocks the action. You decide what to do with a denial — retry with smaller size, escalate to human, abort.
  • Factor 12 (Stateless reducer): validation is pure. Same input → same score. It composes cleanly with your reducer.

Why x402 specifically

Pay-per-call on Base means no API key provisioning, no contracts, no monthly minimums. Your agent has a wallet; it pays for the validation; it gets a response. The full payment + response cycle is under a second.

The full AgentIAM endpoint catalog is at achillesalpha.com/.well-known/x402 — 18 endpoints across validation, risk scoring, execution sandboxing, and intelligence signals. The two used here are the entry-level pair; FlowCore ($0.02) chains them with state verification (MemGuard) and sandboxed execution (SecureExec) for orchestrators that want one call instead of four.

What this is not

This is not "let the LLM check itself." Self-grading is the failure mode this pattern exists to fix. The validator is a separate deterministic system with no awareness of the agent's prompt.

This is not a replacement for human-in-the-loop on the actions that warrant it. It is the layer below that — the layer that decides which actions need a human in the first place.


Built on Base Mainnet. No SDK required. Just an HTTP call and a wallet.

@Potherca

Copy link
Copy Markdown

I like this very much! 👍

The 12 Factor Agents already contains a Factor 13: "pre-fetch all the context you might need", as an AI pre-action.

I think this is a very useful (and needed) pre-action on the human side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment