# delivstat/swarmkit architecture

> Architecture diagram of the GitHub repository delivstat/swarmkit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/delivstat/swarmkit
- Repository: https://github.com/delivstat/swarmkit

## Overview

1. **What this repo is**
SwarmKit is a monorepo for a declarative multi-agent runtime: users define swarms in YAML, and the system compiles those definitions into executable LangGraph workflows. The main architectural boundary is between **workspace data** (YAML) and **runtime behavior** (Python/TypeScript code that resolves, validates, compiles, and executes that data).

2. **Core package split**
The repo is organized into three primary product surfaces: `packages/runtime` for execution and orchestration, `packages/schema` for shared schema/contracts, and `packages/ui` for the dashboard. The runtime is the system-of-record for behavior; schema is the contract layer; UI is a read-only/control-plane layer over runtime state and job history.

3. **Declarative workspace model**
A workspace is the top-level unit of configuration and contains `archetypes`, `skills`, `topologies`, `triggers`, `mcp_servers`, governance, auth, telemetry, and server settings. The runtime resolves a workspace into a canonical internal model before execution, so all downstream subsystems operate on a normalized view rather than raw files.

4. **Schema and validation boundary**
`packages/schema` defines the canonical JSON Schemas and generated Python/TypeScript models for workspace, topology, skill, archetype, and trigger objects. This package acts as the validation boundary for both CLI/runtime and UI, ensuring repo-wide consistency and enabling codegen into both Python and TypeScript consumers.

5. **Execution pipeline in the runtime**
The runtime pipeline starts with workspace discovery and resolution, then topology loading, DAG/dependency analysis, and finally compilation into a LangGraph `StateGraph`. The compiler modules under `langgraph_compiler` handle task planning, delegation, output governance, decision gates, drift checks, and tool-loop control before handing execution to the graph runtime.

6. **Agent, skill, and tool model**
Agents are defined by archetypes and compose skills; skills are the extension point for behavior. Skills can be pure prompt-based capabilities, structured decision skills, or MCP-backed tools. The runtime’s MCP client and skill executor bridge YAML-defined capabilities to concrete tool calls, including external servers and sandboxed tool execution.

7. **Model-provider abstraction**
Model access is isolated behind `model_providers`, with support for multiple LLM vendors and a mock provider for tests/dev. This abstraction matters architecturally because the same topology can mix providers per agent, and the compiler/executor is designed to stay provider-agnostic.

8. **Governance, review, and audit**
Tool use is mediated by governance evaluation before execution, with policy/provider abstractions under `governance` and human-in-the-loop review support under `review`. Every run is audited through the `audit` subsystem, which writes structured events to SQLite and supports redaction, so governance decisions and agent actions are traceable and replayable.

9. **Server mode, triggers, and canarying**
Beyond CLI execution, `serve` turns a workspace into a persistent HTTP service with async jobs, streaming, webhook triggers, and auth. The `triggers` and `canary` modules connect external events and traffic routing to topologies, while auth providers (API key, JWT, none) and webhook verification form the request boundary for the service surface.

10. **Observability and run forensics**
Telemetry is a first-class subsystem: OpenTelemetry tracing/metrics, ring-buffered prompts, trace export, and run inspection are built in. This creates a second operational boundary alongside audit: audit records what happened, telemetry explains how it behaved, and trace tools reconstruct per-run execution graphs and token usage.

11. **Knowledge, documentation, and authoring**
The repo includes a knowledge-server/docs-reader path for LLM-friendly access to repository content, plus authoring-oriented flows for generating skills and topologies conversationally. These subsystems support the product’s “YAML, not code” workflow by helping users produce valid artifacts and by grounding agent behavior in local/reference knowledge.

12. **UI as a control plane**
`packages/ui` is a Next.js dashboard that presents topologies, skills, triggers, jobs, and canary status, with polling-based data refresh. It does not own execution; it consumes runtime-backed data and provides an operator-facing view over state, history, and run details.

13. **Reference implementations and examples**
`reference/` ships production-grade archetypes, skills, and topologies that define the canonical architecture patterns used by the runtime, while `examples/` shows real workspace shapes such as hello-world, content generation, and enterprise OMS workflows. These directories are effectively architecture exemplars and are useful for understanding how the abstract model maps to real deployments.

14. **Testing and contract enforcement**
The repo leans heavily on fixtures and tests around schema validity, compiler behavior, governance, MCP integration, triggers, and CLI/server flows. That test layout reflects the architecture itself: most regressions are prevented at the contract and compilation boundaries rather than by runtime-only checks.

