{ "components": { "schemas": { "Action": { "description": "What the agent did, or what ground truth says it should have done.\n\nESCALATE is only ever an *agent* action. Ground truth is always APPROVE or REJECT,\nbecause every synthetic invoice carries a deterministic correct answer.", "enum": [ "APPROVE", "REJECT", "ESCALATE" ], "title": "Action", "type": "string" }, "AgentContextOut": { "description": "Mirrors `shared.contracts.AgentContext` field-for-field.", "properties": { "current_limit": { "title": "Current Limit", "type": "integer" }, "decisions_since_clawback": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "title": "Decisions Since Clawback" }, "decisions_since_last_change": { "title": "Decisions Since Last Change", "type": "integer" }, "state": { "$ref": "#/components/schemas/AgentState" } }, "required": [ "current_limit", "decisions_since_last_change", "decisions_since_clawback", "state" ], "title": "AgentContextOut", "type": "object" }, "AgentOpinionOut": { "description": "Mirrors `shared.contracts.AgentOpinion` field-for-field.", "properties": { "agent_name": { "title": "Agent Name", "type": "string" }, "concerns": { "items": { "type": "string" }, "title": "Concerns", "type": "array" }, "confidence": { "title": "Confidence", "type": "number" }, "reasoning": { "title": "Reasoning", "type": "string" }, "verdict": { "$ref": "#/components/schemas/OpinionVerdict" } }, "required": [ "agent_name", "verdict", "reasoning", "concerns", "confidence" ], "title": "AgentOpinionOut", "type": "object" }, "AgentOut": { "description": "A governed agent. Backend-local resource \u2014 no `shared/` equivalent.\n\n`current_rung`/`current_limit` are always kept in sync with\n`shared.constants.rung_of`/`limit_of` (the invariant `TrustEvaluation`\ndocuments applies here too, since this is the same pair of numbers).", "properties": { "context": { "$ref": "#/components/schemas/AgentContextOut" }, "current_limit": { "title": "Current Limit", "type": "integer" }, "current_rung": { "title": "Current Rung", "type": "integer" }, "id": { "title": "Id", "type": "string" }, "name": { "title": "Name", "type": "string" }, "state": { "$ref": "#/components/schemas/AgentState" } }, "required": [ "id", "name", "current_limit", "current_rung", "state", "context" ], "title": "AgentOut", "type": "object" }, "AgentState": { "enum": [ "probation", "active", "restricted", "suspended" ], "title": "AgentState", "type": "string" }, "AssistantChatRequest": { "description": "`agent_id` absent (or `null`) is the general scope; present, it is the\nagent-scoped conversation \u2014 see `app/api/v1/assistant.py` for what each\nscope fetches.\n\n`page` is the route the user is looking at (e.g. `/approvals`,\n`/agents/agent-01`). It only selects which page guide the assistant reads\n(`app/services/page_guides.py`); the string itself never reaches the model,\nand an unknown route falls back to the system overview alone.", "properties": { "agent_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Agent Id" }, "messages": { "items": { "$ref": "#/components/schemas/AssistantMessage" }, "minItems": 1, "title": "Messages", "type": "array" }, "page": { "anyOf": [ { "maxLength": 200, "type": "string" }, { "type": "null" } ], "title": "Page" } }, "required": [ "messages" ], "title": "AssistantChatRequest", "type": "object" }, "AssistantChatResponse": { "properties": { "reply": { "title": "Reply", "type": "string" }, "sources": { "items": { "$ref": "#/components/schemas/AssistantSource" }, "title": "Sources", "type": "array" } }, "required": [ "reply", "sources" ], "title": "AssistantChatResponse", "type": "object" }, "AssistantMessage": { "properties": { "content": { "minLength": 1, "title": "Content", "type": "string" }, "role": { "enum": [ "user", "assistant" ], "title": "Role", "type": "string" } }, "required": [ "role", "content" ], "title": "AssistantMessage", "type": "object" }, "AssistantSource": { "description": "One citation: a guide the reply was grounded in. `doc` is `\"Page guide\"`\nand `section` is that guide's title (e.g. `\"Approvals\"`) \u2014 see\n`app/services/page_guides.py`.", "properties": { "doc": { "title": "Doc", "type": "string" }, "section": { "title": "Section", "type": "string" } }, "required": [ "doc", "section" ], "title": "AssistantSource", "type": "object" }, "AuditLogEntryOut": { "description": "One hash-chained row. `prev_hash`/`hash` make tampering with history\ndetectable \u2014 see docs/lanes/vp.md: \"sha256(prev_hash +\ncanonical_json(payload))\". Read-only; nothing in this API ever mutates\nan existing row.", "properties": { "actor": { "title": "Actor", "type": "string" }, "actor_type": { "title": "Actor Type", "type": "string" }, "entity_id": { "title": "Entity Id", "type": "string" }, "entity_type": { "title": "Entity Type", "type": "string" }, "event_type": { "title": "Event Type", "type": "string" }, "hash": { "title": "Hash", "type": "string" }, "id": { "title": "Id", "type": "string" }, "payload": { "additionalProperties": true, "title": "Payload", "type": "object" }, "prev_hash": { "title": "Prev Hash", "type": "string" }, "ts": { "format": "date-time", "title": "Ts", "type": "string" } }, "required": [ "id", "ts", "actor", "actor_type", "event_type", "entity_type", "entity_id", "payload", "prev_hash", "hash" ], "title": "AuditLogEntryOut", "type": "object" }, "AuditLogPage": { "description": "`GET /api/v1/audit-log`'s response: the usual pagination envelope,\nplus a chain-verification result computed fresh on every call \u2014 this is\nwhat makes tamper-evidence demonstrable on screen rather than claimed in\na docstring (docs/lanes/vp.md).\n\n`chain_verified_scope` says exactly what `chain_valid` covers: `\"full\"`\nwhen every row in `audit_log` was recomputed from `GENESIS_HASH`,\n`\"page\"` if the table ever grows large enough that a full recompute on\nevery request stops being cheap and this endpoint falls back to\nverifying only the returned page \u2014 never silently verifying less than\nit claims.", "properties": { "chain_valid": { "title": "Chain Valid", "type": "boolean" }, "chain_verified_scope": { "enum": [ "full", "page" ], "title": "Chain Verified Scope", "type": "string" }, "items": { "items": { "$ref": "#/components/schemas/AuditLogEntryOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size", "chain_valid", "chain_verified_scope" ], "title": "AuditLogPage", "type": "object" }, "AuditSampleOut": { "description": "Mirrors `shared.contracts.AuditSample` field-for-field.", "properties": { "agent_id": { "title": "Agent Id", "type": "string" }, "decision_id": { "title": "Decision Id", "type": "string" }, "reviewed_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Reviewed At" }, "reviewer": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Reviewer" }, "reviewer_action": { "anyOf": [ { "$ref": "#/components/schemas/Action" }, { "type": "null" } ] }, "sample_id": { "title": "Sample Id", "type": "string" }, "sampled_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Sampled At" }, "verdict": { "anyOf": [ { "$ref": "#/components/schemas/ReviewVerdict" }, { "type": "null" } ] } }, "required": [ "sample_id", "decision_id", "agent_id", "sampled_at", "reviewed_at", "reviewer", "verdict", "reviewer_action" ], "title": "AuditSampleOut", "type": "object" }, "AuditSampleReview": { "description": "Request body for `POST /api/v1/audit-samples/{sample_id}/review`.\n\nOnly ADMIN or REVIEWER may call this (`app/deps.py`) \u2014 reviewing sampled\ndecisions is REVIEWER's actual job (ADR-0009); AUDITOR stays read-only.", "properties": { "reason": { "description": "What the reviewer found, and why", "minLength": 1, "title": "Reason", "type": "string" }, "reviewer_action": { "$ref": "#/components/schemas/Action" }, "verdict": { "$ref": "#/components/schemas/ReviewVerdict" } }, "required": [ "verdict", "reviewer_action", "reason" ], "title": "AuditSampleReview", "type": "object" }, "DecisionCreate": { "description": "Request body for `POST /api/v1/decisions` \u2014 the simulator's ingest path.\n\nEvery field needed to construct a `DecisionRecord` (see\n`shared.contracts.DecisionRecord`), plus `reason`\n(cross-cutting rule: every state-changing endpoint requires one \u2014 here,\nwhy this decision is being submitted, e.g. which simulation run or\ninvoice-processing batch produced it).", "properties": { "action": { "$ref": "#/components/schemas/Action" }, "agent_id": { "title": "Agent Id", "type": "string" }, "amount": { "exclusiveMinimum": 0.0, "title": "Amount", "type": "integer" }, "ground_truth": { "$ref": "#/components/schemas/Action" }, "invoice_id": { "title": "Invoice Id", "type": "string" }, "reason": { "description": "Why this decision is being submitted", "minLength": 1, "title": "Reason", "type": "string" }, "recommended_action": { "anyOf": [ { "$ref": "#/components/schemas/Action" }, { "type": "null" } ], "description": "What the agent would have done had it been allowed to act. Only meaningful when `action` is ESCALATE: `shared.contracts.DecisionRecord.has_human_ruling` requires both this and a later `human_ruling` before the pair counts toward human agreement." } }, "required": [ "invoice_id", "amount", "action", "ground_truth", "agent_id", "reason" ], "title": "DecisionCreate", "type": "object" }, "DecisionRecordOut": { "description": "Mirrors `shared.contracts.DecisionRecord` field-for-field.", "properties": { "action": { "$ref": "#/components/schemas/Action" }, "agent_id": { "title": "Agent Id", "type": "string" }, "amount": { "title": "Amount", "type": "integer" }, "decided_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Decided At" }, "decision_id": { "title": "Decision Id", "type": "string" }, "ground_truth": { "$ref": "#/components/schemas/Action" }, "human_ruling": { "anyOf": [ { "$ref": "#/components/schemas/Action" }, { "type": "null" } ] }, "invoice_id": { "title": "Invoice Id", "type": "string" }, "recommended_action": { "anyOf": [ { "$ref": "#/components/schemas/Action" }, { "type": "null" } ] }, "sequence": { "title": "Sequence", "type": "integer" } }, "required": [ "decision_id", "sequence", "invoice_id", "amount", "action", "ground_truth", "agent_id", "decided_at", "recommended_action", "human_ruling" ], "title": "DecisionRecordOut", "type": "object" }, "DecisionRuling": { "description": "Request body for `POST /api/v1/decisions/{decision_id}/ruling`.\n\nRecords what a human decided about an escalated decision. Only ADMIN or\nREVIEWER may call this (`app/deps.py`) \u2014 ruling on an escalation is\nREVIEWER's job, the same reasoning as reviewing an audit sample\n(ADR-0009); AUDITOR stays read-only.\n\nA ruling is only half of the evidence: `human_agreement` compares it\nagainst the agent's own `recommended_action`, so a decision ingested\nwithout one can be ruled on but will not contribute to the trust score.", "properties": { "reason": { "description": "Why the human ruled this way", "minLength": 1, "title": "Reason", "type": "string" }, "ruling": { "$ref": "#/components/schemas/Action", "description": "The human's verdict: APPROVE or REJECT. Never ESCALATE." } }, "required": [ "ruling", "reason" ], "title": "DecisionRuling", "type": "object" }, "Direction": { "enum": [ "INCREASE", "HOLD", "CLAWBACK" ], "title": "Direction", "type": "string" }, "DriftResultOut": { "description": "Mirrors `shared.contracts.DriftResult` field-for-field.", "properties": { "baseline_accuracy": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Baseline Accuracy" }, "baseline_n": { "title": "Baseline N", "type": "integer" }, "critical_errors_in_window": { "title": "Critical Errors In Window", "type": "integer" }, "detected": { "title": "Detected", "type": "boolean" }, "drop_pp": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Drop Pp" }, "p_value": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "P Value" }, "recent_accuracy": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Recent Accuracy" }, "recent_n": { "title": "Recent N", "type": "integer" }, "severity": { "$ref": "#/components/schemas/DriftSeverity" }, "underpowered": { "title": "Underpowered", "type": "boolean" }, "z_statistic": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Z Statistic" } }, "required": [ "severity", "detected", "recent_accuracy", "baseline_accuracy", "drop_pp", "z_statistic", "p_value", "critical_errors_in_window", "recent_n", "baseline_n", "underpowered" ], "title": "DriftResultOut", "type": "object" }, "DriftSeverity": { "enum": [ "NONE", "WARNING", "CONFIRMED", "CRITICAL" ], "title": "DriftSeverity", "type": "string" }, "ErrorBody": { "description": "Every non-2xx response returns this shape as its JSON body.\n\n`code` is a short machine-readable slug (e.g. \"not_found\", \"forbidden\",\n\"validation_error\") for client branching; `message` is one sentence a human\nreads; `detail` carries whatever extra structure the specific failure needs\n(field errors, the resource id that was missing, etc.) and may be null.", "properties": { "code": { "title": "Code", "type": "string" }, "detail": { "anyOf": [ {}, { "type": "null" } ], "title": "Detail" }, "message": { "title": "Message", "type": "string" } }, "required": [ "code", "message" ], "title": "ErrorBody", "type": "object" }, "HTTPValidationError": { "properties": { "detail": { "items": { "$ref": "#/components/schemas/ValidationError" }, "title": "Detail", "type": "array" } }, "title": "HTTPValidationError", "type": "object" }, "HealthOut": { "properties": { "schema_version": { "title": "Schema Version", "type": "string" }, "status": { "title": "Status", "type": "string" } }, "required": [ "status", "schema_version" ], "title": "HealthOut", "type": "object" }, "OpinionVerdict": { "description": "A single governance agent's stance on a recommendation, before opinions are\ncombined into one Recommendation.", "enum": [ "CONCUR", "OBJECT", "ABSTAIN" ], "title": "OpinionVerdict", "type": "string" }, "Page_AgentOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/AgentOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[AgentOut]", "type": "object" }, "Page_AuditSampleOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/AuditSampleOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[AuditSampleOut]", "type": "object" }, "Page_DecisionRecordOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/DecisionRecordOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[DecisionRecordOut]", "type": "object" }, "Page_PolicyVersionOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/PolicyVersionOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[PolicyVersionOut]", "type": "object" }, "Page_RecommendationOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/RecommendationOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[RecommendationOut]", "type": "object" }, "Page_TrustEvaluationOut_": { "properties": { "items": { "items": { "$ref": "#/components/schemas/TrustEvaluationOut" }, "title": "Items", "type": "array" }, "page": { "description": "1-indexed page number", "minimum": 1.0, "title": "Page", "type": "integer" }, "page_size": { "description": "Items per page, as requested", "minimum": 1.0, "title": "Page Size", "type": "integer" }, "total": { "description": "Total matching records, independent of page size", "minimum": 0.0, "title": "Total", "type": "integer" } }, "required": [ "items", "total", "page", "page_size" ], "title": "Page[TrustEvaluationOut]", "type": "object" }, "PolicyVersionOut": { "description": "One row of an agent's append-only limit history.\n\ndocs/lanes/vp.md: \"`policy_versions` is append-only and every decision\nreferences one\" \u2014 this is what `GET /agents/{agent_id}/policy-versions`\nreturns, oldest-relevant invariant first: `previous_version_id` chains\neach row to the one it replaced, `None` only on an agent's very first\nversion.", "properties": { "agent_id": { "title": "Agent Id", "type": "string" }, "created_by": { "title": "Created By", "type": "string" }, "effective_from": { "format": "date-time", "title": "Effective From", "type": "string" }, "id": { "title": "Id", "type": "string" }, "limit": { "title": "Limit", "type": "integer" }, "previous_version_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Previous Version Id" }, "reason": { "title": "Reason", "type": "string" }, "rung": { "title": "Rung", "type": "integer" } }, "required": [ "id", "agent_id", "limit", "rung", "effective_from", "created_by", "reason", "previous_version_id" ], "title": "PolicyVersionOut", "type": "object" }, "ProportionResultOut": { "description": "Mirrors `shared.contracts.ProportionResult` field-for-field.", "properties": { "point": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Point" }, "successes": { "title": "Successes", "type": "integer" }, "trials": { "title": "Trials", "type": "integer" }, "wilson_lower": { "title": "Wilson Lower", "type": "number" }, "wilson_upper": { "title": "Wilson Upper", "type": "number" } }, "required": [ "successes", "trials", "point", "wilson_lower", "wilson_upper" ], "title": "ProportionResultOut", "type": "object" }, "RecommendationDecision": { "description": "Request body for both `POST .../approve` and `POST .../reject`.\n\n`reason` is mandatory on both \u2014 approving *and* rejecting are mutations,\nand the cross-cutting rule doesn't carve out an exception for the\n\"yes\" path. Only ADMIN may call either endpoint (see `app/deps.py`,\n`Role.ADMIN` docstring: \"Reviewer explicitly cannot approve\").", "properties": { "reason": { "description": "Why this decision was made", "minLength": 1, "title": "Reason", "type": "string" } }, "required": [ "reason" ], "title": "RecommendationDecision", "type": "object" }, "RecommendationOut": { "description": "Mirrors `shared.contracts.Recommendation` field-for-field.", "properties": { "agent_id": { "title": "Agent Id", "type": "string" }, "clamped": { "title": "Clamped", "type": "boolean" }, "clamped_from": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "title": "Clamped From" }, "confidence": { "title": "Confidence", "type": "number" }, "direction": { "$ref": "#/components/schemas/Direction" }, "generated_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Generated At" }, "governance_mode": { "title": "Governance Mode", "type": "string" }, "has_dissent": { "title": "Has Dissent", "type": "boolean" }, "opinions": { "items": { "$ref": "#/components/schemas/AgentOpinionOut" }, "title": "Opinions", "type": "array" }, "proposed_limit": { "title": "Proposed Limit", "type": "integer" }, "proposed_rung": { "title": "Proposed Rung", "type": "integer" }, "rationale": { "title": "Rationale", "type": "string" }, "reason_codes": { "items": { "type": "string" }, "title": "Reason Codes", "type": "array" }, "recommendation_id": { "title": "Recommendation Id", "type": "string" }, "schema_version": { "title": "Schema Version", "type": "string" }, "status": { "$ref": "#/components/schemas/RecommendationStatus" }, "trust_evaluation_ref": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Trust Evaluation Ref" } }, "required": [ "recommendation_id", "agent_id", "schema_version", "direction", "proposed_limit", "proposed_rung", "rationale", "opinions", "has_dissent", "confidence", "governance_mode", "status", "trust_evaluation_ref", "generated_at", "clamped", "clamped_from" ], "title": "RecommendationOut", "type": "object" }, "RecommendationStatus": { "description": "Lifecycle of a governance recommendation, from proposed to resolved.", "enum": [ "PENDING", "APPROVED", "REJECTED", "SUPERSEDED" ], "title": "RecommendationStatus", "type": "string" }, "ReviewVerdict": { "description": "A human reviewer's verdict on a sampled decision, from comparing the agent's\naction against what the reviewer determines was correct.", "enum": [ "AGREED", "DISAGREED", "INCONCLUSIVE" ], "title": "ReviewVerdict", "type": "string" }, "RunStatus": { "enum": [ "pending", "running", "completed", "failed" ], "title": "RunStatus", "type": "string" }, "ScoreComponentOut": { "description": "Mirrors `shared.contracts.ScoreComponent` field-for-field.", "properties": { "available": { "title": "Available", "type": "boolean" }, "effective_weight": { "title": "Effective Weight", "type": "number" }, "name": { "title": "Name", "type": "string" }, "nominal_weight": { "title": "Nominal Weight", "type": "number" }, "value": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Value" } }, "required": [ "name", "value", "nominal_weight", "effective_weight", "available" ], "title": "ScoreComponentOut", "type": "object" }, "SimulationPhase": { "description": "Mirrors `simulator.simulator.models.SimulationPhase` by value, not by\nimport \u2014 `simulator/` is a lane the backend must not depend on\n(docs/lanes/vp.md: \"Do not write code outside backend/\"; the simulator\nsubmits to this API, this API does not reach into the simulator).", "enum": [ "good", "degraded", "recovery" ], "title": "SimulationPhase", "type": "string" }, "SimulationRunCreate": { "description": "Request body for `POST /api/v1/simulation/runs`.\n\nOnly ADMIN may start a run (`app/deps.py`) \u2014 this is an operational\naction, not a governance authorization, but it still changes state\n(kicks off a batch of decisions), so `reason` is still required.", "properties": { "agent_id": { "title": "Agent Id", "type": "string" }, "invoice_count": { "exclusiveMinimum": 0.0, "maximum": 10000.0, "title": "Invoice Count", "type": "integer" }, "phase": { "$ref": "#/components/schemas/SimulationPhase" }, "reason": { "description": "Why this run is being started", "minLength": 1, "title": "Reason", "type": "string" }, "seed": { "default": 42, "title": "Seed", "type": "integer" } }, "required": [ "phase", "agent_id", "invoice_count", "reason" ], "title": "SimulationRunCreate", "type": "object" }, "SimulationRunOut": { "description": "The status/result of one simulation run.", "properties": { "accuracy": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Accuracy" }, "agent_id": { "title": "Agent Id", "type": "string" }, "clawback_applied": { "default": false, "title": "Clawback Applied", "type": "boolean" }, "clawback_limit": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "title": "Clawback Limit" }, "completed_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Completed At" }, "decisions_submitted": { "title": "Decisions Submitted", "type": "integer" }, "error_message": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Error Message" }, "invoice_count": { "title": "Invoice Count", "type": "integer" }, "phase": { "$ref": "#/components/schemas/SimulationPhase" }, "run_id": { "title": "Run Id", "type": "string" }, "seed": { "title": "Seed", "type": "integer" }, "started_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Started At" }, "status": { "$ref": "#/components/schemas/RunStatus" }, "wilson_lower_bound": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "title": "Wilson Lower Bound" } }, "required": [ "run_id", "status", "phase", "agent_id", "invoice_count", "seed", "started_at", "completed_at", "decisions_submitted", "accuracy", "wilson_lower_bound" ], "title": "SimulationRunOut", "type": "object" }, "TrustEvaluationOut": { "description": "Mirrors `shared.contracts.TrustEvaluation` field-for-field, plus `id`\n(see module docstring \u2014 this is the one backend-minted addition).", "properties": { "accuracy": { "anyOf": [ { "$ref": "#/components/schemas/ProportionResultOut" }, { "type": "null" } ] }, "acted_decisions": { "title": "Acted Decisions", "type": "integer" }, "agent_id": { "title": "Agent Id", "type": "string" }, "components": { "items": { "$ref": "#/components/schemas/ScoreComponentOut" }, "title": "Components", "type": "array" }, "config_fingerprint": { "title": "Config Fingerprint", "type": "string" }, "critical_error_rate": { "title": "Critical Error Rate", "type": "number" }, "critical_errors": { "title": "Critical Errors", "type": "integer" }, "critical_errors_in_recent_window": { "title": "Critical Errors In Recent Window", "type": "integer" }, "current_limit": { "title": "Current Limit", "type": "integer" }, "current_rung": { "title": "Current Rung", "type": "integer" }, "decisions_since_last_change": { "title": "Decisions Since Last Change", "type": "integer" }, "direction": { "$ref": "#/components/schemas/Direction" }, "drift": { "$ref": "#/components/schemas/DriftResultOut" }, "eligible_for_increase": { "title": "Eligible For Increase", "type": "boolean" }, "escalated_decisions": { "title": "Escalated Decisions", "type": "integer" }, "evaluated_at": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "title": "Evaluated At" }, "human_agreement": { "anyOf": [ { "$ref": "#/components/schemas/ProportionResultOut" }, { "type": "null" } ] }, "id": { "title": "Id", "type": "string" }, "noncritical_errors": { "title": "Noncritical Errors", "type": "integer" }, "reason_codes": { "items": { "type": "string" }, "title": "Reason Codes", "type": "array" }, "recommended_limit": { "title": "Recommended Limit", "type": "integer" }, "recommended_rung": { "title": "Recommended Rung", "type": "integer" }, "ruled_escalations": { "title": "Ruled Escalations", "type": "integer" }, "schema_version": { "title": "Schema Version", "type": "string" }, "state": { "$ref": "#/components/schemas/AgentState" }, "thresholds": { "$ref": "#/components/schemas/TrustThresholdsOut" }, "total_decisions": { "title": "Total Decisions", "type": "integer" }, "trust_score": { "title": "Trust Score", "type": "number" }, "utilization": { "anyOf": [ { "$ref": "#/components/schemas/ProportionResultOut" }, { "type": "null" } ] }, "weights_renormalised": { "title": "Weights Renormalised", "type": "boolean" } }, "required": [ "id", "agent_id", "schema_version", "total_decisions", "acted_decisions", "escalated_decisions", "ruled_escalations", "accuracy", "human_agreement", "utilization", "critical_errors", "noncritical_errors", "critical_error_rate", "critical_errors_in_recent_window", "trust_score", "components", "weights_renormalised", "drift", "current_limit", "recommended_limit", "current_rung", "recommended_rung", "direction", "state", "eligible_for_increase", "decisions_since_last_change", "reason_codes", "evaluated_at", "config_fingerprint" ], "title": "TrustEvaluationOut", "type": "object" }, "TrustThresholdsOut": { "description": "The trust engine's own gate values, sent with the evaluation they\nproduced.\n\nHere because a client that draws a threshold has to get it from somewhere,\nand the only safe somewhere is the engine that applies it.\n`HorizontalThresholdGauge.tsx` used to mark a \"safety threshold\" at a\nhardcoded 85% accuracy and colour the bar red or green against it \u2014 a\nnumber that appears **nowhere** in `trust/` or `backend/`. The engine has\nno accuracy threshold at all: promotion gates on the *trust score*\n(`MIN_TRUST_SCORE_FOR_INCREASE`), and the accuracy axis is policed by drift\ndetection, which compares recent accuracy against the agent's own baseline\nrather than against any fixed line. So the dashboard was not merely\nduplicating a rule in the wrong place; it was displaying one the system\ndoes not have.\n\nThese are configuration, not per-agent evidence, so they are identical on\nevery evaluation. They ride along with it anyway because that is the\nevaluation these exact values produced \u2014 a client reading a historical row\ngets the thresholds that applied then, not today's.", "properties": { "critical_error_window": { "title": "Critical Error Window", "type": "integer" }, "drift_accuracy_drop_pp": { "title": "Drift Accuracy Drop Pp", "type": "number" }, "min_sample_for_increase": { "title": "Min Sample For Increase", "type": "integer" }, "min_trust_score_for_increase": { "title": "Min Trust Score For Increase", "type": "number" }, "recent_window": { "title": "Recent Window", "type": "integer" } }, "required": [ "min_sample_for_increase", "min_trust_score_for_increase", "drift_accuracy_drop_pp", "critical_error_window", "recent_window" ], "title": "TrustThresholdsOut", "type": "object" }, "ValidationError": { "properties": { "ctx": { "title": "Context", "type": "object" }, "input": { "title": "Input" }, "loc": { "items": { "anyOf": [ { "type": "string" }, { "type": "integer" } ] }, "title": "Location", "type": "array" }, "msg": { "title": "Message", "type": "string" }, "type": { "title": "Error Type", "type": "string" } }, "required": [ "loc", "msg", "type" ], "title": "ValidationError", "type": "object" } } }, "info": { "description": "The integration point for all four lanes: the Policy Engine, persistence and audit, the HTTP contract, and the hard ceiling. See docs/SYSTEM-EXPLAINED.md for the full design.", "title": "Adaptive AI Governance Platform \u2014 Backend", "version": "1.1" }, "openapi": "3.1.0", "paths": { "/api/v1/agents": { "get": { "description": "List every governed agent, ordered by id.", "operationId": "list_agents_api_v1_agents_get", "parameters": [ { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_AgentOut_" } } }, "description": "Successful Response" }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Agents", "tags": [ "agents" ] } }, "/api/v1/agents/{agent_id}": { "get": { "description": "Fetch one agent by id, including its current `AgentContext`.", "operationId": "get_agent_api_v1_agents__agent_id__get", "parameters": [ { "in": "path", "name": "agent_id", "required": true, "schema": { "title": "Agent Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AgentOut" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Get Agent", "tags": [ "agents" ] } }, "/api/v1/agents/{agent_id}/policy-versions": { "get": { "description": "The agent's append-only limit history, newest first.\n\n`previous_version_id` always chains to a row that exists, except the\nvery first version for an agent.", "operationId": "list_policy_versions_api_v1_agents__agent_id__policy_versions_get", "parameters": [ { "in": "path", "name": "agent_id", "required": true, "schema": { "title": "Agent Id", "type": "string" } }, { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_PolicyVersionOut_" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Policy Versions", "tags": [ "agents" ] } }, "/api/v1/agents/{agent_id}/recommendations": { "post": { "description": "Generate a fresh governance recommendation for `agent_id`: recompute\nits `TrustEvaluation` from persisted decisions, run the governance panel\nover it (`GOVERNANCE_MODE`, default `stub`), clamp the panel's proposal to\nwhat the evidence actually supports, and persist trust evaluation,\nrecommendation, and audit entry \u2014 all in this one request's transaction\n(`app.deps.get_session`; see `app/services/governance.py`).", "operationId": "create_recommendation_api_v1_agents__agent_id__recommendations_post", "parameters": [ { "in": "path", "name": "agent_id", "required": true, "schema": { "title": "Agent Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "201": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" }, "503": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "A downstream dependency (e.g. governance) could not serve this request." } }, "summary": "Create Recommendation", "tags": [ "agents" ] } }, "/api/v1/agents/{agent_id}/trust": { "get": { "description": "Evaluate `agent_id`'s real persisted decision history with the real\ntrust engine, persist the result, and return it. An agent with zero\ndecisions still gets a valid `TrustEvaluation` back \u2014 `trust_engine.evaluate`\nis designed to handle an empty history, not to be called only once one\nexists (see `app/services/trust.py`).", "operationId": "get_current_trust_api_v1_agents__agent_id__trust_get", "parameters": [ { "in": "path", "name": "agent_id", "required": true, "schema": { "title": "Agent Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TrustEvaluationOut" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Get Current Trust", "tags": [ "agents" ] } }, "/api/v1/agents/{agent_id}/trust/history": { "get": { "description": "Every `TrustEvaluation` ever persisted for this agent, newest first \u2014\nwhat the dashboard's trust-over-time chart is built from.", "operationId": "list_trust_history_api_v1_agents__agent_id__trust_history_get", "parameters": [ { "in": "path", "name": "agent_id", "required": true, "schema": { "title": "Agent Id", "type": "string" } }, { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_TrustEvaluationOut_" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Trust History", "tags": [ "agents" ] } }, "/api/v1/assistant/chat": { "post": { "description": "Answer one question, in the requested scope. `agent_id` absent is the\ngeneral scope; present, it must name a real agent (404 otherwise) and the\nreply is built from that agent's evidence alone (`app/services/assistant.py`).\n\nNo role restriction \u2014 this is a read endpoint over data every stub role can\nalready see elsewhere (agents, decisions, recommendations, audit log), the\nsame reasoning `GET /agents/{id}` itself carries no `require_role`.", "operationId": "chat_api_v1_assistant_chat_post", "parameters": [ { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AssistantChatRequest" } } }, "required": true }, "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AssistantChatResponse" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" }, "503": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "A downstream dependency (e.g. governance) could not serve this request." } }, "summary": "Chat", "tags": [ "assistant" ] } }, "/api/v1/audit-log": { "get": { "description": "The complete hash-chained event log, newest first. Read-only \u2014\nnothing in this API ever mutates an existing row (that's the point).\n\nRecomputes the whole chain from `GENESIS_HASH` on every call, in\n`log_seq` order \u2014\n`audit_log` is small enough in this system for that to be cheap \u2014 and\nreports the result as `chain_valid`/`chain_verified_scope` rather than\njust asserting immutability in a docstring. If the table ever grows\nlarge enough that a full recompute stops being cheap, this falls back\nto verifying only the returned page and says so via\n`chain_verified_scope`, instead of silently verifying less than it\nclaims.", "operationId": "list_audit_log_api_v1_audit_log_get", "parameters": [ { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuditLogPage" } } }, "description": "Successful Response" }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Audit Log", "tags": [ "audit" ] } }, "/api/v1/audit-samples": { "get": { "description": "List sampled decisions pulled for human review, newest first.\n\nReads the real `audit_samples` table. Rows are written by\n`app.services.audit_sampling.sample_if_selected` as decisions are\nrecorded, at `sampling_rate_of(agent.current_rung)` \u2014 as they happen, not\non a schedule, so the queue reflects the agent's current rung rather than\nwhatever it was when a batch job last ran.\n\n`?pending=true` is the review-queue view: samples nobody has ruled on yet.\n`?agent_id=` narrows to one agent, which is what an agent detail page wants.", "operationId": "list_audit_samples_api_v1_audit_samples_get", "parameters": [ { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "query", "name": "pending", "required": false, "schema": { "default": false, "title": "Pending", "type": "boolean" } }, { "in": "query", "name": "agent_id", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Agent Id" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_AuditSampleOut_" } } }, "description": "Successful Response" }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Audit Samples", "tags": [ "audit" ] } }, "/api/v1/audit-samples/{sample_id}/review": { "post": { "description": "Record a human review of one sampled decision. REVIEWER or ADMIN only.\n\nWrites `reviewed_at`/`reviewer`/`verdict`/`reviewer_action` onto the\n`audit_samples` row and appends a hash-chained audit entry. A `DISAGREED`\nverdict carries `SAMPLE_REVIEW_DISAGREEMENT` (shared/reason_codes.py) on\nthat entry: a reviewer contradicting the agent is itself evidence, and it\nis the only place in the system that code is produced.\n\nReviews once. A second review is a 409 rather than a silent overwrite \u2014\nthe same reasoning as a decision ruling: a review is evidence that may\nalready have been counted, and rewriting it would change history under\nwhatever cited it.\n\nWhat this deliberately does NOT do: overwrite the decision's recorded\nground truth. ADR-0009 describes reviewed samples eventually *becoming*\nthe ground-truth source once the system runs past the simulator, but that\nsame ADR flags the contract gap it depends on \u2014 `TrustEvaluation` has no\nfield distinguishing accuracy built from full ground truth from accuracy\nbuilt from a sampled slice \u2014 as deferred, not decided. Silently\nsubstituting one for the other here would corrupt the simulator's\ndeterministic ground truth and break the arc's reproducibility, to\nimplement a contract change nobody has agreed.", "operationId": "review_audit_sample_api_v1_audit_samples__sample_id__review_post", "parameters": [ { "in": "path", "name": "sample_id", "required": true, "schema": { "title": "Sample Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuditSampleReview" } } }, "required": true }, "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuditSampleOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "409": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The resource is not in a state this action applies to." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Review Audit Sample", "tags": [ "audit" ] } }, "/api/v1/decisions": { "get": { "description": "List decisions, newest first.\n\n`?agent_id=` filters in SQL. The agent detail page used to fetch the\nnewest 50 decisions across every agent and filter them in the browser,\nwhich silently showed nothing at all once another agent's run pushed it\noff the first page \u2014 a blank panel that looked like \"no decisions\" rather\nthan \"wrong query\".", "operationId": "list_decisions_api_v1_decisions_get", "parameters": [ { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "query", "name": "agent_id", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Agent Id" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_DecisionRecordOut_" } } }, "description": "Successful Response" }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Decisions", "tags": [ "decisions" ] }, "post": { "description": "Ingest one decision from the simulator (or, eventually, a real agent).\n\nValidates the agent exists and has a policy version on record, evaluates\nthe invoice against that policy with the real Policy Engine\n(`app.policy.engine.evaluate_decision`), and \u2014 in one transaction \u2014\npersists the invoice (if new), the decision (referencing the exact\npolicy version in force), and a hash-chained `audit_log` entry\n(docs/lanes/vp.md). `within_limit` is recorded on the decision row\nverbatim from the Policy Engine's own output; the Policy Engine's reason\ncode is recorded on the audit entry, never recomputed later.", "operationId": "create_decision_api_v1_decisions_post", "parameters": [ { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionCreate" } } }, "required": true }, "responses": { "201": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionRecordOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Create Decision", "tags": [ "decisions" ] } }, "/api/v1/decisions/{decision_id}": { "get": { "description": "Fetch one decision by id.", "operationId": "get_decision_api_v1_decisions__decision_id__get", "parameters": [ { "in": "path", "name": "decision_id", "required": true, "schema": { "title": "Decision Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionRecordOut" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Get Decision", "tags": [ "decisions" ] } }, "/api/v1/decisions/{decision_id}/ruling": { "post": { "description": "Record a human's ruling on one escalated decision. REVIEWER or ADMIN only.\n\nThis is the write path for `decisions.human_ruling`, and the only one:\n`POST /api/v1/decisions` deliberately leaves it null, because an agent\ncannot rule on its own escalation.\n\nEscalating is the agent deferring to a human, so a ruling is the answer to\nthat deferral \u2014 which is why only an ESCALATE decision can be ruled on, and\nwhy the ruling itself must be APPROVE or REJECT. `shared.contracts.\nDecisionRecord.human_agreed` then compares the ruling against the agent's\nown `recommended_action`, and `trust_engine.stats.rates.human_agreement`\naggregates those comparisons over ruled escalations only.\n\nA decision ingested without a `recommended_action` can still be ruled on \u2014\nthe ruling is a real fact worth recording \u2014 but the pair contributes\nnothing to human agreement, since there is no recommendation to compare\nagainst. `has_human_ruling` requires both halves.\n\nRules once. A second ruling is a 409 rather than a silent overwrite: the\naudit chain records what a human decided, and decisions already evaluated\nagainst it must not change underneath that evidence.", "operationId": "rule_on_decision_api_v1_decisions__decision_id__ruling_post", "parameters": [ { "in": "path", "name": "decision_id", "required": true, "schema": { "title": "Decision Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionRuling" } } }, "required": true }, "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionRecordOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "409": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The resource is not in a state this action applies to." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Rule On Decision", "tags": [ "decisions" ] } }, "/api/v1/health": { "get": { "description": "Always 200 while the process is up. No DB check yet \u2014 once\npersistence lands, this should also verify a connection round-trip and\nreturn 503 if the database is unreachable rather than lying about it.", "operationId": "health_api_v1_health_get", "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HealthOut" } } }, "description": "Successful Response" } }, "summary": "Health", "tags": [ "health" ] } }, "/api/v1/recommendations": { "get": { "description": "List recommendations, newest first.\n\n`?status=` is the approvals queue's tab filter \u2014 PENDING is the review\nqueue, APPROVED and REJECTED are history. Without it the dashboard's four\ntabs all rendered the same list: the frontend was already sending the\nparameter, and an endpoint that silently ignores a query parameter looks\nexactly like a broken filter to whoever is clicking it.\n\n`?agent_id=` narrows to one agent, which is what an agent detail page\nwants.", "operationId": "list_recommendations_api_v1_recommendations_get", "parameters": [ { "description": "1-indexed page number", "in": "query", "name": "page", "required": false, "schema": { "default": 1, "description": "1-indexed page number", "minimum": 1, "title": "Page", "type": "integer" } }, { "description": "Items per page", "in": "query", "name": "page_size", "required": false, "schema": { "default": 20, "description": "Items per page", "maximum": 200, "minimum": 1, "title": "Page Size", "type": "integer" } }, { "in": "query", "name": "status", "required": false, "schema": { "anyOf": [ { "$ref": "#/components/schemas/RecommendationStatus" }, { "type": "null" } ], "title": "Status" } }, { "in": "query", "name": "agent_id", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Agent Id" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page_RecommendationOut_" } } }, "description": "Successful Response" }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "List Recommendations", "tags": [ "recommendations" ] } }, "/api/v1/recommendations/{rec_id}": { "get": { "description": "Fetch one recommendation by id, including its full opinion panel.", "operationId": "get_recommendation_api_v1_recommendations__rec_id__get", "parameters": [ { "in": "path", "name": "rec_id", "required": true, "schema": { "title": "Rec Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationOut" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Get Recommendation", "tags": [ "recommendations" ] } }, "/api/v1/recommendations/{rec_id}/approve": { "post": { "description": "Authorize a pending recommendation. ADMIN only.\n\nWrites an `approvals` row (`decided_by`, `verdict=APPROVED`, `reason`,\n`decided_at`), flips `Recommendation.status` to `APPROVED`, and \u2014 only if\n`proposed_limit` actually differs from the agent's current limit \u2014 writes\nthe new `policy_versions` row that changes `agents.current_limit`/\n`current_rung` in the same transaction (docs/lanes/vp.md: \"Never update\nagents.current_limit without writing a policy_versions row in the same\ntransaction\"). Approving a HOLD recommendation (`proposed_limit` already\nequal to the current limit) is still recorded via the `approvals` row,\nbut writes no policy version \u2014 and so does not reset the cooldown clock\n`app/services/trust.py:agent_context` derives from the latest version's\n`effective_from`, which a no-op approval has no business touching.", "operationId": "approve_recommendation_api_v1_recommendations__rec_id__approve_post", "parameters": [ { "in": "path", "name": "rec_id", "required": true, "schema": { "title": "Rec Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationDecision" } } }, "required": true }, "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "409": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The resource is not in a state this action applies to." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Approve Recommendation", "tags": [ "recommendations" ] } }, "/api/v1/recommendations/{rec_id}/reject": { "post": { "description": "Reject a pending recommendation. ADMIN only, same as approve.\n\nWrites an `approvals` row with `verdict=REJECTED` and flips\n`Recommendation.status` to `REJECTED`. No policy version is written \u2014\nthe agent's limit does not change.", "operationId": "reject_recommendation_api_v1_recommendations__rec_id__reject_post", "parameters": [ { "in": "path", "name": "rec_id", "required": true, "schema": { "title": "Rec Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationDecision" } } }, "required": true }, "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecommendationOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "409": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The resource is not in a state this action applies to." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Reject Recommendation", "tags": [ "recommendations" ] } }, "/api/v1/simulation/runs": { "post": { "description": "Start a real simulation run.\n\nCreates the run row with `status=running`, then schedules\n`app.services.simulation.execute_simulation_run` as a `BackgroundTasks`\njob: it generates `invoice_count` synthetic invoices for `phase` from\n`seed`, runs a scripted agent over them, and submits every resulting\ndecision through the same ingest path `POST /api/v1/decisions` itself\nuses (`app.api.v1.decisions._create_decision`, called directly and\nin-process \u2014 no self-HTTP-call, same function either way, so this is\nnot a shortcut into the database).\n\nThe run row is committed here, explicitly, before the background task\nis scheduled \u2014 deliberately not left to `DbSessionDep`'s usual\ncommit-at-end-of-request \u2014 so the background task's own session is\nguaranteed to find the row already durable, regardless of exactly how\nFastAPI orders background-task execution relative to a dependency's\npost-`yield` teardown code.", "operationId": "start_simulation_run_api_v1_simulation_runs_post", "parameters": [ { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SimulationRunCreate" } } }, "required": true }, "responses": { "201": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SimulationRunOut" } } }, "description": "Successful Response" }, "403": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "The current role may not perform this action." }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Start Simulation Run", "tags": [ "simulation" ] } }, "/api/v1/simulation/runs/{run_id}": { "get": { "description": "Poll a run's status and, once complete, its summary accuracy/Wilson\nlower bound over the decisions it submitted. `decisions_submitted`\nupdates after every decision while the run is still in progress.", "operationId": "get_simulation_run_api_v1_simulation_runs__run_id__get", "parameters": [ { "in": "path", "name": "run_id", "required": true, "schema": { "title": "Run Id", "type": "string" } }, { "in": "header", "name": "X-User-Role", "required": false, "schema": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "X-User-Role" } } ], "responses": { "200": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SimulationRunOut" } } }, "description": "Successful Response" }, "404": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorBody" } } }, "description": "No resource with that id." }, "422": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } }, "description": "Validation Error" } }, "summary": "Get Simulation Run", "tags": [ "simulation" ] } } } }