Loop System Architect
Turn a repeated task into an observable control system that can execute, prove its result,
recover after interruption, and improve without rewriting its own purpose.
Choose the mode
- Audit: inspect an existing workflow and report missing or open-loop parts. Do not edit unless asked.
- Design: produce the contract, state schema, role graph, evals, and runtime design.
- Operationalize: implement the controller, adapters, persistence, evidence, and one-command run path.
- Evolve: analyze completed runs, validate a proposed loop/knowledge/skill improvement, and promote or reject it.
When the user asks to “build” or “get it working,” include Operationalize. A Markdown plan alone
is not an operational loop.
Start from live reality
- Read repository instructions and the artifacts the user placed in scope.
- Inspect the actual tools, entry points, state files, tests, schedulers, agent CLIs, and dirty worktree.
- Separate current authoritative input from reference material. Do not use model memory to fill gaps.
- Classify the loop:
- Terminal: one goal with a demonstrable finish line.
- Recurring: every run terminates, while the monitor/service continues until retired.
- State what exists, what is missing, and what is only claimed before changing anything.
For a full audit, read audit-rubric.md.
Require a closed control loop
Identify and connect all of these:
- objective and owner;
- completion condition or per-run success condition;
- authoritative source boundary and provenance;
- trigger and cheap preflight;
- sensor and collected signal;
- comparator, window, and threshold/rule;
- controller and finite decision space;
- actuator and the path that returns the new result to the sensor;
- persistent state, cursor, event log, and evidence store;
- orchestrator, executor, and independent verifier responsibilities;
- open capability/skill discovery and candidate-skill creation;
- authority boundaries and protected fields;
- acceptance evals and required evidence;
- retries, timeouts, backoff, failure classification, and rollback;
- idempotency, deduplication, concurrency lock, and side-effect choke point;
- token, cost, turn, and wall-time budgets;
- observability, alerts, and a no-op success state;
- direct replacement of superseded active truth;
- experience distillation and controlled promotion;
- stop, pause, kill, and retirement conditions.
Missing sensor-to-actuator feedback means open loop. Missing persistent state means a repeated
prompt. Missing verifier evidence means self-asserted completion. Missing a controller/trigger
means a procedure humans must operate.
Produce a loop package
Adapt names to the repository, but keep one canonical machine-readable contract and one state
record. The default package is:
loop/
├── LOOP-CONTRACT.md human-readable operating contract
├── loop.contract.json machine-readable canonical contract
├── RUN-STATE.json current run, cursor, attempts, next machine action
├── events/ append-only run events or an equivalent event store
├── evidence/ verifier-readable receipts
├── evals/ deterministic and semantic acceptance checks
├── knowledge/ typed promoted knowledge, not raw logs
├── candidates/ unpromoted lessons and skill changes
└── scripts/run-loop one-command controller or project-native equivalent
Use loop-contract.md for the field contract. Copy
loop.contract.template.json, fill every placeholder,
then run:
python3 scripts/loop_lint.py /path/to/loop.contract.json
Use the copy inside this skill when the project has not vendored the linter.
Build the controller, not only the instructions
The controller must make one invocation advance the loop without asking the user to copy and
paste between agents:
- acquire a concurrency lock and derive an idempotency key;
- load and lint the contract and state;
- verify frozen-source hashes or current source authority;
- run the cheap trigger/preflight and record a no-op success when no work exists;
- resolve required capabilities;
- create a minimal context packet for the orchestrator/executor;
- execute in an isolated workspace when changes are possible;
- capture outputs, costs, tool calls, diffs, and evidence;
- run an independent verifier that cannot certify its own writes;
- on failure, classify and route a bounded repair, retry, rollback, or stop;
- on pass, atomically promote the result and update current state;
- append an immutable event/receipt;
- invoke distillation only when its trigger is satisfied;
- release the lock and expose the next machine-executable action.
Prefer deterministic code for triggers, state transitions, schema checks, permissions, retries,
hashes, and promotion. Use LLMs for judgment, planning, diagnosis, and content that cannot be
decided mechanically.
Discover or create skills without a static allowlist
Use open discovery with controlled execution:
- Derive a capability contract from the task: input, output, side effects, evidence, risk.
- Search installed skills and project capabilities by metadata and contract fit.
- Inspect provenance and dependencies; do not import embedded project identity as truth.
- Sandbox a candidate skill and run capability-specific evals.
- If none fits, create a candidate skill in isolation with its own examples and evals.
- Promote a version only after it passes security, privacy, functional, and regression checks.
- Register locally by default. External publication follows the owning environment's separate policy.
Open discovery does not grant open authority. Mandates, data scope, side-effect policy, and runtime
permissions still constrain every skill.
Distill experience into usable knowledge
Never feed an ever-growing log to every agent. Keep raw evidence, episodic summaries, candidate
lessons, canonical knowledge, procedural skills, and evals separate.
Run the promotion path:
trace + outcome
→ normalized episode
→ candidate lesson
→ deduplicate and conflict-check
→ replay against prior runs and counterexamples
→ shadow or canary
→ promote a version
→ monitor the next runs
→ keep or rollback
Trigger distillation on repeated failure, repeated manual work, drift, cost regression, meaningful
outcome evidence, or a configured sample size—not merely because time passed. Read
distillation.md before designing or changing the learning layer.
The evolution process may improve SOPs, triggers, context packing, scripts, skills, retrieval, and
operational thresholds within delegated authority. It may not silently rewrite the objective,
source boundary, tenant/privacy boundary, authority model, or the eval that defines success.
Replace active truth cleanly
For any accepted update:
- compute the impact graph across contract, state schema, code, tests, docs, views, and skills;
- declare
REPLACES, REMOVES, and KEEPS;
- update all dependents;
- remove superseded wording and values from active retrieval;
- run contradiction/stale-value scans;
- run affected happy and failure-path evals;
- run a zero-context probe that must recover exactly one current answer;
- promote atomically; retain prior versions only in version control/event history, not active context.
Calibrate autonomy
- Auto-run reversible, bounded actions when deterministic and independent verification passes.
- Use canary, shadow, dual verification, and rollback for higher-risk automated actions.
- Stop for the user only when authority is missing, a required decision changes the objective,
or the action is materially irreversible and not already authorized.
- Never make routine human approval a hidden actuator in a loop advertised as autonomous.
Verify completion
Do not call the loop operational until all are true:
- one command or configured event can advance it without prompt ferrying;
- interruption recovery resumes from persisted state without redoing accepted work;
- duplicate triggers cannot duplicate side effects;
- verifier failure causes bounded repair or a clean stop;
- both success and fail-closed paths have evidence;
- a no-work run terminates successfully and cheaply;
- the current status, last result, cost, open failure, and next action are observable;
- one evolution candidate has been replayed and either promoted or correctly rejected;
- a zero-context agent can explain the current contract and next action from active files alone.
Report separately: what is implemented, what was exercised, what remains dormant for lack of a
live sensor, and what still requires the user's authority.
1---2name: loop-system-architect-23description: Design, audit, repair, and operationalize reliable agent loops with explicit goals, triggers, persistent state, orchestration, independent verification, failure recovery, open skill discovery or creation, experience distillation, controlled self-improvement, and retirement conditions. Use when the user asks to build a loop, autonomous or recurring agent workflow, multi-agent operating system, self-improving process, knowledge/experience distillation pipeline, zero-context recovery flow, permanent update/replacement loop, or to turn a prose plan or repeated prompt into a genuinely executable loop.4---56# Loop System Architect78Turn a repeated task into an observable control system that can execute, prove its result,9recover after interruption, and improve without rewriting its own purpose.1011## Choose the mode1213- **Audit**: inspect an existing workflow and report missing or open-loop parts. Do not edit unless asked.14- **Design**: produce the contract, state schema, role graph, evals, and runtime design.15- **Operationalize**: implement the controller, adapters, persistence, evidence, and one-command run path.16- **Evolve**: analyze completed runs, validate a proposed loop/knowledge/skill improvement, and promote or reject it.1718When the user asks to “build” or “get it working,” include Operationalize. A Markdown plan alone19is not an operational loop.2021## Start from live reality22231. Read repository instructions and the artifacts the user placed in scope.242. Inspect the actual tools, entry points, state files, tests, schedulers, agent CLIs, and dirty worktree.253. Separate current authoritative input from reference material. Do not use model memory to fill gaps.264. Classify the loop:27 - **Terminal**: one goal with a demonstrable finish line.28 - **Recurring**: every run terminates, while the monitor/service continues until retired.295. State what exists, what is missing, and what is only claimed before changing anything.3031For a full audit, read [audit-rubric.md](references/audit-rubric.md).3233## Require a closed control loop3435Identify and connect all of these:36371. objective and owner;382. completion condition or per-run success condition;393. authoritative source boundary and provenance;404. trigger and cheap preflight;415. sensor and collected signal;426. comparator, window, and threshold/rule;437. controller and finite decision space;448. actuator and the path that returns the new result to the sensor;459. persistent state, cursor, event log, and evidence store;4610. orchestrator, executor, and independent verifier responsibilities;4711. open capability/skill discovery and candidate-skill creation;4812. authority boundaries and protected fields;4913. acceptance evals and required evidence;5014. retries, timeouts, backoff, failure classification, and rollback;5115. idempotency, deduplication, concurrency lock, and side-effect choke point;5216. token, cost, turn, and wall-time budgets;5317. observability, alerts, and a no-op success state;5418. direct replacement of superseded active truth;5519. experience distillation and controlled promotion;5620. stop, pause, kill, and retirement conditions.5758Missing sensor-to-actuator feedback means open loop. Missing persistent state means a repeated59prompt. Missing verifier evidence means self-asserted completion. Missing a controller/trigger60means a procedure humans must operate.6162## Produce a loop package6364Adapt names to the repository, but keep one canonical machine-readable contract and one state65record. The default package is:6667```text68loop/69├── LOOP-CONTRACT.md human-readable operating contract70├── loop.contract.json machine-readable canonical contract71├── RUN-STATE.json current run, cursor, attempts, next machine action72├── events/ append-only run events or an equivalent event store73├── evidence/ verifier-readable receipts74├── evals/ deterministic and semantic acceptance checks75├── knowledge/ typed promoted knowledge, not raw logs76├── candidates/ unpromoted lessons and skill changes77└── scripts/run-loop one-command controller or project-native equivalent78```7980Use [loop-contract.md](references/loop-contract.md) for the field contract. Copy81[loop.contract.template.json](assets/loop.contract.template.json), fill every placeholder,82then run:8384```bash85python3 scripts/loop_lint.py /path/to/loop.contract.json86```8788Use the copy inside this skill when the project has not vendored the linter.8990## Build the controller, not only the instructions9192The controller must make one invocation advance the loop without asking the user to copy and93paste between agents:94951. acquire a concurrency lock and derive an idempotency key;962. load and lint the contract and state;973. verify frozen-source hashes or current source authority;984. run the cheap trigger/preflight and record a no-op success when no work exists;995. resolve required capabilities;1006. create a minimal context packet for the orchestrator/executor;1017. execute in an isolated workspace when changes are possible;1028. capture outputs, costs, tool calls, diffs, and evidence;1039. run an independent verifier that cannot certify its own writes;10410. on failure, classify and route a bounded repair, retry, rollback, or stop;10511. on pass, atomically promote the result and update current state;10612. append an immutable event/receipt;10713. invoke distillation only when its trigger is satisfied;10814. release the lock and expose the next machine-executable action.109110Prefer deterministic code for triggers, state transitions, schema checks, permissions, retries,111hashes, and promotion. Use LLMs for judgment, planning, diagnosis, and content that cannot be112decided mechanically.113114## Discover or create skills without a static allowlist115116Use open discovery with controlled execution:1171181. Derive a capability contract from the task: input, output, side effects, evidence, risk.1192. Search installed skills and project capabilities by metadata and contract fit.1203. Inspect provenance and dependencies; do not import embedded project identity as truth.1214. Sandbox a candidate skill and run capability-specific evals.1225. If none fits, create a candidate skill in isolation with its own examples and evals.1236. Promote a version only after it passes security, privacy, functional, and regression checks.1247. Register locally by default. External publication follows the owning environment's separate policy.125126Open discovery does not grant open authority. Mandates, data scope, side-effect policy, and runtime127permissions still constrain every skill.128129## Distill experience into usable knowledge130131Never feed an ever-growing log to every agent. Keep raw evidence, episodic summaries, candidate132lessons, canonical knowledge, procedural skills, and evals separate.133134Run the promotion path:135136```text137trace + outcome138→ normalized episode139→ candidate lesson140→ deduplicate and conflict-check141→ replay against prior runs and counterexamples142→ shadow or canary143→ promote a version144→ monitor the next runs145→ keep or rollback146```147148Trigger distillation on repeated failure, repeated manual work, drift, cost regression, meaningful149outcome evidence, or a configured sample size—not merely because time passed. Read150[distillation.md](references/distillation.md) before designing or changing the learning layer.151152The evolution process may improve SOPs, triggers, context packing, scripts, skills, retrieval, and153operational thresholds within delegated authority. It may not silently rewrite the objective,154source boundary, tenant/privacy boundary, authority model, or the eval that defines success.155156## Replace active truth cleanly157158For any accepted update:1591601. compute the impact graph across contract, state schema, code, tests, docs, views, and skills;1612. declare `REPLACES`, `REMOVES`, and `KEEPS`;1623. update all dependents;1634. remove superseded wording and values from active retrieval;1645. run contradiction/stale-value scans;1656. run affected happy and failure-path evals;1667. run a zero-context probe that must recover exactly one current answer;1678. promote atomically; retain prior versions only in version control/event history, not active context.168169## Calibrate autonomy170171- Auto-run reversible, bounded actions when deterministic and independent verification passes.172- Use canary, shadow, dual verification, and rollback for higher-risk automated actions.173- Stop for the user only when authority is missing, a required decision changes the objective,174 or the action is materially irreversible and not already authorized.175- Never make routine human approval a hidden actuator in a loop advertised as autonomous.176177## Verify completion178179Do not call the loop operational until all are true:180181- one command or configured event can advance it without prompt ferrying;182- interruption recovery resumes from persisted state without redoing accepted work;183- duplicate triggers cannot duplicate side effects;184- verifier failure causes bounded repair or a clean stop;185- both success and fail-closed paths have evidence;186- a no-work run terminates successfully and cheaply;187- the current status, last result, cost, open failure, and next action are observable;188- one evolution candidate has been replayed and either promoted or correctly rejected;189- a zero-context agent can explain the current contract and next action from active files alone.190191Report separately: what is implemented, what was exercised, what remains dormant for lack of a192live sensor, and what still requires the user's authority.