Skip to main content
Pre-execution verification for AI agents. Use this guide when you need AI agent security, zero-trust approval flows, tool call verification, and runtime policy enforcement before an agent touches external systems.

Overview

QWED Agent Verification provides:
  • Pre-execution checks before agents act
  • Budget enforcement to limit costs
  • Risk assessment for each action
  • Activity logging for audit trails

Registering an agent

Verifying actions

Before an agent executes an action, you must provide an ActionContext with a conversation_id and a monotonically increasing step_number. These fields are required — requests without them are rejected.

Conversation controls

QWED enforces runtime guardrails that prevent agents from replaying actions, running in infinite loops, or exceeding conversation length limits. These checks run automatically on every verify_action call.

How it works

Each call to verify_action must include a conversation_id (identifying the current session) and a step_number (a positive integer that increases with each action in that session). QWED uses these fields to enforce four controls:

Incrementing steps correctly

The step_number must be strictly greater than any previously committed step within the same conversation. If an action is denied (for example, due to a loop), that step number is not consumed — you can retry the same step with a different action.
If your agent framework retries failed actions automatically, make sure it does not reuse the same step_number for a previously approved step. Replayed step numbers are always rejected.

Progress-aware doom loop detection (LOOP-004)

New in v5.1.0
LOOP-003 catches agents that repeat the same action consecutively, but it cannot detect an agent that keeps retrying an action when the underlying system state has not changed. LOOP-004 addresses this by binding each action to the world state at the time it was proposed. To enable LOOP-004, include pre_action_state_hash and state_source in the action context:
The guard tracks a sliding window of the last 20 action+state fingerprints per conversation. If the same fingerprint appears 3 or more times, the action is halted with QWED-AGENT-LOOP-004. Accepted state_source values: Validation rules:
  • pre_action_state_hash must be a 64-character lowercase hex SHA-256 digest
  • Both pre_action_state_hash and state_source must be provided together — supplying only one is rejected
  • During gradual rollout, both fields are optional. When the server enables DOOM_LOOP_GUARD_REQUIRED, they become mandatory
LOOP-004 fingerprints are only committed to the sliding window when the action decision is APPROVED. Denied and pending actions do not affect the history, preventing false positives from rejected retries.

Trust levels

Tool approval policy

Changed in v5.0.2
The ToolApprovalSystem classifies every tool call into one of three categories before execution: Unknown tools are denied by default, regardless of their heuristic risk score. Previously, unknown tools with a low risk score (below 0.3) were auto-approved. This fail-closed behavior ensures that new or unexpected tools cannot execute without being explicitly added to the allowlist. When an unknown tool is blocked, the response includes the tool name and the computed risk score for debugging:
To allow a custom tool, add it to the safe operations list in your ToolApprovalSystem configuration.

Risk assessment

Actions are assessed for risk:

Decision matrix

Tool approval policy

Changed in v5.0.2
The tool approval system categorizes every tool call into one of three groups before execution: Unknown tools are always denied, regardless of their computed risk score. The blocked response includes the tool name and risk score for debugging:
Before v5.0.2, unknown tools with a risk score below 0.3 were auto-approved. If your agents rely on custom tools that were previously approved through this heuristic, you must add them to the safe operations allowlist. See the changelog for migration details.

Adding tools to the allowlist

Register custom tools as safe operations when configuring your agent’s permissions:

Budget enforcement

Activity logging

Runtime hardening

New in v5.0.0
QWED enforces several runtime controls to prevent agent misuse, infinite loops, and replay attacks. These protections operate at the verification kernel level and cannot be bypassed by agents.

Action context enforcement

Every verify_action call requires an ActionContext with: The step number must increase with each action in a conversation. Attempts to reuse or decrement step numbers are rejected.

Registered action enforcement

New in v5.1.1
Every verify_action call must reference an action_type that QWED has registered semantics for. Action types must be either bound to a verification engine or registered as a governed tool with a known risk level. Engine examples: verify_mathmath, execute_sqlsql. Tool examples: read_database, send_email. Action types outside those two registries are denied with QWED-AGENT-ACTION-001 before any risk assessment runs.
The denial fires before risk assessment, so unknown actions can never be auto-approved through a permissive default. The reserved conversation step is released, allowing the agent to retry the same step with a registered action type. To allow a custom action, either bind it to an engine in ACTION_ENGINES or add it to your tool registry with an explicit risk level. Tools registered this way are reported with engine: "tool_control" in the verification response.
Before v5.1.1, unknown action types defaulted to engine: "security" and proceeded through risk assessment as MEDIUM risk. This could result in APPROVED or PENDING decisions depending on the agent’s trust level. Audit any production agents that emit non-standard action_type values and register them explicitly before upgrading.

Replay and loop detection

The agent service detects and blocks four types of problematic patterns: Actions are fingerprinted deterministically using action_type, query, code, target, and parameters. When pre_action_state_hash is provided, the fingerprint also incorporates the world state hash. If a loop is detected, the conversation state is not advanced — the agent can recover by submitting a different action at the same step number.

Fail-closed for unknown action types

QWED denies any verify_action call whose action_type has no registered engine binding or tool risk level. Action verification is deterministic — actions without explicit semantics cannot be risk-assessed or routed to a verification engine, so the kernel returns a denial instead of falling back to a permissive default.
A denial under QWED-AGENT-ACTION-001 releases the in-flight step reservation, so the agent may retry the same step number with a registered action type. Registered action types include the entries in ACTION_ENGINES (such as calculate, verify, prove) and tools listed in TOOL_RISK_LEVELS.

In-flight reservation system

While QWED processes a verify_action call, it reserves the step number so concurrent requests cannot claim the same step. QWED releases the reservation if the action is denied, allowing the agent to retry with a different action at the same step.

Budget denial behavior

When a budget check fails, the conversation step is not consumed. This means the agent can retry the same step number after the budget resets without triggering a replay detection error.

Fail-closed rate limiting

The Redis-backed sliding window rate limiter fails closed when Redis is unavailable. If the Redis backend encounters an error, all requests are denied rather than allowed, preventing uncontrolled access during infrastructure failures. When Redis is entirely absent at startup, a local in-memory fallback limiter is used instead.

Environment integrity verification

On API server startup, QWED runs an environment integrity check (via StartupHookGuard) before initializing the database. If the environment is compromised, the server refuses to start. This prevents operation in tampered runtime environments.

Timing-safe token verification

Agent token verification uses hmac.compare_digest for constant-time comparison, preventing timing side-channel attacks against agent authentication.

Fail-closed on unknown actions

QWED only verifies actions whose action_type has explicit, registered semantics. If you submit an action_type that is not bound to a verification engine or a known tool, the request is denied with QWED-AGENT-ACTION-001 before risk assessment runs. Registered actions fall into two categories: Anything else — including custom action names, typos, and forward-compatible names that the runtime does not yet recognize — is denied:
Key behaviors to plan for:
  • No verification block is returned. Unknown actions never receive an engine label or a VERIFIED status — there is no generic "security" fallback.
  • The step reservation is released. Because the action was denied, the same step_number can be retried with a registered action (no QWED-AGENT-LOOP-002 replay error).
  • Map custom intents to registered actions. If your agent needs to perform a domain-specific operation, route it through one of the registered verification engines or tool calls rather than inventing a new action_type string.

Framework integration

LangChain

CrewAI