Purpose
Define explicit input/output schemas for artifacts passed between agents or pipeline stages. Every producer knows exactly what shape to emit; every consumer knows exactly what shape to expect. Eliminates silent data-loss and schema drift across multi-agent workflows.
When to use
- A multi-agent workflow hands data from one stage to another and the schema is undocumented.
- An agent's output is consumed by a downstream agent and validation is missing.
- Contract versioning is needed because the artifact shape is evolving across iterations.
- A new pipeline stage is being added and its expected inputs/outputs must be specified.
Do NOT use when
- The task is a single-agent, single-step operation with no handoff.
- An existing contract file already fully covers the artifact shape (update it instead).
- The work is pure prose generation where structured schemas add no value.
Operating procedure
- Run
grep -r "contract" --include="*.md" --include="*.json" --include="*.yaml"in the repo to find existing contract definitions. - List every pipeline stage involved in the workflow in a numbered table:
| # | Stage | Producer Agent | Consumer Agent |. - For each stage boundary, write a JSON Schema or TypeScript interface defining the artifact with required fields, types, and descriptions.
- Add a
versionfield (semver string) to every contract schema — start at1.0.0for new contracts. - Define validation rules: list which fields are required vs. optional, acceptable value ranges, and enum constraints.
- Write a
validate_artifact(data, schema)pseudocode block showing how the consumer should reject malformed input. - Create a producer/consumer pairing table:
| Contract Name | Producer | Consumer | Version | Breaking Change Policy |. - Add a
_contract_metaenvelope to each artifact specifyingschema_version,produced_by,produced_at(ISO-8601), andchecksum(SHA-256 of payload). - Run a dry-run validation: pick one real or sample artifact, apply the schema, and list any violations found.
- Write the final contract files to
contracts/(or the repo's equivalent directory), one file per stage boundary.
Decision rules
- If a field is consumed by any downstream agent, it is
required— never silently optional. - If two producers emit the same artifact type, unify into one schema and version it; do not fork.
- Breaking changes (removing fields, narrowing types) require a major version bump and a migration note.
- Non-breaking changes (adding optional fields) require a minor version bump.
- If a consumer receives an artifact that fails validation, it must halt and return a structured error — never silently drop fields.
Output requirements
- Contract Schema — one JSON Schema or TypeScript interface per stage boundary.
- Pairing Table — maps every producer to every consumer with version and change policy.
- Validation Report — dry-run results showing pass/fail per field for a sample artifact.
- Migration Notes — for any version bump, a list of what changed and how consumers should adapt.
References
references/delegate-contracts.md— patterns for structuring delegation handoff.references/checkpoint-rules.md— when to checkpoint before/after artifact production.- JSON Schema specification (https://json-schema.org/) for schema authoring.
Related skills
autonomous-run-control— contracts govern what a run must produce before it can terminate.collaboration-checkpoints— checkpoints often trigger contract validation.goal-decomposition— decomposed tasks need contracts at each task boundary.verification-before-advance— verification uses contracts as the acceptance criteria.
Failure handling
- Missing contract: If no contract exists for a stage boundary, create one before allowing data to flow — never infer schema from a single sample.
- Schema mismatch: If a produced artifact fails validation, block the pipeline and emit a diff showing expected vs. actual shape.
- Version conflict: If producer and consumer expect different versions, halt and surface both versions for reconciliation.
- Ambiguous ownership: If no single agent owns a contract, assign ownership explicitly before proceeding.
