Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Build with AI

The 3-Step Agent Protocol

Aegil provides an agent-driven development architecture engineered specifically for autonomous AI coding assistants (such as Claude Code, Cursor, Windsurf, and Antigravity). By confining AI operations to declarative specifications and isolated hooks, Aegil’s deterministic compiler and verification harness mathematically prevent hallucinated code and architectural drift.

The problem with AI agents in full-stack repos

Section titled “The problem with AI agents in full-stack repos”

AI coding assistants (such as Claude Code, Cursor, Windsurf, or Antigravity) are powerful, but when given an unstructured full-stack codebase, they frequently make subtle, dangerous errors:

  • They edit generated ORM models or database migration files directly.
  • They forget server-side authorization checks on newly added endpoints.
  • They accept client-provided user IDs or roles (actingUserId), introducing critical security vulnerabilities.
  • They modify native iOS or Android manifests by hand, breaking build scripts.

Aegil eliminates these risks by providing deterministic boundaries and a machine-readable protocol designed specifically for AI agents.


Instruct your AI agent to follow this exact 3-step execution loop:

The 3-Step Agent Execution Loop

Step 1: Edit the Domain Specification (specs/<feature>/*.tsp)

Section titled “Step 1: Edit the Domain Specification (specs/<feature>/*.tsp)”

The agent defines or updates entities, @validate bounds, @policy rules, @stateMachine transitions, or custom @mutation operations in specs/<feature>/*.tsp.

Note: Domain specs must reside in feature folders (e.g. specs/notes/notes.tsp). Only app.tsp and platforms.tsp live at the root. Placing domain specs at the root triggers ERR_SPEC_MISPLACED.

The agent executes:

Terminal window
aegil build --project . --agent

Aegil returns a structured JSON Action Manifest containing agentTasks:

{
"status": "PENDING_IMPLEMENTATION",
"agentTasks": [
{
"taskId": "escalateTicket",
"targetFile": "hooks/escalate_ticket_hook.dart",
"expectedClassName": "EscalateTicketHook",
"implementsInterface": "EscalateTicketHandler",
"contract": {
"preconditionsGuaranteedByCompiler": [
"Caller identity and role verified from session",
"Database transaction active",
"Ticket entity pre-fetched",
"CEL policy permissions verified",
"State transition to Escalated verified"
],
"postconditionsRequiredFromAgent": [
"Assign assignedAgentId",
"Transition status to Escalated",
"Save changes and return updated Ticket"
]
}
}
]
}

The agent reads the task’s contract:

  • Preconditions: The agent knows that authentication, transactions, and permissions are already handled and must not be re-checked.
  • Postconditions: The agent knows the exact output state required.

Step 3: Implement Hooks and Run the Verification Harness

Section titled “Step 3: Implement Hooks and Run the Verification Harness”

When aegil build runs, it scaffolds hook templates with // AEGIL:STUB markers for any pending tasks. The agent replaces the stub logic at targetFile, then rebuilds and verifies:

Terminal window
aegil build --project . --agent
aegil verify --project . --agent

The task is only complete when aegil verify --agent returns "status": "VERIFIED".


Essential prompt instructions for AI agents

Section titled “Essential prompt instructions for AI agents”

Add these rules to your project’s agent instructions (e.g. AGENTS.md or CLAUDE.md):

  1. Never edit files in .aegil/: All files in .aegil/ are hash-locked. Modifying them triggers ERR_TAMPERED_GENERATED_FILE.
  2. Never accept caller ID or role from the client: All endpoints must derive user identity strictly from the server session.
  3. Always rebuild after editing hooks: Run aegil build before aegil verify to avoid ERR_STALE_HOOK_MIRROR.
  4. Always put domain specs in feature folders: Place specs in specs/<feature>/*.tsp to avoid ERR_SPEC_MISPLACED.
  5. Never stop on VERIFIED_PARTIAL: Verification is only complete when Docker integration tests pass and status is VERIFIED.

What you see Why What to do
ERR_TAMPERED_GENERATED_FILE The AI agent edited a generated file in .aegil/. Tell the agent to discard the edit and update specs/<feature>/*.tsp instead.
ERR_STALE_HOOK_MIRROR The agent edited a hook file but forgot to run aegil build before aegil verify. Instruct the agent to run aegil build before verifying.
ERR_SPEC_MISPLACED The agent created a spec file at specs/*.tsp root. Instruct the agent to place domain specs under specs/<feature>/*.tsp.
Status: UNAVAILABLE Docker is not running in the agent environment. Start Docker so the agent can execute the integration suite.