Main entry points: [`packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py`](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py) (Skill executor), [`packages/runtime/src/swarmkit_runtime/server.py`](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/server.py) (Serve), [`packages/schema/schemas/workspace.schema.json`](https://github.com/delivstat/swarmkit/blob/main/packages/schema/schemas/workspace.schema.json) (Workspace model), [`packages/runtime/src/swarmkit_runtime/resolver/_resolved.py`](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_resolved.py) (Resolver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_contract["Contract Layer"]
  node_n_workspace_model["Workspace model<br/>declarative config"]
  node_n_entity_schemas["Entity schemas<br/>json schema set<br/>[skill.schema.json]"]
  node_n_ts_codegen["TS models<br/>codegen models<br/>[index.ts]"]
  node_n_py_models["Python models<br/>codegen models<br/>[workspace.py]"]
end

subgraph group_grp_runtime["Runtime Core"]
  node_n_discovery["Discovery<br/>workspace resolution<br/>[_env_config.py]"]
  node_n_resolver["Resolver<br/>canonicalization<br/>[_resolved.py]"]
  node_n_topology_loader["Topology loader<br/>dag loader<br/>[_topology.py]"]
  node_n_dag["DAG analysis<br/>dependency graph<br/>[_dag.py]"]
  node_n_compiler["LangGraph compiler<br/>workflow compiler<br/>[_compiler.py]"]
  node_n_plan_exec["Plan executor<br/>task planning<br/>[_task_plan.py]"]
  node_n_skill_exec["Skill executor<br/>skill runtime<br/>[_skill_executor.py]"]
  node_n_governance["Governance<br/>policy gate"]
  node_n_review["Review<br/>[_hitl.py]"]
  node_n_audit[("Audit<br/>[_sqlite.py]")]
  node_n_telemetry["Telemetry<br/>otel observability<br/>[_tracer.py]"]
  node_n_model_providers["Model providers<br/>llm abstraction<br/>[_registry.py]"]
  node_n_mcp["MCP client<br/>tool bridge<br/>[_client.py]"]
  node_n_docs_reader["Docs reader<br/>knowledge server<br/>[_server.py]"]
end

subgraph group_grp_surface["Operator Surfaces"]
  node_n_serve["Serve<br/>http service<br/>[server.py]"]
  node_n_auth["Auth<br/>[_registry.py]"]
  node_n_triggers["Triggers<br/>event ingress<br/>[_webhook.py]"]
  node_n_canary["Canary<br/>traffic routing<br/>[_router.py]"]
  node_n_ui["Dashboard<br/>nextjs ui<br/>[page.tsx]"]
end

subgraph group_grp_content["Workspaces"]
  node_n_reference["Reference packs<br/>example workspace<br/>[workspace.yaml]"]
  node_n_examples["Examples<br/>example workspaces<br/>[README.md]"]
end

node_n_workspace_model -->|"loads"| node_n_discovery
node_n_discovery -->|"normalizes"| node_n_resolver
node_n_resolver -->|"hydrates"| node_n_topology_loader
node_n_topology_loader -->|"analyzes"| node_n_dag
node_n_dag -->|"compiles"| node_n_compiler
node_n_compiler -->|"orchestrates"| node_n_plan_exec
node_n_plan_exec -->|"invokes"| node_n_skill_exec
node_n_skill_exec -->|"calls models"| node_n_model_providers
node_n_skill_exec -->|"uses tools"| node_n_mcp
node_n_governance -->|"escalates"| node_n_review
node_n_review -->|"approves"| node_n_skill_exec
node_n_skill_exec -->|"records"| node_n_audit
node_n_skill_exec -->|"traces"| node_n_telemetry
node_n_serve -->|"protects"| node_n_auth
node_n_serve -->|"accepts events"| node_n_triggers
node_n_triggers -->|"routes"| node_n_canary
node_n_serve -->|"runs"| node_n_compiler
node_n_ui -->|"reads state"| node_n_serve
node_n_reference -->|"exemplifies"| node_n_workspace_model
node_n_examples -->|"demonstrates"| node_n_workspace_model
node_n_docs_reader -->|"grounds"| node_n_resolver
node_n_entity_schemas -->|"codegen"| node_n_py_models
node_n_entity_schemas -->|"codegen"| node_n_ts_codegen

click node_n_workspace_model "https://github.com/delivstat/swarmkit/blob/main/packages/schema/schemas/workspace.schema.json"
click node_n_entity_schemas "https://github.com/delivstat/swarmkit/blob/main/packages/schema/schemas/skill.schema.json"
click node_n_ts_codegen "https://github.com/delivstat/swarmkit/blob/main/packages/schema/typescript/src/index.ts"
click node_n_py_models "https://github.com/delivstat/swarmkit/blob/main/packages/schema/python/src/swarmkit_schema/models/workspace.py"
click node_n_discovery "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_env_config.py"
click node_n_resolver "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_resolved.py"
click node_n_topology_loader "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_topology.py"
click node_n_dag "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_dag.py"
click node_n_compiler "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_compiler.py"
click node_n_plan_exec "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_task_plan.py"
click node_n_skill_exec "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py"
click node_n_governance "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/governance/_decision_evaluator.py"
click node_n_review "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/review/_hitl.py"
click node_n_audit "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/audit/_sqlite.py"
click node_n_telemetry "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/telemetry/_tracer.py"
click node_n_model_providers "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/model_providers/_registry.py"
click node_n_mcp "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/mcp/_client.py"
click node_n_serve "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/server.py"
click node_n_auth "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/auth/_registry.py"
click node_n_triggers "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/triggers/_webhook.py"
click node_n_canary "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/canary/_router.py"
click node_n_ui "https://github.com/delivstat/swarmkit/blob/main/packages/ui/app/dashboard/page.tsx"
click node_n_reference "https://github.com/delivstat/swarmkit/blob/main/reference/workspace.yaml"
click node_n_examples "https://github.com/delivstat/swarmkit/blob/main/examples/README.md"
click node_n_docs_reader "https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/docs_reader/_server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_workspace_model,node_n_entity_schemas,node_n_ts_codegen,node_n_py_models toneBlue
class node_n_discovery,node_n_resolver,node_n_topology_loader,node_n_dag,node_n_compiler,node_n_plan_exec,node_n_skill_exec,node_n_governance,node_n_review,node_n_audit,node_n_telemetry,node_n_model_providers,node_n_mcp,node_n_docs_reader toneAmber
class node_n_serve,node_n_auth,node_n_triggers,node_n_canary,node_n_ui toneMint
class node_n_reference,node_n_examples toneRose
```

## Components

### Contract Layer

Canonical schemas and generated models shared across runtime and UI.

- [Workspace model](https://github.com/delivstat/swarmkit/blob/main/packages/schema/schemas/workspace.schema.json): declarative config · Top-level YAML workspace boundary containing agents, skills, topologies, triggers, governance, auth, telemetry, and server settings. · `packages/schema/schemas/workspace.schema.json`
- [Entity schemas](https://github.com/delivstat/swarmkit/blob/main/packages/schema/schemas/skill.schema.json): json schema set · Canonical schemas for archetypes, skills, topologies, and triggers. · `packages/schema/schemas/skill.schema.json`
- [TS models](https://github.com/delivstat/swarmkit/blob/main/packages/schema/typescript/src/index.ts): codegen models · Generated TypeScript types that mirror the canonical schemas. · `packages/schema/typescript/src/index.ts`
- [Python models](https://github.com/delivstat/swarmkit/blob/main/packages/schema/python/src/swarmkit_schema/models/workspace.py): codegen models · Generated Python models that mirror the canonical schemas. · `packages/schema/python/src/swarmkit_schema/models/workspace.py`

### Runtime Core

Workspace resolution, compilation, execution, governance, and observability.

- [Discovery](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_env_config.py): workspace resolution · Finds a workspace and builds the runtime entry context. · `packages/runtime/src/swarmkit_runtime/resolver/_env_config.py`
- [Resolver](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_resolved.py): canonicalization · Normalizes raw YAML into a resolved workspace model for downstream subsystems. · `packages/runtime/src/swarmkit_runtime/resolver/_resolved.py`
- [Topology loader](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/resolver/_topology.py): dag loader · Loads topology definitions and prepares them for dependency analysis. · `packages/runtime/src/swarmkit_runtime/resolver/_topology.py`
- [DAG analysis](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_dag.py): dependency graph · Builds task/dependency structure before compilation. · `packages/runtime/src/swarmkit_runtime/langgraph_compiler/_dag.py`
- [LangGraph compiler](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_compiler.py): workflow compiler · Compiles the resolved topology into an executable LangGraph state graph. · `packages/runtime/src/swarmkit_runtime/langgraph_compiler/_compiler.py`
- [Plan executor](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_task_plan.py): task planning · Creates and runs task plans, task handlers, and execution state. · `packages/runtime/src/swarmkit_runtime/langgraph_compiler/_task_plan.py`
- [Skill executor](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py): skill runtime · Bridges archetypes, skills, delegation, and tool-loop execution. · `packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py`
- [Governance](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/governance/_decision_evaluator.py): policy gate · Evaluates tool use and output constraints before execution proceeds. · `packages/runtime/src/swarmkit_runtime/governance/_decision_evaluator.py`
- [Review](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/review/_hitl.py): hitl review · Human-in-the-loop review and approval boundary for sensitive actions. · `packages/runtime/src/swarmkit_runtime/review/_hitl.py`
- [Audit](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/audit/_sqlite.py): sqlite audit · Structured audit trail with redaction support for replayable run history. · `packages/runtime/src/swarmkit_runtime/audit/_sqlite.py`
- [Telemetry](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/telemetry/_tracer.py): otel observability · Tracing, metrics, ring-buffered prompts, and trace export. · `packages/runtime/src/swarmkit_runtime/telemetry/_tracer.py`
- [Model providers](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/model_providers/_registry.py): llm abstraction · Provider-agnostic model access across vendor backends and mock implementations. · `packages/runtime/src/swarmkit_runtime/model_providers/_registry.py`
- [MCP client](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/mcp/_client.py): tool bridge · Connects skills to external MCP-backed tools and servers. · `packages/runtime/src/swarmkit_runtime/mcp/_client.py`
- [Docs reader](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/docs_reader/_server.py): knowledge server · LLM-friendly repository/document access path used for grounding and authoring. · `packages/runtime/src/swarmkit_runtime/docs_reader/_server.py`

### Operator Surfaces

Persistent service, request boundary, and dashboard entry points.

- [Serve](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/server.py): http service · Persistent service mode with jobs, streaming, and workspace-backed APIs. · `packages/runtime/src/swarmkit_runtime/server.py`
- [Auth](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/auth/_registry.py): request auth · API key, JWT, and no-auth request boundary for the service surface. · `packages/runtime/src/swarmkit_runtime/auth/_registry.py`
- [Triggers](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/triggers/_webhook.py): event ingress · Webhook and scheduler ingress that routes events to topologies. · `packages/runtime/src/swarmkit_runtime/triggers/_webhook.py`
- [Canary](https://github.com/delivstat/swarmkit/blob/main/packages/runtime/src/swarmkit_runtime/canary/_router.py): traffic routing · Routes or splits traffic across topologies for canary-style operation. · `packages/runtime/src/swarmkit_runtime/canary/_router.py`
- [Dashboard](https://github.com/delivstat/swarmkit/blob/main/packages/ui/app/dashboard/page.tsx): nextjs ui · Read-only operator control plane for topologies, skills, jobs, and canary state. · `packages/ui/app/dashboard/page.tsx`

### Workspaces

Reference implementations and examples that demonstrate the declarative model.

- [Reference packs](https://github.com/delivstat/swarmkit/blob/main/reference/workspace.yaml): example workspace · Canonical production-grade archetypes, skills, and topologies for common patterns. · `reference/workspace.yaml`
- [Examples](https://github.com/delivstat/swarmkit/blob/main/examples/README.md): example workspaces · Runnable sample workspaces including hello-world, content, multimodal, and enterprise workflows. · `examples/README.md`

## Connections

- Workspace model → Discovery: loads · Workspace definition is the starting point for runtime discovery.
- Discovery → Resolver: normalizes · Discovery hands the raw workspace to resolution and canonicalization.
- Resolver → Topology loader: hydrates · Resolved workspace feeds topology materialization.
- Topology loader → DAG analysis: analyzes · Topology structure is converted into dependency graph form.
- DAG analysis → LangGraph compiler: compiles · Dependency analysis informs LangGraph compilation.
- LangGraph compiler → Plan executor: orchestrates · Compiled graph is executed through task planning and handlers.
- Plan executor → Skill executor: invokes · Task execution delegates into skill and tool execution.
- Skill executor → Model providers: calls models · Skills and delegated steps use provider-agnostic model access.
- Skill executor → MCP client: uses tools · Tool-backed skills reach external MCP servers through the client.
- Governance → Review: escalates · Governance decisions can require human review.
- Review → Skill executor: approves · Approved actions resume execution in the skill runtime.
- Skill executor → Audit: records · Execution events are written to the audit trail.
- Skill executor → Telemetry: traces · Runtime behavior is instrumented for observability.
- Serve → Auth: protects · HTTP surface is guarded by configured authentication.
- Serve → Triggers: accepts events · Service mode ingests webhook and scheduled triggers.
- Triggers → Canary: routes · Trigger ingress can be routed through canary policies.
- Serve → LangGraph compiler: runs · Persistent service ultimately drives compiled workflows.
- Dashboard → Serve: reads state · Dashboard consumes runtime-backed job and topology data.
- Reference packs → Workspace model: exemplifies · Reference packs demonstrate the declarative workspace contract.
- Examples → Workspace model: demonstrates · Examples show practical workspace shapes and flows.
- Docs reader → Resolver: grounds · Docs reader supports authoring and knowledge-grounded runtime flows.
- Entity schemas → Python models: codegen · Entity schemas are mirrored into Python models.
- Entity schemas → TS models: codegen · Entity schemas are mirrored into TypeScript types.
