Skip to main content

Runtime adaptive governance for AI agents โ€” score, gate, adapt.

Project description

๐Ÿง  Autonomica โ€” Runtime adaptive governance for AI agents

CI PyPI Python License

Like the autonomic nervous system โ€” your agents breathe freely when safe, tighten up when risky.


The Problem

AI agents can send emails, move money, and delete records โ€” all without asking. The industry treats agent governance as binary: either the agent runs free, or a human rubber-stamps every action. Neither is acceptable at scale.


Quickstart

from autonomica import govern, GovernanceBlocked

@govern(agent_id="finance-bot", action_type="financial")
def process_payment(amount: float, recipient: str) -> str:
    return f"Paid ${amount} to {recipient}"

# Call normally โ€” governance runs transparently in < 1 ms
result = process_payment(500.0, "vendor@corp.com")

# High-risk actions raise a structured exception
try:
    process_payment(1_000_000.0, "unknown@external.com")
except GovernanceBlocked as e:
    print(e.decision.risk_score.explanation)
pip install autonomica
python examples/real_agent_demo.py   # works without an API key

LangChain integration

from autonomica import Autonomica
from autonomica.integrations.langchain import wrap_langchain_tools

gov = Autonomica()
tools = wrap_langchain_tools(tools, gov, agent_id="invoice-agent")
# Every tool call now flows through governance. That's it.

Five Governance Modes

Every action lands in the least restrictive mode its risk warrants. Thresholds are static by default โ€” predictable and auditable. Enable adaptation_enabled=True to let them drift based on real override history.

Mode Risk Behaviour
๐ŸŸข FULL_AUTO 0โ€“15 Proceed silently. Log only. Zero latency overhead.
๐Ÿ”ต LOG_AND_ALERT 16โ€“35 Proceed immediately + async notification to your team.
๐ŸŸก SOFT_GATE 36โ€“60 Pause up to 60 s. Auto-proceeds unless a human vetoes.
๐Ÿ”ด HARD_GATE 61โ€“85 Full stop. Blocked until a human explicitly approves.
โ›” QUARANTINE 86โ€“100 Fully blocked. Requires audit review before any retry.

Benchmarks

Real measurements on Apple M-series, SQLite storage, Python 3.12:

Metric Result
P50 latency (sequential) 0.057 ms
P99 latency (sequential) 0.124 ms
P99 latency (1 000 concurrent) 0.123 ms
Throughput (sequential) ~17 000 actions/sec
Human interruptions โ€” static governance 5 per 100 actions
Human interruptions โ€” adaptive governance 1 per 100 actions (80% fewer)

Run it yourself: python examples/load_test.py ยท python examples/benchmark_adaptive_vs_static.py


Why Bio-Inspired?

The human brain runs two systems in parallel. System 1 handles 99% of decisions instantly โ€” breathing, walking, reading familiar text. Interrupting it for every action would cause paralysis. System 2 kicks in only for genuinely high-stakes moments. Autonomica works the same way: routine agent actions flow through in < 1 ms with zero human friction; high-risk actions pause for review. The vagal tone metric tells you how well-calibrated this balance is โ€” too tight means alert fatigue, too loose means incidents.


Installation

pip install autonomica                  # PyPI โ€” coming soon
# or from source:
git clone https://github.com/ai-singh07/autonomica
cd autonomica && pip install -e ".[dev]"

Requirements: Python 3.11+ Core deps: pydantic >= 2.0 ยท fastapi ยท uvicorn ยท httpx ยท langchain-core


Configuration

Static mode (default)

Predictable, auditable, enterprise-safe. Thresholds never change without explicit config updates.

from autonomica import Autonomica, AutonomicaConfig, SQLiteStorage
from autonomica.escalation.slack import SlackEscalation

gov = Autonomica(
    config=AutonomicaConfig(
        soft_gate_timeout_seconds=30,
        hard_gate_timeout_seconds=120,
        fail_policy="open",          # "open" | "closed" | "adaptive"
        tool_overrides={
            "process_payment": {     # always high-stakes, regardless of amount
                "financial_magnitude": 90,
                "reversibility": 80,
            },
            "write_tutorial": {      # zero financial/PII risk by design
                "data_sensitivity": 0,
                "financial_magnitude": 0,
            },
        },
    ),
    storage=SQLiteStorage("sqlite:///autonomica.db"),
    escalation=SlackEscalation("https://hooks.slack.com/services/YOUR/WEBHOOK/URL"),
)

