Every rule of this system came from a real mistake in our work. Then we checked it against what research and model vendors say.
I'll show you five such rules: for each one you'll see what problem it solves, how it works and how much weight it carries in our system.
Our system counted the numbers on 4 Nov 2026; a few carry the date of an earlier measurement. The numbers grow day by day.
Framework 01 · answers the question: why the system improves
Lesson after consent
ProblemAn agent skill that a human corrected repeats the same mistake on the next run, because a correction made in the chat is lost along with the conversation.
Rules
- A case is created only from a failure or a correction - a rejection, an override, a workaround, an error, a better way - never from a success, so that the system does not learn shortcuts.
- A lesson binds only after a human's decision, recorded in their own words. The agent proposes a lesson, the human accepts it.
- The bank is light and undeletable: character limits, and a rejected lesson stays as a record of the refusal.
- A lesson reaches the run through a hook every time the skill starts, so it does not depend on whether the model remembers it.
- A lesson that says to do less - for example to skip a check - is flagged.
In codeskills/sa-skill-creator/lesson-bank.mdskills/sa-skill-creator/scripts/lesson_bank.pytools/lessons-view/
Framework 02 · answers the question: why the system won't do damage
Five classes of acts
ProblemAn agent started without a human - at night, in the background, as a subagent - must not be able to perform an act it shouldn't, even when the content it reads tries to steer it. The boundary has to come from the design, not from a request in the instructions.
Rules
- Every act has a class from 1 to 5 - the scale is below.
- A script computes the class, not the model: for built-in tools and the shell, from the tool's name and its arguments.
- No subagent gets class 4 or 5 tools, and the policy hook refuses.
- An unsupervised role has no shell and sees only named tools - injected content has nothing to send with.
- A class 3 act goes only through a narrow tool whose code a human approved in a commit.
In codetools/roles/operation_class.pytools/roles/policy.pytools/roles/launch.pytools/narrow-tools/
Framework 03 · answers the question: why the system doesn't break
Control in code, not in the prompt
ProblemA model is probabilistic, so a rule in the instructions is a request. Where something depends on it, you need a check that works every time. Without such checks the knowledge base and the system rot quietly: dead links, stale boards, skipped maintenance rituals.
Rules
- Hooks before a tool call and before a commit check what has to be right, instead of reminding. The delete guard asks before files are removed.
- Every field of a shared data store has one owner, and a write to a field with no owner stops.
- Tool settings are generated from one source, not typed in by hand. A value a script can compute is computed by the script, and the model copies it.
- Faults are detected without a model: the linter only states facts about files, with no auto-fix, and the heartbeat counts signals with a script and shows one snapshot at the start of a session.
- Several independent layers, because none is airtight: the degradation register says, for each maintenance ritual, how to tell that it has stopped happening, and the tools have tests beside them.
In codetools/hooks/tools/delete-guard/tools/write-contract/tools/context-lint/tools/heartbeat/tools/degradation/
Framework 04 · answers the question: why search works
Map before content
ProblemAn agent that reads everything or scans folders pays in context for every file, and a model makes worse use of information in a long input. On top of that, grep returns dozens of files in no order, and a vector index drifts out of sync with a knowledge base that changes every day.
Rules
- A fixed reading order: the scope index, the entity's status board in full, the file map - never a folder scan.
- A read / don't-read split as volume control: archives, correspondence and finished artifacts are not read, and what matters in them is extracted into files read by default.
- The map is generated from a one-sentence description in the header of every file.
- Size before content: find first, then read a range by headings; logs and registers only through a script, and a reminder of this enters the context the moment a long file is read.
- The agent searches on its own, with tools, helped by a local SQLite FTS5 index with BM25 ranking, refreshed on every query, and a link graph that, before a file is moved, tells what points to it. All local, no network.
In code.claude/rules/long-files.mdtools/sections/tools/catalog/tools/search/tools/context-graph/
Framework 05 · answers the question: how to search hundreds of legal documents economically and effectively
Source beside the note
ProblemA legal answer without a verifiable quote is hard to check, and legal tools built on RAG still get things wrong. Fragments from vector search lose their context, and a whole legal act in the context with every question costs a lot of tokens.
Rules
- The source text sits with you, with its provenance and version: you know where it came from, which command fetched it and when; a change to the text is a separate commit that shows the diff.
- First the note with the findings, the source only when the note is not enough: the agent reads a note of a few pages instead of a 9,449-line act.
- Every finding has a verbatim quote and its location in the source (provision, file), so a human can check it in a few seconds.
- Search by structure and by words, read by range: a provision number, a case reference and a legal term are searched for exactly, and only the fragment around the hit is read.
- Conclusions checked against the sources, and the level of trust said out loud: an audit by a second reading catches wrong claims before they are used, and an answer resting on an unconfirmed file says that it is unconfirmed.
The same approach works for hundreds of documents, and for a database of hundreds of thousands of rulings we add hybrid search.
Comparison: full text, RAG, agentic search and “source beside the note”
| Full text in context | Classic RAG | Agentic search | Source beside the note | |
|---|---|---|---|---|
| Tokens | a lot with every question; only a small knowledge base fits (Anthropic: under 200,000 tokens) | few | more than RAG, because the agent searches in several steps | few: a note instead of the act, a range instead of the file |
| Accuracy in law | the model makes worse use of the middle of a long input | fragments lose context; legal tools built on RAG are wrong in 17-33% of answers | more accurate and more transparent than semantic search, slower | exact terms and provision numbers, findings checked against the source |
| Verifiability | hard | depends on citing the fragment | good, the agent points to the file and line | a verbatim quote and location in every finding |
| Change in the law | has to be loaded again | the index has to be recomputed; the index drifts | nothing to recompute | a diff in the commit and a list of notes to review |
| Scale | smallest | largest | medium | today: tens to hundreds of documents |
In codedata/zrodla/POCHODZENIE.mdtools/search/tools/context-graph/
Plus · where a model judges
Judge certification
ProblemWhere a model judges a rule - a judge at a gate - the same prompt gives different verdicts, and a judge trained on the same cases we test it on looks better than it is.
Rules
- One prompt change per round, accepted only if accuracy rises; a tie is a rejection. from GEPA
- Reflection on missed cases together with their cause. from GEPA
- A hypothesis written down before the result, with a list of the cases it is meant to fix. from VISTA
- A wall between the training set and the held-out set; the held-out set is not even used to choose a candidate. further than GEPA
- A short prompt; a deletion is a full-fledged change (in GEPA, prompts up to 9.2 times shorter than MIPROv2), and the certificate covers a specific model and wording of the rule. from GEPA
In codetools/prompt-stabiliser/tools/gates/
List · accessed 4 Nov 2026
Sources
Research papers and pages the frameworks stand on. All accessed 4 Nov 2026.
01 · Lesson after consent
- Zhang et al., “Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models”, ICLR 2026 - arxiv.org/abs/2510.04618
- Suzgun et al., “Dynamic Cheatsheet: Test-Time Learning with Adaptive Memory”, 2025 - arxiv.org/abs/2504.07952
- Google Cloud AI Research et al., “ReasoningBank: Scaling Agent Self-Evolving with Reasoning Memory”, ICLR 2026 - arxiv.org/abs/2509.25140
- City University of Hong Kong, Adelaide University, “Practice Makes Unsafe: Skill Misevolution in Self-Improving LLM Agents”, 2026 - arxiv.org/abs/2608.12851
- Shinn et al., “Reflexion: Language Agents with Verbal Reinforcement Learning”, 2023 - arxiv.org/abs/2303.11366
- Zhao et al., “ExpeL: LLM Agents Are Experiential Learners”, AAAI-24 - arxiv.org/abs/2308.10144
- Wang, Mao, Fried, Neubig, “Agent Workflow Memory”, 2024 - arxiv.org/abs/2409.07429
- Anthropic, “Equipping agents for the real world with Agent Skills”, 16 Oct 2025 - anthropic.com/engineering
- Anthropic, memory tool documentation - platform.claude.com/docs
02 · Five classes of acts
- Saltzer, Schroeder (MIT), “The Protection of Information in Computer Systems”, 1975 - web.mit.edu/Saltzer
- Debenedetti et al. (Google, Google DeepMind, ETH Zurich), “Defeating Prompt Injections by Design” (CaMeL), 2025 - arxiv.org/abs/2503.18813
- Beurer-Kellner et al., “Design Patterns for Securing LLM Agents against Prompt Injections”, 2025 - arxiv.org/abs/2506.08837
- OWASP, “LLM06:2025 Excessive Agency” - genai.owasp.org
- Simon Willison, “The lethal trifecta for AI agents”, 16 Jun 2025 - simonwillison.net
- Anthropic, Claude Code: “Configure permissions” - code.claude.com/docs
03 · Control in code, not in the prompt
- Anthropic, Claude Code: “Automate actions with hooks” - code.claude.com/docs
- Anthropic, “Building effective agents”, 19 Dec 2024 - anthropic.com/engineering
- CaMeL and “Design Patterns for Securing LLM Agents” - as for framework 02
- James Reason (University of Manchester), “Human error: models and management”, BMJ 2000 - pmc.ncbi.nlm.nih.gov
- Martin Thompson, “Single Writer Principle”, 22 Sep 2011 - mechanical-sympathy.blogspot.com
04 · Map before content
- Liu, Lin, Hewitt, Paranjape, Bevilacqua, Petroni, Liang (Stanford, UC Berkeley, Samaya AI), “Lost in the Middle: How Language Models Use Long Contexts”, TACL 2023 - arxiv.org/abs/2307.03172
- Li, Li, Zhang, Mei, Bendersky (Google DeepMind, University of Michigan), “Retrieval Augmented Generation or Long-Context LLMs?”, EMNLP 2024 - arxiv.org/abs/2407.16833
- Hong, Troynikov, Huber (Chroma), “Context Rot”, 14 Jul 2025 - trychroma.com/research/context-rot
- Robertson (Microsoft Research), Zaragoza (Yahoo! Research), “The Probabilistic Relevance Framework: BM25 and Beyond”, 2009 - staff.city.ac.uk
- Anthropic, “Effective context engineering for AI agents”, 29 Sep 2025 - anthropic.com/engineering
- Anthropic, “Building agents with the Claude Agent SDK”, 29 Sep 2025 - claude.com/blog
- Boris Cherny, conversation about Claude Code on Latent Space - latent.space/p/claude-code
- Andrej Karpathy, “LLM Wiki”, 4 Apr 2026 - gist.github.com/karpathy
- SQLite, FTS5 documentation - sqlite.org/fts5.html
05 · Source beside the note
- Magesh, Surani, Dahl, Suzgun, Manning, Ho (Stanford, Yale), “Hallucination-Free? Assessing the Reliability of Leading AI Legal Research Tools”, 2024 - arxiv.org/abs/2405.20362
- Pipitone, Houir Alami (ZeroEntropy), “LegalBench-RAG”, 2024 - arxiv.org/abs/2408.10343
- Kim, Lee, Hwang (LBOX, University of Illinois Urbana-Champaign, University of Seoul), “LegalSearchLM”, EMNLP 2025 - arxiv.org/abs/2505.23832
- Anthropic, “Introducing Contextual Retrieval”, 19 Sep 2024 - anthropic.com/news
Plus · Judge certification
- Agrawal et al. (UC Berkeley, Stanford, MIT, Databricks, Notre Dame), “GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning”, ICLR 2026 - arxiv.org/abs/2507.19457
- Liu et al. (UC Berkeley, Huazhong University of Science and Technology, Hefei University of Technology), “Reflection in the Dark: Exposing and Escaping the Black Box in Reflective Prompt Optimization” (VISTA), ACL SRW 2026 - arxiv.org/abs/2603.18388
- Yang et al. (Google DeepMind), “Large Language Models as Optimizers” (OPRO), ICLR 2024 - arxiv.org/abs/2309.03409
- Pryzant et al. (Microsoft), “Automatic Prompt Optimization with ‘Gradient Descent’ and Beam Search” (ProTeGi), EMNLP 2023 - arxiv.org/abs/2305.03495
- Opsahl-Ong et al. (incl. Stanford, UC Berkeley), “Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs” (MIPRO), EMNLP 2024 - arxiv.org/abs/2406.11695
- Shankar et al. (UC Berkeley, Université de Montréal), “Who Validates the Validators?” (EvalGen), 2024 - arxiv.org/abs/2404.12272