spb/air Public MIT
AIR — The Language of Accounting.
Python 100%
1# =============================================================================2# Projet : AIR — Accounting Intermediate Representation3# Auteur : Simon-Pierre Boucher4# Contact : contact@spboucher.ai5# Fichier : demo_agent.py6# Description : Demonstration agent — books a month of activity using ONLY syscalls.7# =============================================================================8"""Demo agent (Phase 5).910A scripted stand-in for an AI agent: it records a small month of business11using exclusively the syscall interface — it never sees the ledger file, the12compiler internals, or the account codes. Every call it makes lands in the13hash-chained audit log.1415Run: python -m sdk.demo_agent --home books16"""17from __future__ import annotations1819import argparse2021from sdk.syscalls import AirKernel, SyscallError222324def run(home: str, actor: str = "agent:demo") -> int:25 kernel = AirKernel(home, actor=actor)2627 print(f"[{actor}] staging January's events via CreateEconomicEvent...")28 kernel.create_economic_event({29 "id": "evt_agent_owner", "type": "OwnerContribution",30 "date": "2026-01-02", "description": "Initial owner investment",31 "amount": {"amount": "15000.00", "currency": "CAD"},32 })33 kernel.create_economic_event({34 "id": "evt_agent_sale", "type": "Sale", "date": "2026-01-15",35 "description": "Consulting engagement",36 "amount": {"amount": "2500.00", "currency": "CAD"},37 "tax": {"jurisdiction": "CA-QC"},38 })39 kernel.create_economic_event({40 "id": "evt_agent_purchase", "type": "Purchase", "date": "2026-01-18",41 "description": "Office supplies (cash)",42 "amount": {"amount": "180.00", "currency": "CAD"},43 "payment": {"immediate": True},44 "tax": {"jurisdiction": "CA-QC"},45 })4647 print(f"[{actor}] Validate...")48 diagnostics = kernel.validate()49 for d in diagnostics:50 print(" " + d.render().splitlines()[0])5152 print(f"[{actor}] Post...")53 receipt = kernel.post()54 print(f" posted {receipt['entries']} entries "55 f"(+{receipt['appended']} appended, key {receipt['idempotency_key']})")5657 print(f"[{actor}] oops — the purchase was a duplicate. Reverse...")58 contra = kernel.reverse("je_evt_agent_purchase")59 print(f" reversal entry: {contra}")6061 print(f"[{actor}] ClosePeriod 2026-01...")62 kernel.close_period("2026-01")63 try:64 kernel.create_economic_event({65 "id": "evt_agent_late", "type": "Sale", "date": "2026-01-31",66 "amount": {"amount": "10.00", "currency": "CAD"},67 "tax": {"jurisdiction": "CA-QC"},68 })69 kernel.post()70 except SyscallError as exc:71 print(f" refused as expected: {str(exc).splitlines()[0]}")7273 print(f"[{actor}] GenerateReport trial-balance...")74 print(kernel.generate_report("trial-balance"))7576 ok = kernel.audit.verify_chain()77 print(f"audit log: {len(kernel.audit.records)} syscalls recorded, "78 f"chain {'VALID' if ok else 'BROKEN'}")79 return 0 if ok else 1808182def main() -> int:83 parser = argparse.ArgumentParser(84 description="AIR demo agent — keeps books through syscalls only")85 parser.add_argument("--home", required=True)86 parser.add_argument("--actor", default="agent:demo")87 args = parser.parse_args()88 return run(args.home, args.actor)899091if __name__ == "__main__":92 raise SystemExit(main())93