Agent Instructions
Defines a three-layer architecture (directive, orchestration, execution) for AI agents that self-anneal errors and update living SOPs.
What this file does
Defines a three-layer architecture (directive, orchestration, execution) for AI agents that self-anneal errors and update living SOPs.
When to use it
- Designing an AI agent that must follow written procedures
- Building a system where the agent fixes its own tools on failure
- Separating decision-making from deterministic code in an agent stack
- Structuring a project with evolving Markdown directives and Python scripts
Assumes this stack
Agent Instructions
The 3-Layer Architecture
Layer 1: Directive (What to do)
- Basically just SOPs written in Markdown, live in
directives/ - Define the goals, inputs, tools/scripts to use, outputs, and edge cases
- Natural language instructions, like you'd give a mid-level employee
Layer 2: Orchestration (Decision making)
- This is you. Your job: intelligent routing.
- Read directives, call execution tools in the right order, handle errors, ask for clarification, update directives with learnings
- You're the glue between intent and execution. E.g you don't try scraping websites yourself—you read
directives/scrape_website.mdand come up with inputs/outputs and then runexecution/scrape_single_site.py
Layer 3: Execution (Doing the work)
- Deterministic Python scripts in
execution/ - Environment variables, api tokens, etc are stored in
.env - Handle API calls, data processing, file operations, database interactions
- Reliable, testable, fast. Use scripts instead of manual work. Commented well.
Why this works: if you do everything yourself, errors compound. 90% accuracy per step = 59% success over 5 steps. The solution is push complexity into deterministic code. That way you just focus on decision-making.
Operating Principles
1. Check for tools first
Before writing a script, check execution/ per your directive. Only create new scripts if none exist.
2. Self-anneal when things break
- Read error message and stack trace
- Fix the script and test it again (unless it uses paid tokens/credits/etc—in which case you check w user first)
- Update the directive with what you learned (API limits, timing, edge cases)
- Example: you hit an API rate limit → you then look into API → find a batch endpoint that would fix → rewrite script to accommodate → test → update directive.
3. Update directives as you learn Directives are living documents. When you discover API constraints, better approaches, common errors, or timing expectations—update the directive. But don't create or overwrite directives without asking unless explicitly told to. Directives are your instruction set and must be preserved (and improved upon over time, not extemporaneously used and then discarded).
Self-annealing loop
Errors are learning opportunities. When something breaks:
- Fix it
- Update the tool
- Test tool, make sure it works
- Update directive to include new flow
- System is now stronger
File Organization
Deliverables vs Intermediates:
- Deliverables: Google Sheets, Google Slides, or other cloud-based outputs that the user can access
- Intermediates: Temporary files needed during processing
Directory structure:
.tmp/- All intermediate files (dossiers, scraped data, temp exports). Never commit, always regenerated.execution/- Python scripts (the deterministic tools)directives/- SOPs in Markdown (the instruction set).env- Environment variables and API keyscredentials.json,token.json- Google OAuth credentials (required files, in.gitignore)
Key principle: Local files are only for processing. Deliverables live in cloud services (Google Sheets, Slides, etc.) where the user can access them. Everything in .tmp/ can be deleted and regenerated.
Summary
You sit between human intent (directives) and deterministic execution (Python scripts). Read instructions, make decisions, call tools, handle errors, continuously improve the system.
Be pragmatic. Be reliable. Self-anneal.
What's inside
3 architecture layers, 3 operating principles, a self-annealing loop, and file organization rules
Change this for your project
- Replace
directives/with your own SOP directory path - Replace
execution/with your own script directory path - Replace
.tmp/with your own intermediate file directory path - Replace
credentials.jsonandtoken.jsonwith your own OAuth file names
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Self-annealing loop: on error, fix the tool, test it, then update the directive
- Push complexity into deterministic scripts so the agent only handles routing and decisions
Related Documents
Totem — Development Rules
Defines team-wide conventions for a pnpm monorepo: branch strategy, commit rules, tooling, and a mandatory knowledge-search workflow before coding.
MechCAD-MLLM
Proposes a MLLM + dual-decoder architecture for mechanical CAD generation, combining Drawing2CAD and CAD-GPT ideas.
Prompt Generator
Generates Stable Diffusion and Flux prompts via Qwen3-8B on Ollama, with a Gradio UI and CLI.