Status: Draft
Version: 1.1.1
Date: 2026-04-06
Extends: QWED-SPEC v1.0, QWED-Attestation v1.0
Table of contents
- Introduction
- Agent verification model
- Agent registration
- Verification requests
- Tool verification
- Budget & limits
- Audit trail
- Trust levels
- Runtime hardening
- 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
Thecontext 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
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_typequerycodetargetparameters
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
pre_action_state_hash and state_source are provided in the action context, the guard computes a combined fingerprint:
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:- When a verification request begins processing, the step number is reserved
- Concurrent requests for the same step are rejected with
QWED-AGENT-LOOP-002 - If the action is denied, the reservation is released — the step can be retried
- 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 anyaction_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:
- Risk assessment is not performed — there is no deterministic risk binding for the action.
- Verification checks are not run.
- The in-flight step reservation is released so the agent can retry the same step number with a registered action.
- The response is
DENIEDwith error codeQWED-AGENT-ACTION-001.
decision and error — no verification block is emitted, because no engine is bound to the action:
"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 (viaStartupHookGuard) 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 whoseaction_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-001before risk assessment runs. - No
verificationblock 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_numberwith a registered action.
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.