Getting Started with agentAssert
Integrate formal behavioral contracts into your production Python AI agent pipeline in under five minutes. Wrap any existing LLM or multi-agent orchestrator with <10ms inline invariant checking and automated recovery.
Watch the 5-Minute Technical Masterclass
Author Varun Pratap Bhardwaj breaks down the 18,000-mission empirical study, the 4-tuple $C = (P, I, G, R)$ architecture, and the convex moment polytope certifier.
Installation
Install the core `agentassert-abc` library via PyPI with optional YAML and numerical certificate solvers.
pip install agentassert-abc[yaml,math]
Define Your Contract
Create a contract specification file `contract.yaml` specifying preconditions ($P$), invariants ($I$), governance rules ($G$), and recovery policies ($R$).
agent: financial-advisor
version: "1.0"
before:
- user must be authenticated
during:
- responses must not contain SSN patterns
- session cost must stay under $5.00
severity: critical
action: block
after:
- response must include regulatory disclaimer
on_failure:
retries: 3
fallback: escalate_to_human Wrap & Execute Your Agent
Wrap your standard agent execution function or class instance. The monitor evaluates invariants asynchronously without blocking token streaming.
from agentassert_abc import Contract, Monitor import openai # 1. Load contract specification contract = Contract.from_yaml("contract.yaml") # 2. Define baseline agent runner def my_agent(prompt: str) -> str: response = openai.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": prompt}] ) return response.choices[0].message.content # 3. Wrap with runtime behavioral contract monitor guarded_agent = Monitor(contract).wrap(my_agent) # 4. Execute safely result = guarded_agent.run("Summarize account details for user 1024") print(result.output) print(f"Drift: {result.metrics.drift}, Violations: {result.metrics.violations}")
Certify Production Telemetry
Audit runtime mission logs with the ABC II non-parametric linear program solver to generate mathematically certified reliability reports.
from agentassert_abc.certifier import certify_missions # Run LP certifier over recorded production mission trajectories certificate = certify_missions( log_file="production_missions.jsonl", moments=14, alpha=0.05 ) print(f"Certified Reliability Floor: {certificate.floor:.4f}") print(f"Anytime-valid Type-I Bound: {certificate.type_1_bound:.4f}") certificate.export_audit_pdf("compliance_report.pdf")
Open Source Code, Benchmarks & YAML Contracts
All Python source code, mathematical verification certificates, 18,000 mission datasets, and YAML contract templates are open-source and available on GitHub.