WORKER.md Specification
The WORKER.md specification defines an open, portable format for declaring bounded AI execution units.
While general agents reason, plan, and loop open-endedly, a worker executes against an explicit schema contract, enforces strict resource constraints, and produces auditable, deterministic output envelopes.
This document specifies the directory anatomy, YAML frontmatter schema, execution constraints, and runtime lifecycle for compliant AI worker runners.
Key ideas#
- Every worker is declared with a WORKER.md file containing YAML frontmatter and execution directives.
- Input and output contracts are strictly typed (JSON schema compatible).
- Hard constraints (timeouts, max tokens/cost, allowed tools) prevent runaway autonomous loops.
- Workers are decoupled from frameworks: compatible with LangGraph, Temporal, AWS Step Functions, Claude Code, Cursor, or custom runners.
- Execution produces standardized response envelopes with trace IDs, metrics, and logs.
Diagram#
my-worker/
├── WORKER.md # Required: frontmatter contract + instructions
├── tools/ # Optional: executable tool scripts or schemas
├── tests/ # Optional: input/output test fixtures
└── evals/ # Optional: benchmark scoring prompts & assertions
Directory Structure#
A worker is packaged as a directory containing, at minimum, a WORKER.md file:
my-worker/
├── WORKER.md # Required: metadata, schema contract, and instructions
├── tools/ # Optional: executable scripts or tool declarations
│ ├── ast-grep.sh
│ └── lint.json
├── tests/ # Optional: test input/output fixture pairs
│ ├── fixture-clean.json
│ └── fixture-vuln.json
└── evals/ # Optional: evaluation scoring criteria & assertions
└── benchmark.jsonWORKER.md File Anatomy#
A WORKER.md file consists of strict YAML frontmatter enclosed by triple hyphens (---), followed by Markdown instructions for the model runtime:
---
name: pr-security-reviewer
version: 1.0.0
description: Reviews Git pull request diffs for OWASP Top 10 security vulnerabilities.
inputs:
diff:
type: string
required: true
description: Unified Git diff of changes to inspect.
repo_context:
type: object
required: false
description: Optional metadata regarding repo frameworks and languages.
outputs:
status:
type: enum
values: [clean, warnings, blocking]
findings:
type: array
description: List of detected security vulnerabilities with line numbers.
constraints:
timeout_ms: 30000
max_tokens: 4000
max_cost_usd: 0.05
allowed_tools: [git, ast-grep]
temperature: 0.0
observability:
trace_propagation: true
log_level: structured
---
# Instructions
You are an isolated security review worker. You receive raw Git diffs and evaluate them against OWASP Top 10 vulnerabilities.
## Execution Rules
1. Never propose changes outside the scope of the diff.
2. If no vulnerabilities are found, return status "clean" with an empty findings array.
3. If critical vulnerabilities exist, return status "blocking".Frontmatter Specification Reference#
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Unique lowercase identifier (lowercase letters, numbers, hyphens; max 64 chars). |
version |
string | Yes | Semantic version string (e.g., 1.0.0). |
description |
string | Yes | Non-empty summary of what the worker executes and when orchestrators should invoke it. |
inputs |
object | Yes | Mapping of accepted input field names to type definitions and schema rules. |
outputs |
object | Yes | Mapping of output property definitions expected in the response envelope. |
constraints |
object | Yes | Execution resource constraints: timeout_seconds (or timeout_ms), max_tokens, max_cost_usd, and canonical allowed_tools. |
observability |
object | No | Logging and tracing configuration (trace_propagation, log_level). |
metadata |
object | No | Arbitrary string map for author, license, repo URL, or documentation links. |
Contract Declaration vs. Runtime Enforcement#
A core architectural principle of the WORKER.md specification is the explicit separation between declaration and enforcement:
- WORKER.md is a declarative contract: Declaring
timeout_seconds: 15,max_cost_usd: 0.02, orallowed_tools: ["git"]in frontmatter establishes operational boundaries and expectations, but does not enforce them by itself. - The runtime harness enforces constraints: Compliant runners (such as Temporal activity workers, Docker sandboxes, Lambda timeouts, or API gateway proxies) must implement active deadline timers, API token spend limits, and tool-dispatch whitelists. If an execution exceeds its deadline or attempts to call an unauthorized tool, the harness halts execution and emits a standard failure envelope.
- Execution engine flexibility: An AI worker is a callable task contract. Its internal implementation may be deterministic code (e.g. an AST parser, SQL linter, or regex engine), an LLM prompt completion, or a bounded multi-step reasoning workflow. To the caller, it behaves as a predictable, auditable black box.
Runtime Lifecycle: The Three-Stage Contract#
1. Input Validation
The runner validates the incoming request payload against the worker's inputs schema and verifies quota and rate limits before calling any AI model.
2. Bounded Execution
The runner sandboxes the execution with strict timeout handlers, enforces the allowed_tools whitelist, and bounds token generation. No unbounded loops.
3. Audited Output
Output data is verified against the outputs schema, stamped with trace IDs, execution duration, and token metrics, then returned in a standard envelope.
Standard Response Envelope#
A compliant worker runner wraps execution results in a standard JSON envelope:
{
"status": "ok",
"worker": "pr-security-reviewer",
"version": "1.0.0",
"trace_id": "tr-89410-b9a",
"outputs": {
"status": "clean",
"findings": []
},
"metrics": {
"duration_ms": 1420,
"tokens": 830,
"cost_usd": 0.003
}
}See also#
FAQ#
What is the relationship between WORKER.md and SKILL.md?
SKILL.md (Agent Skills) provides procedural instructions and domain context to extend an agent. WORKER.md defines a bounded execution contract: typed input/output schemas, hard resource ceilings, tool gating, and deterministic response envelopes.
Can a worker invoke other workers?
Workers are single-responsibility execution units. Orchestration layers (such as Temporal, LangGraph, or pipeline routers) compose multiple workers together rather than nesting workers arbitrarily.
How are tools restricted during execution?
Only tools explicitly listed in the constraints.allowed_tools array are exposed to the model by the runtime harness.