# ============================================================================= # Projet : AIR — Accounting Intermediate Representation # Auteur : Simon-Pierre Boucher # Contact : contact@spboucher.ai # Fichier : demo_agent.py # Description : Demonstration agent — books a month of activity using ONLY syscalls. # ============================================================================= """Demo agent (Phase 5). A scripted stand-in for an AI agent: it records a small month of business using exclusively the syscall interface — it never sees the ledger file, the compiler internals, or the account codes. Every call it makes lands in the hash-chained audit log. Run: python -m sdk.demo_agent --home books """ from __future__ import annotations import argparse from sdk.syscalls import AirKernel, SyscallError def run(home: str, actor: str = "agent:demo") -> int: kernel = AirKernel(home, actor=actor) print(f"[{actor}] staging January's events via CreateEconomicEvent...") kernel.create_economic_event({ "id": "evt_agent_owner", "type": "OwnerContribution", "date": "2026-01-02", "description": "Initial owner investment", "amount": {"amount": "15000.00", "currency": "CAD"}, }) kernel.create_economic_event({ "id": "evt_agent_sale", "type": "Sale", "date": "2026-01-15", "description": "Consulting engagement", "amount": {"amount": "2500.00", "currency": "CAD"}, "tax": {"jurisdiction": "CA-QC"}, }) kernel.create_economic_event({ "id": "evt_agent_purchase", "type": "Purchase", "date": "2026-01-18", "description": "Office supplies (cash)", "amount": {"amount": "180.00", "currency": "CAD"}, "payment": {"immediate": True}, "tax": {"jurisdiction": "CA-QC"}, }) print(f"[{actor}] Validate...") diagnostics = kernel.validate() for d in diagnostics: print(" " + d.render().splitlines()[0]) print(f"[{actor}] Post...") receipt = kernel.post() print(f" posted {receipt['entries']} entries " f"(+{receipt['appended']} appended, key {receipt['idempotency_key']})") print(f"[{actor}] oops — the purchase was a duplicate. Reverse...") contra = kernel.reverse("je_evt_agent_purchase") print(f" reversal entry: {contra}") print(f"[{actor}] ClosePeriod 2026-01...") kernel.close_period("2026-01") try: kernel.create_economic_event({ "id": "evt_agent_late", "type": "Sale", "date": "2026-01-31", "amount": {"amount": "10.00", "currency": "CAD"}, "tax": {"jurisdiction": "CA-QC"}, }) kernel.post() except SyscallError as exc: print(f" refused as expected: {str(exc).splitlines()[0]}") print(f"[{actor}] GenerateReport trial-balance...") print(kernel.generate_report("trial-balance")) ok = kernel.audit.verify_chain() print(f"audit log: {len(kernel.audit.records)} syscalls recorded, " f"chain {'VALID' if ok else 'BROKEN'}") return 0 if ok else 1 def main() -> int: parser = argparse.ArgumentParser( description="AIR demo agent — keeps books through syscalls only") parser.add_argument("--home", required=True) parser.add_argument("--actor", default="agent:demo") args = parser.parse_args() return run(args.home, args.actor) if __name__ == "__main__": raise SystemExit(main())