A risk-based autonomy governance system for AI agent actions. Every action an agent proposes is scored across four independent risk dimensions and routed to one of three autonomy levels -- autonomous execution, user confirmation, or human review -- instead of the usual all-or-nothing choice between "let the agent do anything" and "a human approves every single step."
Live deployment: https://ps91-backend.onrender.com/docs (hosted on Render's free tier -- the first request after a period of inactivity can take ~30-60s to respond while the instance cold-starts; this is expected, not a bug)
Credentials: Username: admin | Password: X3Bsgz0dFHMN9eXYwqSTqovDwPUEFH8rPe-FL8t5vc4
A fully autonomous agent takes unnecessary risks on high-stakes actions. A fully gated agent requires human approval for trivial decisions and becomes a bottleneck that eliminates the value of automation. This engine scores every action's actual risk and routes it accordingly:
- A read-only query is low risk -> executes autonomously, no human in the loop.
- A single-record update is medium risk -> previewed to a human, executes only on confirmation.
- A bulk delete is high risk -> routed to a full human review queue before anything happens.
Untrusted action proposal
|
v
ActionBuilder (validates/normalizes the proposal)
|
v
RiskScorer (4 weighted dimensions, see below)
|
v
AutonomyMapper (risk score -> autonomous | confirm | full_review)
|
+--> autonomous --> ToolGateway executes immediately
|
+--> confirm --> ConfirmationService holds it; a human confirms/rejects via API
|
+--> full_review --> ReviewService holds it; a REVIEWER/ADMIN approves/rejects via API
|
v
AuditService (every decision recorded, in full, regardless of outcome)
| Dimension | Question it answers |
|---|---|
| Reversibility | Can this action be undone? (read < create < update < delete) |
| Data scope | How many records/users does this affect? |
| Regulatory category | Is this action in a regulated domain? |
| Confidence | How certain is the agent/LLM's proposal? |
Each dimension produces a 0-100 score with a human-readable explanation; a weighted
sum produces the overall risk score, which AutonomyMapper compares against configured
thresholds (backend/policies/) to pick the autonomy level.
| Component | Responsibility |
|---|---|
app/core/actions/ |
Validates and normalizes untrusted action proposals |
app/core/risk_engine/ |
The 4-dimension risk scorer |
app/core/autonomy/ |
Risk score -> autonomy level mapping |
app/core/confirmation/ |
Holds/resolves medium-risk actions pending user confirmation |
app/core/review/ |
Holds/resolves high-risk actions pending human review |
app/core/audit/ |
Immutable record of every routing decision + risk breakdown |
app/core/auth/ |
JWT auth, Argon2id password hashing, 4-role RBAC (agent/user/reviewer/admin) |
app/tools/ |
ToolGateway + a deterministic in-memory database_tool the engine actually executes against |
app/llm/ |
Real LLM integration (OpenAI or Groq) for POST /agent/chat |
This is not a script that runs once on localhost:
- Deployed to a real cloud environment (Render), not localhost -- see the live link above.
- Real persistence: PostgreSQL, not in-memory-only -- schema managed with Alembic
migrations (
backend/migrations/), verified with a real, disposable Postgres instance in CI (tests/test_postgres_integration.py). - Concurrent request handling: multi-worker
uvicorn(WEB_CONCURRENCY), async FastAPI. - Real LLM provider connected: Groq (
openai/gpt-oss-20b) and OpenAI are both supported through one provider abstraction (app/core/llm/provider.py) -- not mocked in production, only mocked in the test suite. - Authentication and authorization: JWT bearer tokens, 4 roles, enforced on every protected route -- verified in Swagger with the standard Authorize flow.
- Health and readiness endpoints:
GET /health(liveness + static config) andGET /ready(real DB connectivity + migration-state check). - Structured logging and centralized error handling: every request logged as JSON with a request ID; no unhandled exception ever reaches a client as a raw stack trace.
- 1251 automated tests, including dedicated auth-security and real-Postgres integration suites.
- Docker:
backend/Dockerfile+docker-compose.ymlbuild and run the full stack (Postgres + migration + backend) reproducibly. - AWS Terraform prepared (
deploy/aws/) for ECS Fargate + RDS, not yet applied.
The bonus "adaptive threshold calibration" (auto-adjusting risk scores based on confirm/reject history) is not implemented. Everything else in the problem statement is.
cd backend
python -m venv .venv && source .venv/Scripts/activate # Windows Git Bash
pip install -r requirements.txt
cp .env.example .env # fill in real values -- never commit this file
alembic upgrade head
uvicorn app.main:app --reloadWithout DATABASE_URL set, the app falls back to in-memory repositories automatically
(useful for quick local testing without standing up Postgres).
docker compose up -d
curl http://localhost:8000/healthcd backend
pytest -q| Endpoint | Purpose |
|---|---|
POST /auth/login |
Exchange username/password for a JWT (public) |
POST /auth/users |
Create a user (ADMIN only) |
POST /actions/evaluate |
Submit an action proposal through the full governance pipeline |
POST /agent/chat |
Natural-language endpoint backed by a real LLM; any tool call it proposes goes through the identical governance pipeline |
GET /confirmations, POST /confirmations/{id}/confirm | /reject |
Medium-risk queue (USER/ADMIN) |
GET /reviews, POST /reviews/{id}/approve | /reject |
High-risk queue (REVIEWER/ADMIN) |
GET /audit, GET /audit/{action_id} |
Full audit trail with risk breakdowns |
GET /health, GET /ready |
Liveness / readiness |
Full interactive documentation, with request/response schemas, at /docs.
The following screenshots demonstrate the complete functionality of the application. All API functionality screenshots were captured using the live Render deployment, demonstrating that the system is deployed and operational.
The Swagger /docs page provides an overview of the available API endpoint groups, including:
- Health
- Authentication
- Actions
- Confirmations
- Reviews
- Audit
- Simulation
The Swagger Authorize modal demonstrates the configured HTTPBearer authentication mechanism and token input field.
Endpoint: POST /actions/evaluate
A low-risk read operation is evaluated by the system.
The request demonstrates a low-risk operation submitted for evaluation.
The response demonstrates that the operation was classified as autonomous and executed successfully. The response also includes the risk score and risk breakdown.
{
"autonomy_level": "autonomous",
"execution_status": "executed"
}Endpoint: POST /actions/evaluate
A medium-risk single-record operation is evaluated by the system.
The request demonstrates a medium-risk update or delete operation.
The response shows that the operation requires explicit confirmation before execution.
{
"autonomy_level": "confirm",
"confirmation_id": "..."
}Endpoint: POST /confirmations/{id}/confirm
The confirmation workflow demonstrates the human-in-the-loop execution process.
The request uses the confirmation_id generated during the medium-risk evaluation.
The response confirms that the action was successfully executed after explicit human confirmation.
Endpoint: POST /actions/evaluate
A high-risk bulk operation is evaluated by the system.
The request demonstrates a potentially destructive bulk operation, such as deleting a large number of records.
The response shows that the operation has been escalated for complete human review.
{
"autonomy_level": "full_review"
}Endpoint: GET /audit/{action_id}
The audit endpoint provides a complete record of the evaluated action.
The request retrieves the audit information using the generated action_id.
The response includes the audit record along with a human-readable risk explanation, demonstrating why the system assigned a particular risk level and autonomy decision.
The health and readiness endpoints demonstrate that the deployed application is operational and correctly configured.
The health endpoint verifies that the application and its required services are functioning correctly.
The /ready endpoint confirms production readiness, including:
- Database connectivity
- Successful migrations
- Configured LLM provider
{
"database": {
"status": "ok"
},
"migrations": {
"status": "ok"
},
"llm_provider": {
"status": "configured"
}
}The final screenshot provides additional evidence of successful deployment or application testing.
| Section | Description | Screenshots |
|---|---|---|
| 1 | Swagger API Overview | 1 |
| 2 | HTTPBearer Authorization | 1 |
| 3 | Low-Risk Autonomous Execution | 2 |
| 4 | Medium-Risk Confirmation | 2 |
| 5 | Human Confirmation Workflow | 2 |
| 6 | High-Risk Full Review | 2 |
| 7 | Audit Record and Risk Explanation | 2 |
| 8 | Health and Readiness Checks | 2 |
| 9 | Deployment/Test Evidence | 1 |
| Total | Project Evidence Screenshots | 15 |
Note: The API screenshots demonstrate the deployed application's authentication, risk evaluation, autonomous execution, confirmation workflow, full-review escalation, audit logging, health checks, and production readiness.














