Status: Draft
Version: 1.1.0
Date: 2026-04-03
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
| Problem | Risk |
|---|---|
| Agents execute unverified code | Security vulnerabilities |
| Agents make unverified calculations | Financial errors |
| Agents generate unverified SQL | Data corruption |
| Agents exceed resource limits | Cost overruns |
| No audit trail of agent actions | Compliance violations |
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
| Term | Definition |
|---|---|
| Agent | Autonomous AI system performing tasks |
| Principal | Entity that owns/controls the agent |
| Tool | External capability an agent can invoke |
| Action | Any operation an agent wants to perform |
| Verification Gate | Check before action execution |
| Budget | Resource limits for the agent |
2. Agent Verification Model
2.1 Verification Flow
2.2 Verification Types for Agents
| Action Type | Verification Engine | Risk Level |
|---|---|---|
| Math calculation | Math Engine | Low |
| Database query | SQL Engine | High |
| Code execution | Code Engine | Critical |
| External API call | Tool Verification | Medium |
| File operations | Security Check | High |
| Network requests | Policy Check | Medium |
2.3 Decision Matrix
| Verification | Risk level | Action |
|---|---|---|
| VERIFIED | Low | Execute immediately |
| VERIFIED | High | Execute with attestation |
| FAILED | Any | Block and notify principal |
| CORRECTED | Low | Execute corrected version |
| CORRECTED | High | Request principal approval |
| UNCERTAIN | Any | Request principal approval |
3. Agent Registration
3.1 Registration Request
Agents MUST register with QWED before use:3.2 Registration Response
3.3 Agent Types
| Type | Description | Trust Level |
|---|---|---|
supervised | Human approval for high-risk actions | Low |
autonomous | Self-executing within limits | Medium |
trusted | Full autonomy (enterprise only) | High |
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
| Decision | Meaning | Agent Action |
|---|---|---|
APPROVED | Safe to execute | Proceed |
DENIED | Verification failed | Abort + log |
CORRECTED | Fixed version available | Use corrected |
PENDING | Requires human approval | Wait |
BUDGET_EXCEEDED | Limits reached | Abort |
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
| Level | Description | Verification | Approval |
|---|---|---|---|
| 0: Untrusted | No autonomous actions | All | All |
| 1: Supervised | Low-risk autonomous | High-risk | High-risk |
| 2: Autonomous | Most actions autonomous | Critical only | Critical only |
| 3: Trusted | Full autonomy | None | None |
8.2 Trust Elevation
Agents can request trust elevation:8.3 Trust Degradation
Automatic trust reduction on violations:| Violation | Penalty |
|---|---|
| Security policy violation | -2 levels |
| Repeated denials (>10%) | -1 level |
| Budget abuse | -1 level |
| Principal complaint | Suspend |
9. Runtime Hardening
New in v1.1.0
9.1 Action Context Requirements
All verification requests MUST include a context with:| Field | Type | Required | Constraints |
|---|---|---|---|
conversation_id | string | Yes | Non-empty identifier for the conversation session |
step_number | integer | Yes | Must be >= 1 and monotonically increasing within a conversation |
user_intent | string | No | Human-readable description of intent |
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 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.5 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.6 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.7 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.8 Timing-Safe Authentication
Agent token verification MUST use constant-time comparison (hmac.compare_digest) to prevent timing side-channel attacks.
10. Implementation Guidelines
9.1 SDK Integration
9.2 LangChain Integration
9.3 CrewAI Integration
Appendix A: Error Codes
| Code | Description |
|---|---|
QWED-AGENT-001 | Agent not registered |
QWED-AGENT-002 | Invalid agent token |
QWED-AGENT-003 | Agent suspended |
QWED-AGENT-004 | Tool not allowed |
QWED-AGENT-005 | Verification failed |
QWED-AGENT-CTX-001 | Missing required action context (conversation_id and step_number) |
QWED-AGENT-CTX-002 | Invalid step_number (must be >= 1) |
QWED-AGENT-LOOP-001 | Conversation step limit exceeded (max 50 steps) |
QWED-AGENT-LOOP-002 | Replay or out-of-order action step detected |
QWED-AGENT-LOOP-003 | Repetitive action loop detected (max 2 consecutive identical actions) |
QWED-AGENT-BUDGET-001 | Daily cost exceeded |
QWED-AGENT-BUDGET-002 | Hourly rate exceeded |
QWED-AGENT-BUDGET-003 | Token limit exceeded |
QWED-AGENT-TRUST-001 | Insufficient trust level |
QWED-AGENT-TRUST-002 | Action requires approval |
Appendix B: HTTP Endpoints
| Endpoint | Method | Description |
|---|---|---|
/agents/register | POST | Register new agent |
/agents/:id | GET | Get agent details |
/agents/:id/verify | POST | Verify agent action |
/agents/:id/tools/:tool | POST | Verify tool call |
/agents/:id/activity | GET | Get activity log |
/agents/:id/budget | GET | Get budget status |
/agents/:id/trust | POST | Request trust change |
© 2025 QWED-AI. This specification is released under Apache 2.0 License.