Structuring AI Agent Rules and Skills Without Blowing Up Context
Overwhelming a language model with every rule at once makes output accuracy worse, not better. When structuring AI-assisted development workflows for amarjyoti.dev, that practical lesson guided how repository instructions are organized.
Most projects begin with a small AGENTS.md (or single root rule file) that grows incrementally whenever an AI coding assistant forgets a build flag, introduces an unintended style attribute, or breaks a Content Security Policy (CSP) hash. Over time, a single flat file swells to hundreds of lines. Because that entire file loads into every session, an agent updating a unit test spends context tokens reading CSS print rules and RSS XML conventions, diluting attention across irrelevant instructions.
In amarjyoti.dev, repository guidance applies progressive disclosure and separation of concerns across three layers.
Why Monolithic Instruction Files Degrade AI Output
An unbounded root instruction file creates three predictable failure modes during AI-assisted engineering:
- Context budget waste: Every always-loaded rule competes with source files, command output, and task reasoning. Loading design tokens and SEO schema checklists for a minor TypeScript utility fix wastes context before the first edit.
- Instruction dilution: Combining universal safety boundaries (“never deploy or push without explicit approval”) with situational recovery commands (“run
node scripts/check-csp.mjs --writeto updatefirebase.jsonhashes”) forces the model to weigh minor procedures alongside critical constraints. - Documentation drift: Long monolithic files are awkward to refactor, so stale file paths and outdated build flags accumulate and cause agents to hallucinate broken commands.
Just as structured prompt engineering relies on focused, task-relevant context rather than sprawling instructions, agent rules work best when routed on demand.
The Three-Tier Instruction System
Instead of placing every rule at the root, amarjyoti.dev organizes agent guidance into an entrypoint, a task router with domain guides, and progressive checklists:
AGENTS.md # Tier 1: Always-loaded invariants & entrypoint (~2.5 KB)
.agents/
├── GUIDE.md # Tier 2: Task-routing table & canonical file map
├── AVOID.md # Tier 2: Anti-patterns & refactoring pitfalls
├── ARCHITECTURE.md # Tier 2: Directory layout, boundaries, build pipeline
├── ARTICLES.md # Tier 2: Markdown loading, IST dates, reader prose
├── CONTENT.md # Tier 2: Portfolio copy, profile data, routes
├── DESIGN.md # Tier 2: CSS tokens, themes, typography, print PDF
├── FRONTEND.md # Tier 2: Astro components, TypeScript, client JS, a11y
├── SEO.md # Tier 2: JSON-LD, /llms.txt, RSS, firebase.json CSP
└── skills/ # Tier 3: Progressive, step-by-step workflows
├── add-article/SKILL.md
├── update-content/SKILL.md
└── verify-and-csp/SKILL.md
Each tier has a strict scope and predictable loading rule.
Tier 1: The Thin AGENTS.md Entrypoint
AGENTS.md is the only file loaded unconditionally at the start of every task. Keeping it around ~2.5 KB restricts it strictly to repository-wide invariants:
- Task routing: Directs every contributor or agent to read
.agents/GUIDE.mdbefore modifying files. - Engineering standards: Separation of concerns across data, types, constants, utilities, UI, styles, and client scripts; minimalism and zero empty directories; zero code comments; zero em dashes; zero import-time side effects;
Object.hasOwn()prototype-safe lookups; required tests only; and synchronized documentation. - Verification gates: Defines
npm run format && npm run verify:fastas the baseline pre-finish gate (plus a concise commit message suggestion), andnpm run format && npm run verifywhen modifying routes, UI, CSS, client scripts, tests, or config. - Operational safety: Prohibits running
firebase deploy,git push, destructive git commands, committing.env*files, or editing generated directories (dist/,.astro/,.firebase/,node_modules/,test-results/).
Nothing specific to CSS tokens, Astro props, or Markdown frontmatter belongs in Tier 1.
Tier 2: Scoped Domain Guides via .agents/GUIDE.md
.agents/GUIDE.md serves as a lightweight router. A single Markdown table maps each task scope to the exact domain guide and progressive skill required:
| Task Scope | Domain Guide | Progressive Skill |
|---|---|---|
| Anti-patterns & pitfalls | AVOID.md |
None |
| Layout, boundaries, build flow | ARCHITECTURE.md |
None |
| Copy, profile data, skills, routes | CONTENT.md |
update-content |
| Markdown articles, reader, pagination | ARTICLES.md |
add-article |
| Astro, TypeScript, client JS, a11y | FRONTEND.md |
verify-and-csp |
| CSS tokens, themes, typography, print PDF | DESIGN.md |
verify-and-csp |
| SEO, JSON-LD, endpoints, RSS, CSP | SEO.md |
verify-and-csp |
GUIDE.md also summarizes the stack and npm scripts, indexes canonical sources of truth (src/data/portfolio.ts, src/utils/articles/loader.ts, src/types/, src/constants/, src/utils/seo/index.ts, src/styles/tokens.css), and enforces four execution guardrails: locate before reading, batch independent work, reuse existing primitives, and no unrequested dependencies.
Tier 3: Progressive Skills in .agents/skills/
Domain guides explain the rules and architecture; skills provide repeatable procedures for common workflows.
Each skill lives in .agents/skills/<name>/SKILL.md with brief YAML metadata (name and description) followed by concise execution steps:
---
name: add-article
description: Author, update, or validate a Markdown technical article in src/assets/articles/, including frontmatter, IST datetime normalization, reader prose rules, and build verification.
---
Only when an agent edits an article does it load add-article/SKILL.md to review filename rules, required frontmatter fields, CSP-safe prose rules, and exact verification commands (npm run format, targeted Vitest suites, and npm run verify:fast). Keeping SKILL.md files under ~25 lines keeps them fast to scan and easy to maintain.
Enforcing AI-Assisted Quality with Automated Gates
Consistent output evaluation matters as much in AI-assisted coding as it does in prompt engineering: prose rules alone cannot catch every subtle regression. Two practices keep instructions honest as amarjyoti.dev evolves:
- Synchronized documentation:
AGENTS.mdrequires updatingAGENTS.md,.agents/guides and skills,README.md, and the living architecture and workflow articles whenever routes, commands, endpoints, tokens, CSP rules, or conventions change. - Deterministic verification over prose reminders: Rather than relying on the model to manually remember formatting, zero-comment rules, doc references, JSON-LD
@idreferences, or CSP hashes,npm run verify:fastenforcesastro check,npm run check:hygiene(including Knip dead-code checks plus Markdown relative links, backticked repository file paths, andSKILL.mdfrontmatter validation acrossAGENTS.md,.agents/,README.md, and articles),npm run build(including 2-page PDFKit output),npm run check:output, andnpm run check:csp, whilenpm run verifyadds Prettier format verification, Vitest unit tests, and Playwright E2E checks (including live CSP and dual-theme WCAG AA audits).
When a CSP hash check fails after a template update, verify-and-csp/SKILL.md provides the exact diagnostic and recovery commands (node scripts/check-csp.mjs --print or --write) on demand without bloating every session.
Applying This Pattern Incrementally
Any repository struggling with oversized AI rule files can adopt this three-tier design step by step:
- Shrink the root file to ~2.5 KB: Keep only universal safety limits, core engineering standards, and verification commands in
AGENTS.md. - Build a routing index: Split domain rules (content, styling, SEO, architecture) into small focused guides linked from one routing table.
- Turn repeat procedures into skills: Move multi-step checklists (content updates, article publishing, CSP troubleshooting) into concise
SKILL.mdfiles. - Automate deterministic invariants: Replace repeated prose warnings with scriptable checks (
check:hygienefor code hygiene, doc links/paths, andSKILL.mdfrontmatter, pluscheck:output,check:csp, typechecks, and E2E gates).
Delivering focused context at the exact moment a task requires it keeps AI-assisted development reliable, verifiable, and grounded in real engineering standards.