Monarchic AI Protocol
This repository defines the shared, versioned protocol for Monarchic AI. It is the compatibility layer between the orchestrator, runner, and agent roles, so the schemas are minimal and stable while allowing forward-compatible extensions.
Overview
- Provide versioned JSON Schemas for language-agnostic validation.
- Provide Rust, TypeScript, and Protobuf bindings that mirror the schemas.
- Keep the protocol small and explicit for v1 interoperability.
Usage
Quickstart
Install the published package for your language, then use the generated bindings.
Install
- Rust (crates.io):
cargo add monarchic-agent-protocol - TypeScript (npm):
npm install @monarchic-ai/monarchic-agent-protocol - Python (PyPI):
pip install monarchic-agent-protocol - Ruby (RubyGems):
gem install monarchic-agent-protocol - Go (Go modules):
go get github.com/monarchic-ai/monarchic-agent-protocol/src/go@vX.Y.Z - Java/Kotlin (JitPack):
implementation("com.github.monarchic-ai:monarchic-agent-protocol:vX.Y.Z") - .NET (NuGet):
dotnet add package Monarchic.AgentProtocol - PHP (Packagist):
composer require monarchic-ai/monarchic-agent-protocol
Examples
- Rust:
examples/rust/task.rs - TypeScript:
examples/ts/task.ts - Protobuf C++:
examples/proto/cpp/task.cpp - Protobuf Java:
examples/proto/java/TaskExample.java - Protobuf Kotlin:
examples/proto/kotlin/TaskExample.kt - Protobuf C#:
examples/proto/csharp/TaskExample.cs - Protobuf Python:
examples/proto/python/task.py - Protobuf Ruby:
examples/proto/ruby/task.rb - Protobuf PHP:
examples/proto/php/task.php - Protobuf Dart:
examples/proto/dart/task.dart - Protobuf Rust:
examples/proto/rust/task.rs
Versioning
- Protocol versions live under
schemas/v1/. - Each v1 object requires
version: "v1". - New versions must be added under a new directory (e.g.
schemas/v2/) without changing existing v1 files.
Schema summary
JSON Schema files are generated from the protobuf definitions. Do not edit them by hand.
Schema files live under schemas/v1/:
schemas/v1/task.jsonschemas/v1/artifact.jsonschemas/v1/event.jsonschemas/v1/gate_result.jsonschemas/v1/run_context.jsonschemas/v1/delivery_contract.jsonschemas/v1/agent_role.jsonschemas/v1/dataset_ref.jsonschemas/v1/experiment_spec.jsonschemas/v1/objective_spec.jsonschemas/v1/eval_result.jsonschemas/v1/provenance.jsonschemas/v1/schema.json(index)schemas/v1/monarchic_agent_protocol.proto
All schemas allow additional properties for forward compatibility.
Schema index coverage
schemas/v1/schema.json is the canonical top-level JSON schema index. Its oneOf entries currently cover:
schemas/v1/task.jsonschemas/v1/artifact.jsonschemas/v1/event.jsonschemas/v1/gate_result.jsonschemas/v1/run_context.jsonschemas/v1/dataset_ref.jsonschemas/v1/experiment_spec.jsonschemas/v1/objective_spec.jsonschemas/v1/eval_result.jsonschemas/v1/provenance.json
schemas/v1/agent_role.json is a shared schema used by task.json.
AgentRole
Enum values:
product_ownerproject_managerdevqareviewersecurityops
Example:
Task
Represents work assigned to an agent.
Required fields:
version:"v1"task_id: stable identifierrole:AgentRolegoal: human-readable objective
Optional fields:
inputs: free-form objectconstraints: free-form objectgates_required: list of gate names to run (ex:["qa", "security"])run_context:RunContextdelivery_contract: typed acceptance and risk contract for autonomous delivery loopsobjective_spec: objective scoring contract for deterministic outcome evaluationexperiment_spec: typed experiment design contract for deterministic in silico runs
Example:
DeliveryContract
Typed acceptance contract for autonomous delivery execution.
Required fields:
objective: plain-language objective statementdefinition_of_done: ordered completion checklistrequired_checks: required gate/check names for merge readinessrisk_tier:low | medium | high | critical
Optional fields include cycle/turn budgets (max_cycle_minutes, max_agent_turns) and PR/review/rollback strategy hints.
RunContext
Execution hints for a runner.
Required fields:
version:"v1"repo: repository identifier or URLworktree: worktree path or identifierimage: VM/container image referencerunner: runner identifier
Optional fields:
labels: list of labels or tags
Example:
Artifact
Outputs produced by an agent or runner.
Required fields:
version:"v1"artifact_id: stable identifiertype: artifact type (ex:patch,log,report)summary: short descriptionpath: path or locator for the artifacttask_id: task identifier that produced itprovenance: typed provenance hashes and runtime metadatadataset_refs: datasets used while producing the artifacteval_results: typed metric outputs with optional uncertainty boundsexperiment_spec: optional copy of experiment contract used for this output
Example:
Event
Lifecycle state updates.
Required fields:
version:"v1"event_type: event categorytimestamp: ISO 8601 timestamptask_id: task identifierstatus: state label
Optional fields:
message: human-readable detailsprovenance: typed runtime/source hashes for event attributioneval_results: optional metric snapshot payloads
Example:
GateResult
Outcome of QA, review, security, or other gates.
Required fields:
version:"v1"gate: gate namestatus: pass/fail or other gate-specific status
Optional fields:
reason: short explanationevidence: free-form object with supporting data
Example:
DatasetRef
Reference to a dataset used by an experiment or output artifact.
Required fields:
dataset_idsha256format
Optional fields include uri, split, size_bytes, and description.
ExperimentSpec
Typed contract for model design and acceptance checks.
Required fields:
experiment_idobjectivedataset_refs: list ofDatasetRefacceptance: metric threshold policy
Optional fields include hypothesis, model_family, seeds, and free-form constraints.
ObjectiveSpec
Typed objective scoring contract for progress/outcome checks.
Required fields:
metric_keydirection:maximize,minimize, ortarget
Optional fields include target, min_delta, tolerance, report_file,
report_task_id, weight, and description.
EvalResult
Typed evaluation output row.
Required fields:
metricvaluepassed
Optional fields include lower_ci, upper_ci, variance, seed, and notes.
Provenance
Typed provenance contract for reproducibility and traceability.
Required fields:
prompt_sha256code_sha256runtimerunnerorchestratorcreated_at
Optional fields include dataset hashes/references and command/task/pipeline hashes.
Language bindings
Rust
The crate lives at the repo root with sources under src/rust/lib.rs.
use ;
let task = Task ;
TypeScript
TypeScript bindings are in src/ts/index.ts.
import { Task } from "./src/ts/index";
const task: Task = {
version: "v1",
task_id: "task-123",
role: "dev",
goal: "Implement protocol",
};
Go
Go module sources live under src/go with module path:
github.com/monarchic-ai/monarchic-agent-protocol/src/go
Protobuf
The v1 protobuf schema lives at schemas/v1/monarchic_agent_protocol.proto. It mirrors the JSON schema and uses google.protobuf.Struct for free-form objects (inputs, constraints, evidence, extensions). Additional JSON properties should be stored in the extensions field on each message.
Language packages are published per registry. Use the registry package for your language instead of generating local outputs.
Python (PyPI)
Install the published package and import the generated protobuf bindings:
Ruby
Ruby bindings live under src/ruby.
Java/Kotlin
Java/Kotlin sources live under src/java.
C#
C# sources live under src/csharp.
PHP
PHP sources live under src/php.
Dart
Dart sources live under src/dart.
Contributing
Tooling
nix developprovides Rust, Node, jq, Pythonjsonschema, andprotoc.nix flake checkvalidates JSON schemas, protobuf codegen, and package imports (PyPI + Rust + npm + Go).- JSON Schema test:
scripts/test-json-schema.sh. - Pre-commit schema JSON parse check:
scripts/pre-commit-schema-json-parse.sh. - Pre-commit schema parse smoke test:
scripts/test-pre-commit-schema-json-parse.sh. - Schema edit changelog:
schemas/SCHEMA_CHANGELOG.md. - Schema changelog format test:
scripts/test-schema-changelog-format.sh. - README schema index coverage test:
scripts/test-readme-schema-index-coverage.sh. - Protobuf codegen test (all languages):
scripts/test-proto.sh. - Protobuf availability smoke test:
scripts/test-proto-availability-smoke.sh. - Protobuf codegen (write to
src/<lang>):scripts/generate-proto.sh. - Protobuf codegen (write to
src/<lang>and regenerate JSON schemas):scripts/generate-proto.sh. - JSON Schema regeneration only:
scripts/generate-json-schema.sh. - JSON Schema generation requires
protoc-gen-jsonschema(install withgo install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema@latest).
Use the Nix apps (preferred) or the scripts directly:
nix run .#generate-proto(scripts/generate-proto.sh): regenerate protobuf outputs intosrc/<lang>.nix run .#generate-json-schema(scripts/generate-json-schema.sh): regenerate JSON Schemas from the protobuf source.nix run .#update-local-hashes(scripts/update-local-hashes.sh): refresh hashes for local build inputs.nix run .#update-version -- <version>(scripts/update-version.sh): bump version across manifests and tags (expectsvX.Y.Zinput).nix run .#update-registry-hashes(scripts/update-registry-hashes.sh): refresh hashes for published registries (npm, crates, PyPI, RubyGems, NuGet, JitPack, GitHub source).
For every schema change, generate protobuf outputs and update local hashes.
For every release, tag the commit, update versions, push, and update registry hashes after pushing.
Schema validation workflow
- Run full schema lint and semantic checks:
bash scripts/lint-schemas.sh. - Run direct schema fixture checks:
bash scripts/test-json-schema.sh. - Validate staged schema JSON before commit:
bash scripts/pre-commit-schema-json-parse.sh. - Verify pre-commit checker behavior is deterministic:
bash scripts/test-pre-commit-schema-json-parse.sh. - Verify schema changelog entry format:
bash scripts/test-schema-changelog-format.sh. - Verify README schema index coverage stays aligned:
bash scripts/test-readme-schema-index-coverage.sh.
Nix packages
packages.default: Rust crate for protocol typespackages.rs-lib: Rust crate for protocol types (local)packages.rs-registry-lib: Rust crate from crates.io (registry)packages.py-lib: installable Python package (local)packages.py-registry-lib: PyPI package (registry)packages.ts-lib: TypeScript types package (local)packages.ts-registry-lib: npm registry package (types-only)packages.go-lib: Go module (local)packages.go-registry-lib: Go module from GitHub (registry)packages.rb-lib: Ruby gem (local)packages.rb-registry-lib: Ruby gem from RubyGems (registry)packages.java-lib: Java/Kotlin jar (local)packages.java-registry-lib: Java/Kotlin jar from JitPack (registry)packages.dart-lib: Dart package (local)packages.dart-registry-lib: Dart package from pub.dev (registry)packages.csharp-lib: C# package sources (local)packages.csharp-registry-lib: C# package from NuGet (registry)packages.php-lib: PHP package sources (local)packages.php-registry-lib: PHP package from Packagist (registry)
CI and releases
.github/workflows/ci.ymlvalidates JSON schemas, protobuf codegen, and runscargo test..github/workflows/release.ymlpublishes language packages.- Python publishing is implemented for PyPI; other language registry steps are scaffolded.
License
LGPL-3.0-only