ADR 0003 — Autonomy Orchestrator (Two-Pillar Loop, Strict Level-2)¶
- Status: accepted — amended by ADR 0008 (2026-10-26): Pillar A, the test synthesis, is retired; Pillar B, the digest and the LSAT pillars stand
- Date: 2026-05-11
- Spec: specs/018-autonomous-framework
- Constitution clauses amended: §10 Autonomy Level, new §12 Autonomy Loop Invariants
Context¶
The repo's only autonomous loop today is the weekly /evolve audit (scripts/evolve_audit.py + .github/workflows/evolve.yml — both moved to the fleet hub's spec-driven kit on 2026-10-25, see docs/spec-driven.md) that appends BACKLOG candidates from grep + coverage parsing. It does not measure reasoning quality (the backend/law_ai/eval/ LegalBench harness referenced from docs/legalbench.md is empty), and it does not grow the corpus — every ingestion run is hand-driven via make ingest.
Legal content is effectively unbounded: statutes, regulations, opinions, and citations expand daily across jurisdictions. We need a sustained, auditable loop that (a) measures reasoning quality continuously and proposes test coverage for low-coverage modules, and (b) walks the existing knowledge graph for orphan citations / under-cited jurisdictions and dispatches known sources to fill the gaps.
Decision¶
Add an AutonomyOrchestrator that coordinates two cooperating loops on top of the existing /evolve infrastructure:
- TestPilot (Pillar A, kind=
test): runs LegalBench, parses coverage, and aTestSynthesizercrew proposes pytest cases for the lowest-coverage modules. Proposals are written to*.proposed.pyfiles decorated with@pytest.mark.skip("autonomy-proposed")and surfaced via a draft PR (labelautonomy) — never executed by default, never merged automatically. - CorpusGrowth (Pillar B, kind=
content): aTopicFrontierLangGraph workflow walks Neo4j (scan_graph→prioritize→dispatch→summarize) and dispatches queries againstSOURCE_REGISTRYadapters. Every dispatched document still flows throughIngestionScout.run_and_commit, so the existing confidence gate +PendingReviewHITL queue are preserved. New:Case/:Statutenodes can be created only byIngestionScout— the orchestrator never writes to Neo4j directly.
Both pillars are invoked through one entry point — python manage.py run_autonomy --kind {test,content,evolve} and law_ai.core.autonomy.run_cycle() — wrapped in a single audit.AuditEvent (event_type='autonomy_cycle') per run. A daily compose_digest task writes backend/var/autonomy/digest-<date>.md enumerating PRs opened, BACKLOG items appended, docs quarantined, and the LegalBench delta. The digest file is the canonical human-review surface.
Three settings flags govern the loop:
AUTONOMY_ENABLED(defaultFalse): global kill-switch. When false,run_cycleexits with a singleevent_type='autonomy_disabled'provenance event. No Celery dispatch, no HTTP, no Neo4j read.AUTONOMY_ALLOWED_SOURCES(default[]): allow-list of adapter names dispatch is permitted to call. Anything else emitsevent_type='policy_violation'and exits non-zero.AUTONOMY_DIGEST_DIR(defaultbackend/var/autonomy): location of digest files.
Cadences:
nightly_tests— daily 06:00 UTC via.github/workflows/nightly-tests.yml(CI keeps Ollama state hot enough for--limit 20runs).weekly_evolve— Mondays 13:00 UTC via the existing.github/workflows/evolve.yml.content_sweep— every 6h via Celery beat in the localworkerservice (CI runners cannot keep Ollama state hot for full sweeps; this runs on operator hardware viamake autonomy-up).
Reaffirmation: AO-SDLC Level 2 (no auto-merge)¶
This ADR explicitly retains the §10 Autonomy Level Level-2 stance. Every loop ends in either:
- a draft PR (code) that a human reviewer must mark ready + merge, or
- a
PendingReviewrow (data) that a HITL reviewer must approve via Django admin.
No GitHub Actions workflow in this design is granted permissions sufficient to merge a PR; no Celery task may write to a :Case/:Statute node outside IngestionScout.run_and_commit. Promotion to Level 3 — even for narrow change classes — would require a separate ADR and a constitution amendment per §10.
Alternatives considered¶
- Self-hosted GitHub Actions runner for content sweeps. Rejected for MVP — adds operator burden without unlocking new behavior;
make autonomy-upon operator hardware is sufficient. May revisit if multiple operators need shared cadence. - Append TestSynthesizer output directly into the real test file. Rejected — defeats the propose-only stance; reviewer cannot easily distinguish autonomy-generated tests from human-authored ones; risk of breaking CI on a typo.
- Allow auto-merge for low-risk PR classes (test additions, doc backfills). Rejected — would require constitution amendment per §10 and an explicit policy matrix; user explicitly chose strict Level 2 for legal-accuracy reasons.
- Free-form web scraping in TopicFrontier. Rejected — constitution §5 makes "ingestion of a new public data source" a HITL gate; recursion expands within a closed
SOURCE_REGISTRYwhose names appear inAUTONOMY_ALLOWED_SOURCES. Adding a new source is its own/specifycycle. - Promote
AutonomyRunto its own Postgres table immediately. Deferred —audit.AuditEventcarries enough JSON payload for v1 digest queries. Recorded as BL-20260511-04.
Consequences¶
Positive
- Reasoning regressions become visible per-night (currently never).
- Coverage debt becomes a steady stream of reviewable proposals instead of an annual cleanup.
- Ingestion plan is data-driven: "you have N orphan citations, here are the M registered adapters that could resolve them" rather than ad-hoc.
- One audited entry point (
run_cycle→audit.AuditEvent) means one digest, one review surface.
Negative / risks
- LegalBench latency on Mistral 7B may exceed 30 minutes/night on weak hardware. Mitigation:
--limit 20default; full set monthly. - TestSynthesizer noise. Mitigation:
*.proposed.py+@pytest.mark.skipmake every proposal opt-in. - Operator confusion if
AUTONOMY_ENABLED=Falsesilently no-ops. Mitigation:make autonomy-statussurfaces the flag; digest task records the disabled state explicitly.
Compliance check¶
| Constitution clause | Compliance |
|---|---|
| §1 mission alignment, local-first | All LLM calls go through the existing local Ollama client. No closed-source fallback. |
| §2 tech stack | Uses Django + Celery + LangGraph + Pydantic + httpx + tenacity already in §2. No new top-level frameworks. |
| §4 provenance & audit | Every cycle, every adapter dispatch, every LLM call logged via law_ai.core.provenance. |
| §5 HITL | New data sources still gated by /specify; low-confidence ingest still goes to PendingReview. |
| §10 autonomy level | Level 2 explicitly retained; this ADR is the recorded reaffirmation. |
| §11 continuous evolution | Loop appends BACKLOG items; never deletes; spec-driven additions of new adapters preserved. |
| New §12 autonomy invariants | This ADR is the source of those invariants. |
Supersedes / Superseded by¶
- Supersedes: none.
- Superseded by: none.