Adaptive mode

Agents earn trust over time. Thresholds tighten after incidents, widen after false alarms. Recommended after your deployment has a baseline of human override history.

gov = Autonomica(
    config=AutonomicaConfig(
        adaptation_enabled=True,           # off by default
        adaptation_rate=0.3,
        min_actions_before_adaptation=20,
        default_trust_score=40.0,
    ),
)

Valid override signal names: financial_magnitude ยท data_sensitivity ยท reversibility ยท agent_track_record ยท novelty ยท cascade_risk. Values must be in [0, 100].


Override API

uvicorn api.main:app --reload --port 8000
Endpoint Description
GET /api/agents All agents with trust score and vagal tone
GET /api/agents/{id} Profile + adaptive threshold detail
GET /api/metrics/overview Mode distribution, escalation rate, avg score
POST /api/governance/override Approve or reject a pending gate
GET /api/audit/export?fmt=csv Compliance export (JSONL / JSON / CSV)

Examples

File What it shows
examples/quickstart.py LangChain agent + wrap_langchain_tools
examples/real_agent_demo.py @govern decorator, 4 tool types, LLM fallback
examples/benchmark_adaptive_vs_static.py Adaptive vs static human interruption comparison
examples/load_test.py P50/P95/P99 latency at 1 000 concurrent calls

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Your AI Agent               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚  every tool call
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               Autonomica                 โ”‚
โ”‚                                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Risk Scorerโ”‚โ”€โ–ถโ”‚ Governor โ”‚โ”€โ–ถโ”‚Adapt โ”‚  โ”‚
โ”‚  โ”‚ 6 signals  โ”‚  โ”‚ 5 modes  โ”‚  โ”‚ EMA  โ”‚  โ”‚
โ”‚  โ”‚ < 1 ms     โ”‚  โ”‚ enforce  โ”‚  โ”‚trust โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                       โ”‚                  โ”‚
โ”‚               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚               โ”‚  Escalation  โ”‚ Slack/CLI  โ”‚
โ”‚               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚  approved / blocked
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Your Tools                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Roadmap

  • 6-signal heuristic risk scorer (< 1 ms, zero LLM calls)
  • 5-mode governance engine with adaptive thresholds
  • EMA trust score + vagal tone calibration
  • @govern universal decorator (sync + async)
  • LangChain integration (wrap_langchain_tools)
  • Slack escalation with colour-coded risk breakdowns
  • SQLite persistence + async audit log
  • FastAPI dashboard + override API
  • Per-tool risk overrides + argument-aware SQL scoring
  • Fail policy (open / closed / adaptive)
  • PostgreSQL storage backend
  • CrewAI integration
  • AutoGen integration
  • Slack interactive approve/reject buttons
  • React dashboard frontend
  • OpenTelemetry tracing support
  • Interactive governance demo notebook
  • ML-based risk scoring (optional upgrade path)
  • Multi-tenancy + API key authentication

Contributing

See CONTRIBUTING.md. Good first issues are labelled good first issue on GitHub.

git clone https://github.com/ai-singh07/autonomica
cd autonomica && pip install -e ".[dev]"
pytest                             # 436 tests, < 2 s

License

Apache 2.0 โ€” see LICENSE.


The right governance model is not binary. It's graduated, earned, and adaptive โ€” just like trust between humans.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autonomica-0.1.0.tar.gz (93.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autonomica-0.1.0-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file autonomica-0.1.0.tar.gz.

File metadata

  • Download URL: autonomica-0.1.0.tar.gz
  • Upload date:
  • Size: 93.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for autonomica-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb40cd7d64d259f7559549dc697a45426a4f61bf78012ca61082c02c9baca5bf
MD5 244135a70ce6a34654876dc3c0f66b60
BLAKE2b-256 84376dc9817ebd028aef8db85afe00944eab8f7492c5845e9628f8cace5e3105

See more details on using hashes here.

File details

Details for the file autonomica-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autonomica-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for autonomica-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef8a1677b35624e41204da1500d93e94dff7f69e6bb03f890bade9fb1d49ac52
MD5 c6759f5e8ecab117c64b9c2c911e56c6
BLAKE2b-256 22c3b46812998dbb27a23f12bf54d164c50c0f0128987fa70a2c36bc314582ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page