worker.md SPEC
Menu

AI Worker

An AI Worker is a callable, bounded task contract. While autonomous agents reason across open-ended loops, a worker defines the explicit contract: validated inputs, structured outputs, strict deadlines, and tool whitelists. Its runner may execute via deterministic code, a model call, or an internal bounded agent workflow.

Worker Package Structure
my-worker/
├── worker.md    # Bounded execution contract
├── tools/       # Optional tool scripts & schemas
├── tests/       # Input/output fixture pairs
└── evals/       # Benchmark quality scoring
worker.md (Sample File)
---
name: pr-security-reviewer
role: Security Auditor
skills: [git-analysis, owasp-checklist]
timeout: 30s
allowed_tools: [git, ast-grep]
---

# PR Security Reviewer

Reviews pull request diffs for security vulnerabilities before merge.

## Input Contract
- `diff`: Unified Git diff string of proposed code changes.

## Output Contract
- `status`: "clean" | "warnings" | "blocking"
- `findings`: Array of detected issues with file and line numbers.

## Instructions
1. Analyze only modified lines in the provided diff.
2. Check strictly against OWASP Top 10 vulnerabilities.
3. If critical vulnerabilities exist, return status "blocking".

The AI Triad: Sub-Agent, Skill, and Worker#

Modern agentic architectures separate identity, capability, and execution into three complementary primitives:

WHO

Sub-Agent (Role)

The persona, domain identity, and reasoning model delegated to tackle the work.

Defines: Persona, goals, reasoning loop
Example: Security Auditor
HOW

Skill (SKILL.md)

Modular procedural knowledge, reference documentation, and executable scripts that extend what an agent knows how to do.

Defines: Workflows, scripts, reference docs
Example: owasp-audit skill instructions

Sub-Agent vs AI Worker: Side-by-Side#

Why do we need a separate worker.md contract instead of just creating another sub-agent?

Dimension Sub-Agent (Role) AI Worker (worker.md)
Core Nature An actor / persona with an active reasoning loop. A bounded work contract for a single task.
Autonomy High: decides what steps to take, what tools to call, and when it is finished. Bounded: executes only the contract defined in worker.md. No open-ended looping.
Execution Model Loop: Think → Act → Observe → Repeat Pipeline: Validate Input → Execute Task → Verify Output
Resource Limits Unpredictable token usage and step counts. Hard limits: strict timeout (e.g. 30s), cost budget, and tool whitelist.
Deliverable Conversational explanation, summary, or report. Strict, schema-validated JSON with trace metadata.
Software Parallel A background daemon or long-running worker thread. An AWS Lambda function, Celery task, or Temporal activity.

How They Fit Together in Production#

Orchestrator / Caller (FastAPI, Temporal, LangGraph)
         │
  invokes callable contract
         ▼
AI Worker (worker.md)     [The Contract: inputs, outputs, deadlines, tool gating]
         │
  executed by runner using
         ▼
Runner Implementation    [Deterministic script, single LLM call, or bounded sub-agent]
         +
Skills (SKILL.md)        [Procedural instructions & tool definitions]
Contract Declaration vs. Runtime Enforcement: A worker.md file declares explicit limits (such as timeout_ms, max_cost_usd, and allowed_tools). The runner harness is responsible for actively enforcing those limits through deadline timers, cost quotas, sandbox boundaries, and schema validation.
Want to dive deeper into commercial packaging or architectural boundaries?

How AI Workers Work#

Workers execute via a three-phase bounded execution contract, eliminating runaway loops and cost spikes:

01 / DISCOVERY & CONTRACT

Input Schema Validation

The runtime verifies input payloads against strict schemas, checks quota/rate limits, and gates permissions before calling any model.

02 / BOUNDED EXECUTION

Sandboxed Resource Ceilings

Workers run with strict timeouts, token budgets, and tool whitelists. No open-ended planning loops or arbitrary self-delegation.

03 / AUDITED OUTPUT

Structured Response Envelope

Results are validated against output schemas and wrapped in a deterministic envelope stamped with trace IDs, execution duration, and token metrics.

Frequently Asked Questions#

FAQ#

Is this a framework or a standard?

No. It is a design pattern and a shared vocabulary. You can implement workers with any model, runtime, or platform.

When should I use a worker instead of an agent?

Use a worker for bounded, auditable execution (do X with these inputs). Use an agent when you need autonomous planning and goal selection.

What belongs in a worker contract?

Inputs, outputs, status codes, constraints (timeouts, tools), and observability fields like trace IDs and attempt counters.

Do workers need to be deterministic?

They do not need to be perfectly deterministic, but they should be repeatable enough that teams can test, monitor, and reason about them.