Architecture & Metrics Baseline
Engineering metrics baseline and architecture observability.
Purpose: Architectural reference for follow-up metrics, onboarding, and product decisions.
Source of truth: This document is derived from the codebase only (agentrust-edge/, agentrust_sdk/, k8s/). External URLs and CLI stubs are called out where the code references them but does not implement them.
Last reviewed against: gateway, SDK, dashboard, docker-compose, and k8s manifests in this repository.
Table of contents
- What problem this code solves
- How users can use this platform
- Edge-only vs server deployment
- Server-side management requirements
- Agent development support
- Evolving into an agent certification harness
- Integrating new agent frameworks
- Metrics to track
- Repository layout
- Explicit gaps (not in repo)
1. What problem this code solves
This repository implements runtime governance for AI agent executions. Each agent run is validated, scored, risk-rated, and given a decision before its output is treated as trustworthy.
Core pipeline
The primary entry point is POST /v1/runtime/validate in agentrust-edge/gateway/routes/runtime.py. The documented pipeline:
- Fetch historical reliability (Redis cache → audit store)
- Run six-check
ValidationEngine - Run seven-signal
ConfidenceEngine - Run full
RiskEngine(formula scoring) - Run
DecisionEngine - Persist to append-only audit ledger
- Push
escalate/request_evidencedecisions to review queue (fire-and-forget) - Enqueue LLM judge job for slow-path enrichment (fire-and-forget)
Validation (fast path)
ValidationEngine in agentrust-edge/gateway/engines/validation_engine.py is documented as target: <20ms, zero LLM calls. It runs:
| Check | Role |
|---|---|
| Schema | Output structure validation |
| Tool trust | Tool call / result verification |
| Policy | Policy pack rules |
| Consistency | Output consistency (with optional contradiction detector) |
| Golden tests | YAML-defined regression rules |
| Grounding | Evidence / grounding checks |
| Adversarial | Hard gate; caps policy score on failure |
Decisions and risk
Defined in agentrust-edge/gateway/models/envelope.py:
- Decision outcomes:
approve,retry,request_evidence,escalate,block,pending - Risk tiers:
low,medium,high,critical - Frameworks:
LangGraph,CrewAI,OpenAI Agents,Claude Agents,MCP,Custom,REST
Supporting capabilities (in code)
| Concern | Implementation |
|---|---|
| Confidence scoring | ConfidenceEngine — weighted signals: schema, tool trust, policy, consistency, evidence, judge, historical reliability |
| Audit & compliance | AuditStore, /v1/audit/*, 90-day payload retention loop in main.py |
| Human review | review_queue for escalate / request_evidence |
| Async LLM judge | Redis worker started in gateway lifespan (main.py) |
| Multi-agent trust | parent_envelope_id + trust_chain_service (can block on violation) |
| Golden / regression tests | gateway/config/golden_tests/*.yaml (e.g. payment_agent.yaml) |
| Reliability over time | reliability_service, /v1/agents/{agent_id}/reliability |
Product naming (from code)
- Gateway: AgentTrust Edge Gateway (
agentrust-edge/gateway/main.py) - SDK: AgentTrust Edge — the AI Agent Harness (
agentrust_sdk/pyproject.toml)
Problem statement (from behavior): Agents from many frameworks produce structured outputs and tool calls. This stack measures trustworthiness per execution, enforces policy, records an auditable envelope, and routes risky runs to human review—with deterministic checks on the fast path and optional async LLM judging on the slow path.
2. How users can use this platform
2.1 Local / self-hosted stack
agentrust-edge/docker-compose.yml runs:
| Service | Port | Role |
|---|---|---|
| Postgres | 5432 | Audit and execution storage |
| Redis | 6379 | Job queue, rate limiting, cache |
| Gateway | 8000 | Validate + management APIs |
| Dashboard | 3000 | React UI (VITE_API_URL → gateway) |
Required env (from compose): POSTGRES_PASSWORD, REDIS_PASSWORD, AGENTRUST_JWT_SECRET; optional AGENTRUST_API_KEYS.
2.2 HTTP API — validate
Endpoint: POST /v1/runtime/validate
Router prefix: /v1/runtime (routes/runtime.py)
Clients send agent id, framework, request (user, input), execution metadata (model, tools, latency, tokens), and output. Response includes envelope_id, validation scores, risk, decision, latency, and governance disclosure text.
2.3 Other gateway APIs
Routers registered in agentrust-edge/gateway/main.py:
| Prefix | Purpose |
|---|---|
/v1/runtime | Validate executions |
/v1/audit | List/get executions, verify audit chain |
/v1/review | Human review queue |
/v1/policy | Policy evaluation |
/v1/agents | Agent reliability metrics |
/v1/analytics | Analytics |
/v1/alerts | Alerts |
/v1/feedback | Feedback |
/v1/health | Health checks |
2.4 Python SDK (agentrust-sdk v2.0.0)
| Mechanism | Location | Behavior |
|---|---|---|
@harness decorator | agentrust_sdk/decorator.py | Wraps agent functions; validates after execution |
validate | Same module | Alias for @harness |
AgentTrustClient / AsyncAgentTrustClient | agentrust_sdk/client.py | HTTP client; tier-gated response fields |
| OSS tier (no API key) | client.py | Local schema-only via _oss_schema_only; no HTTP |
| LangGraph adapter | adapters/langgraph.py | AgentTrustNode (Team tier) |
| CrewAI adapter | adapters/crewai.py | AgentTrustCallback (Team tier) |
| CLI | cli.py | init, whoami, status, policy, audit tail, etc. |
Default gateway URL: http://localhost:8000 (client.py, decorator._resolve_base_url reads config control_plane_url with same default).
Blocking behavior: @harness can raise BlockedError on block or review outcomes when configured (decorator.py).
2.5 Dashboard
React app (agentrust-edge/dashboard/src/App.tsx):
| Route | Page |
|---|---|
/ | Dashboard home |
/executions | Executions list |
/executions/:id | Execution detail |
/review | Review queue |
/reliability | Agent reliability |
/policies | Policy packs |
/health | System health |
Roles stored in browser localStorage: admin, auditor, developer (client-side only; not enforced by gateway auth by default).
2.6 Tier and auth model
- API key / JWT via header
X-AgentTrust-Token(middleware/auth.py,auth.py) - Capabilities gated by tier in
agentrust_sdk/tiers.py: OSS → Team → Enterprise - Without a key, SDK uses OSS tier (local schema validation only)
3. Edge-only vs server deployment
What the code ships
| Deployment | Evidence |
|---|---|
| Docker Compose | Full stack in agentrust-edge/docker-compose.yml |
| Kubernetes | k8s/agentrust-edge/ (also agentrust-edge/k8s/) — postgres, redis, gateway (multi-replica in 03-gateway.yaml), dashboard, ingress |
| Naming | Product is Edge Gateway; SDK defaults to local gateway URL |
| Enterprise flag | Capability.SELF_HOSTED in tiers.py — message references Enterprise tier; no separate control-plane binary in repo |
| SDK URL | control_plane_url optional on client; resolves to same HTTP validate surface as base_url |
Conclusion
| Shape | Supported in repo? |
|---|---|
| Single machine / “edge-like” (compose) | Yes |
| K8s / datacenter server | Yes — same gateway + Postgres + Redis + dashboard |
| Separate SaaS control plane service | Not implemented — CLI and tier flags reference it only |
Edge here means tenant-owned governance runtime (self-hosted gateway + data plane), not a requirement for physical edge hardware. The same codebase deploys via compose or k8s.
4. Server-side management requirements
Required for full operation (in-repo)
| Component | Role |
|---|---|
| Gateway | Validate pipeline + management APIs |
| Postgres | Audit ledger, executions (DATABASE_URL) |
| Redis | Judge queue, rate limit, cache (REDIS_URL) |
| Dashboard | Optional UI; API-only integration is valid |
| Config | Policy and golden-test YAML under gateway/config/; settings via env (config/settings.py) |
Gateway lifespan (main.py): DB migrations on startup, judge worker, retention maintenance every 6 hours.
Not required in-repo (referenced but stubbed / external)
| Feature | Code evidence |
|---|---|
| Remote control plane | CLI policy sync / policy push print *Connect to control plane — agentrust init first* without HTTP implementation (cli.py`) |
| Central audit | Capability.CENTRAL_AUDIT in tiers.py — no separate central audit service |
| Policy sync from cloud | Capability.POLICY_SYNC — CLI stub only |
| Commercial URLs | agentrust.io, docs.agentrust.io in pyproject.toml / CLI — not implemented in this repo |
Conclusion: You do not need an external AgentRust server to run and manage what exists today. Operational management is gateway API + dashboard + Postgres/Redis. External “control plane” is a tier/commercial concept, not a second application in this repository.
5. Agent development support
Yes. The SDK is intended for integration during agent development and at runtime.
Integration patterns
@harness— Wrap any Python callable; auto-detects framework from installed packages (_detect_frameworkindecorator.py: langgraph, crewai, langchain, autogen, llama_index → label, elseREST).- Explicit validate —
AgentTrustClient.validate(...)withagent_id,framework, I/O,tools_called,latency_ms,tokens, optionalparent_envelope_id(Enterprise trust chain). - Framework adapters — LangGraph node, CrewAI callback (Team tier, tier check at construction).
- Gateway
Frameworkenum — Accepts known framework strings on validate requests. - OSS path — Development without API keys: local schema validation only.
- Golden tests — YAML suites under
gateway/config/golden_tests/for regression-style checks (e.g. payment agent status/transaction_id rules).
Model of integration
This is post-execution governance: the agent runs first; output (and tool metadata) is sent to the gateway for scoring and decision. It does not replace LangGraph, CrewAI, or other orchestration frameworks.
6. Evolving into an agent certification harness
There is no route, model, or service named “certification” in the gateway today. Certification would compose existing primitives plus new workflow APIs.
6.1 Building blocks already in code
| Building block | Location | Certification-like behavior |
|---|---|---|
| Golden test engine | engines/golden_test_engine.py + config/golden_tests/ | Pass/fail rules on output fields |
| Validation engine | engines/validation_engine.py | Multi-check scorecard |
| Decision engine | engines/decision_engine.py | Approve / block / escalate / etc. |
| Reliability API | routes/agents.py, reliability_service.py | Historical pass rates per agent |
| Audit trail | AuditStore, /v1/audit/* | Evidence for audits |
| Review queue | services/review_queue.py | Human attestation |
| LLM judge (async) | Judge worker; judge_backend in settings | Slow-path qualitative score |
| Trust chain | trust_chain_service | Multi-agent linkage |
| Gateway tests | tests/test_phase2.py, test_phase4.py, test_phase5.py | Pipeline regression |
6.2 Recommended extensions (not in repo — grounded in extension points)
- Certification run API — e.g.
POST /v1/certify/runacceptingagent_id,framework, golden suite id, batch inputs; return aggregate pass rate and envelope IDs by reusing validate pipeline in a loop. - Certification record — Postgres entity:
certification_id,agent_id,framework,policy_version, golden version, aggregate confidence, outcome,expires_at; link to auditenvelope_idlist. - Agent certification status — Extend
/v1/agents/{agent_id}/reliabilityor add/v1/agents/{agent_id}/certification. - CI harness mode — CLI or
@harness(certify=True)running golden YAML from repo; fail CI onblockor below confidence threshold. - Framework profiles — Map
Frameworkenum → required checks / policy weights in policy YAML. - Human-in-the-loop certification — Review queue resolution flips certification from
pendingtoapproved. - Certification KPIs — Aggregate pass rate, mean confidence, block rate by framework via analytics queries on audit store.
7. Integrating new agent frameworks
7.1 Minimal integration (works today)
- Pass
frameworkonPOST /v1/runtime/validate(string aligned withFrameworkenum or useCustom/REST). - Use
@harness(framework="MyFramework")orclient.validate(..., framework="..."). - Add golden tests:
gateway/config/golden_tests/my_agent.yamlwithagent_id_patternand matchers (seepayment_agent.yaml). - No adapter required if the agent sends structured
outputdict and optionaltools_called.
7.2 SDK auto-detection
Extend _detect_framework() in agentrust_sdk/decorator.py:
for name, label in [
("langgraph", "LangGraph"),
("crewai", "CrewAI"),
("langchain", "LangChain"),
("autogen", "AutoGen"),
("llama_index", "LlamaIndex"),
# ("new_pkg", "NewFramework"),
]:7.3 First-class framework support
| Step | File(s) | Action |
|---|---|---|
| 1 | gateway/models/envelope.py | Add member to Framework enum |
| 2 | agentrust_sdk/adapters/ | New adapter module (mirror crewai.py / langgraph.py) |
| 3 | agentrust_sdk/tiers.py | Optional Capability.*_ADAPTER + min tier |
| 4 | agentrust_sdk/pyproject.toml | Optional [project.optional-dependencies] |
| 5 | gateway/config/golden_tests/ | Framework- or agent-specific suites |
| 6 | Tests | Adapter + validate integration tests |
7.4 Policy and risk by framework
Policy routes accept a framework string; extend policy YAML under gateway/config/ for framework-specific tool allowlists or risk weights without changing core engines.
7.5 Tier gating
Follow AgentTrustCallback / LangGraph adapter pattern: _check_adapter_tier() before exposing adapter classes (adapters/crewai.py).
8. Metrics to track
Derived from the validate pipeline and stored fields. Use these for dashboards, SLOs, and certification KPIs.
| Metric | Source |
|---|---|
| Validate latency (ms) | ValidateResponse.latency_ms (runtime.py) |
| Per-check scores | ValidationScores on envelope |
| Final confidence | ValidationEngine / ConfidenceEngine → final_confidence |
| Risk tier | RiskTier on envelope |
| Decision outcome | DecisionOutcome |
| Historical reliability | reliability_service (Redis + audit) |
| Judge score (async) | validation.judge_score when worker completes |
| Review queue depth | /v1/review |
| Audit chain integrity | GET /v1/audit/chain/verify |
| Golden test contribution | Golden engine weights in validation scores |
| Block / escalate rate | Aggregate from audit store by agent_id, framework |
| Retention archived count | Retention loop logs in main.py |
Suggested operational SLOs (to define against your deployment)
| SLO | Baseline from code |
|---|---|
| Fast-path validate p99 | Engine target <20ms (ValidationEngine docstring); measure latency_ms in production |
| Audit write success | Step 6 in validate pipeline must succeed for envelope persistence |
| Judge queue lag | Redis worker; monitor time from enqueue to judge_score populated |
| Gateway availability | /v1/health |
9. Repository layout
agentrust/
├── agentrust-edge/
│ ├── gateway/ # FastAPI governance runtime
│ │ ├── routes/ # runtime, audit, review, policy, agents, …
│ │ ├── engines/ # validation, confidence, decision, risk, golden, …
│ │ ├── services/ # audit_store, job_queue, review_queue, …
│ │ └── config/ # golden_tests, policy packs, weights
│ ├── dashboard/ # React UI (Vite)
│ └── docker-compose.yml
├── agentrust_sdk/ # Python harness, client, adapters, CLI
└── k8s/agentrust-edge/ # Kubernetes manifests10. Explicit gaps (not in repo)
The following are not implemented as runnable code in this repository:
- Separate multi-tenant SaaS control plane service
- Working policy sync / policy push to remote server (CLI stubs only)
- Dedicated certification API or certification badge storage
- Non-Python SDKs (only Python client in tree)
- Server-side enforcement of dashboard roles (localStorage only in UI)
When planning metrics or compliance narratives, distinguish implemented behavior (gateway + SDK + compose/k8s) from tier/marketing capabilities declared in tiers.py and CLI help text.
Appendix — Key file index
| Topic | Path |
|---|---|
| Validate pipeline | agentrust-edge/gateway/routes/runtime.py |
| Validation engine | agentrust-edge/gateway/engines/validation_engine.py |
| Confidence engine | agentrust-edge/gateway/engines/confidence_engine.py |
| Envelope models | agentrust-edge/gateway/models/envelope.py |
| Gateway app | agentrust-edge/gateway/main.py |
| Audit API | agentrust-edge/gateway/routes/audit.py |
| Docker stack | agentrust-edge/docker-compose.yml |
| SDK client | agentrust_sdk/agentrust_sdk/client.py |
| Harness decorator | agentrust_sdk/agentrust_sdk/decorator.py |
| Tiers / capabilities | agentrust_sdk/agentrust_sdk/tiers.py |
| CLI | agentrust_sdk/agentrust_sdk/cli.py |
| Golden test example | agentrust-edge/gateway/config/golden_tests/payment_agent.yaml |
| Dashboard routes | agentrust-edge/dashboard/src/App.tsx |