Skip to main content
Status: Draft
Version: 1.1.1
Date: 2026-04-06
Extends: QWED-SPEC v1.0, QWED-Attestation v1.0

Table of contents

  1. Introduction
  2. Agent verification model
  3. Agent registration
  4. Verification requests
  5. Tool verification
  6. Budget & limits
  7. Audit trail
  8. Trust levels
  9. Runtime hardening
  10. Implementation guidelines

1. Introduction

1.1 Purpose

QWED-Agent defines a protocol for AI agents to verify their actions before execution. As agentic AI systems become more autonomous, QWED-Agent provides guardrails ensuring agents operate within defined boundaries.

1.2 Problem statement

1.3 Solution

QWED-Agent establishes:
  • Pre-execution verification of agent outputs
  • Tool call approval workflow
  • Budget enforcement
  • Complete audit trail
  • Trust level management

1.4 Terminology


2. Agent verification model

2.1 Verification flow

2.2 Verification types for agents

2.3 Decision matrix


3. Agent registration

3.1 Registration request

Agents MUST register with QWED before use:

3.2 Registration response

3.3 Agent types

3.4 Agent identity

Agents receive a DID-based identity:

4. Verification requests

4.1 Agent verification request

The context object with conversation_id and step_number is required. The step_number must be a positive integer that increases monotonically within a conversation. QWED uses these fields to enforce replay protection, loop detection, and conversation length limits. See conversation controls for details.

4.2 Verification response

4.3 Decision types


5. Tool verification

5.1 Tool call request

Before an agent calls an external tool:

5.2 Tool risk assessment

5.3 Tool registry


6. Budget & limits

6.1 Budget schema

6.2 Budget enforcement

6.3 Budget response


7. Audit trail

7.1 Activity log schema

Every agent action is logged:

7.2 Audit query API

Response:

7.3 Compliance export


8. Trust levels

8.1 Trust level definitions

8.2 Trust elevation

Agents can request trust elevation:

8.3 Trust degradation

Automatic trust reduction on violations:

9. Runtime hardening

New in v1.1.0

9.1 Action context requirements

All verification requests MUST include a context with: The maximum number of steps per conversation is 50. Exceeding this limit triggers QWED-AGENT-LOOP-001.

9.2 Replay detection

The runtime tracks the highest committed step number per (agent_id, conversation_id) pair. A verification request with a step_number less than or equal to the last committed step is rejected as a replay (QWED-AGENT-LOOP-002). Step numbers are only committed when the action decision is APPROVED or PENDING. Denied actions do not advance the conversation state, allowing the agent to retry the same step number with a different action.

9.3 Repetitive loop detection

Actions are fingerprinted using a deterministic JSON serialization of:
  • action_type
  • query
  • code
  • target
  • parameters
If the same fingerprint appears more than 2 consecutive times, the action is blocked with QWED-AGENT-LOOP-003. The repeat counter resets when a different action is submitted. Action parameters MUST be deterministic JSON-compatible values (strings, numbers, booleans, nulls, arrays, and objects with string keys). Non-finite floats (NaN, Infinity) and non-string dictionary keys are rejected.

9.4 Progress-aware doom loop detection (LOOP-004)

New in v1.1.1
LOOP-003 detects repeated actions but cannot detect an agent that retries the same action on an unchanged world state. LOOP-004 closes this gap by binding each action fingerprint to the state of the environment at the time it was proposed. When pre_action_state_hash and state_source are provided in the action context, the guard computes a combined fingerprint:
The combined fingerprint is tracked in a per-conversation sliding window of the last 20 entries. If the same combined fingerprint appears 3 or more times (including the current request), the action is blocked with QWED-AGENT-LOOP-004. Key design properties: Gradual rollout: The server-side flag DOOM_LOOP_GUARD_REQUIRED controls whether pre_action_state_hash and state_source are mandatory. When set to false (the default during rollout), requests without these fields skip LOOP-004 checks. When set to true, requests without both fields are rejected with QWED-AGENT-STATE-001. Both fields must be provided together. Supplying only one triggers QWED-AGENT-STATE-001.

9.5 In-flight reservations

To prevent race conditions in concurrent environments, the runtime uses a reservation system:
  1. When a verification request begins processing, the step number is reserved
  2. Concurrent requests for the same step are rejected with QWED-AGENT-LOOP-002
  3. If the action is denied, the reservation is released — the step can be retried
  4. If the action is approved or pending, the reservation is committed — the step is permanently consumed

9.6 Unknown action type denial

The runtime fails closed for any action_type that does not have explicit registered semantics. An action type is considered registered when it appears in either the action-engine map (e.g. execute_sql, execute_code, verify_logic) or the tool risk map (e.g. calculate, read_file, database_read). When an unregistered action_type is submitted:
  1. Risk assessment is not performed — there is no deterministic risk binding for the action.
  2. Verification checks are not run.
  3. The in-flight step reservation is released so the agent can retry the same step number with a registered action.
  4. The response is DENIED with error code QWED-AGENT-ACTION-001.
The denial response contains only decision and error — no verification block is emitted, because no engine is bound to the action:
Previously, unregistered action types would receive a generic "security" engine label and could pass through verification. The runtime no longer emits this fallback engine; the engine field in a verification response always reflects the explicitly registered engine for the action.

9.7 Budget denial semantics

Budget check failures (QWED-AGENT-BUDGET-001, QWED-AGENT-BUDGET-002) do not consume the conversation step. The in-flight reservation is released so the agent can retry the same step number after the budget resets.

9.8 Fail-closed rate limiting

When the Redis backend is unavailable, the sliding window rate limiter fails closed (denies all requests) rather than failing open. This prevents uncontrolled access during infrastructure failures. When Redis is entirely absent at process startup, a local in-memory fallback limiter is used.

9.9 Environment integrity

On server startup, the runtime MUST verify environment integrity (via StartupHookGuard) before initializing the database. A compromised environment causes the server to abort startup with a RuntimeError.

9.10 Timing-safe authentication

Agent token verification MUST use constant-time comparison (hmac.compare_digest) to prevent timing side-channel attacks.

9.11 Fail-closed on unknown actions

The runtime MUST reject any verification request whose action_type is not explicitly registered in the agent service. An action is considered registered only when it appears in either the engine map (e.g. execute_sql, execute_code, calculate, verify_logic, verify_fact) or the tool risk table (e.g. database_read, database_write, send_email, file_read, file_write, file_delete, api_call). When an action_type has no registered semantics:
  • The request is denied with QWED-AGENT-ACTION-001 before risk assessment runs.
  • No verification block is returned — the runtime never emits a generic "security" engine fallback for unknown actions.
  • The in-flight step reservation is released so the agent can retry the same step_number with a registered action.
This guarantees that verification outcomes are always tied to explicit, deterministic semantics. An unrecognized action cannot be silently treated as approved or marked as VERIFIED.

10. Implementation guidelines

10.1 SDK integration

10.2 LangChain integration

10.3 CrewAI integration


Appendix A: Error codes

Appendix B: HTTP endpoints


© 2025 QWED-AI. This specification is released under Apache 2.0 License.