How delivstat/swarmkit works
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: _skill_executor.py Skill executor · server.py Serve · workspace.schema.json Workspace model · _resolved.py Resolver
Components 25
Contract Layer
Canonical schemas and generated models shared across runtime and UI.
- Workspace model · Top-level YAML workspace boundary containing agents, skills, topologies, triggers, governance, auth, telemetry, and server settings.
packages/schema/schemas/workspace.schema.json - Entity schemas · Canonical schemas for archetypes, skills, topologies, and triggers.
packages/schema/schemas/skill.schema.json - TS models · Generated TypeScript types that mirror the canonical schemas.
packages/schema/typescript/src/index.ts - Python 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 · Finds a workspace and builds the runtime entry context.
packages/runtime/src/swarmkit_runtime/resolver/_env_config.py - Resolver · Normalizes raw YAML into a resolved workspace model for downstream subsystems.
packages/runtime/src/swarmkit_runtime/resolver/_resolved.py - Topology loader · Loads topology definitions and prepares them for dependency analysis.
packages/runtime/src/swarmkit_runtime/resolver/_topology.py - DAG analysis · Builds task/dependency structure before compilation.
packages/runtime/src/swarmkit_runtime/langgraph_compiler/_dag.py - LangGraph compiler · Compiles the resolved topology into an executable LangGraph state graph.
packages/runtime/src/swarmkit_runtime/langgraph_compiler/_compiler.py - Plan executor · Creates and runs task plans, task handlers, and execution state.
packages/runtime/src/swarmkit_runtime/langgraph_compiler/_task_plan.py - Skill executor · Bridges archetypes, skills, delegation, and tool-loop execution.
packages/runtime/src/swarmkit_runtime/langgraph_compiler/_skill_executor.py - Governance · Evaluates tool use and output constraints before execution proceeds.
packages/runtime/src/swarmkit_runtime/governance/_decision_evaluator.py - Review · Human-in-the-loop review and approval boundary for sensitive actions.
packages/runtime/src/swarmkit_runtime/review/_hitl.py - Audit · Structured audit trail with redaction support for replayable run history.
packages/runtime/src/swarmkit_runtime/audit/_sqlite.py - Telemetry · Tracing, metrics, ring-buffered prompts, and trace export.
packages/runtime/src/swarmkit_runtime/telemetry/_tracer.py - Model providers · Provider-agnostic model access across vendor backends and mock implementations.
packages/runtime/src/swarmkit_runtime/model_providers/_registry.py - MCP client · Connects skills to external MCP-backed tools and servers.
packages/runtime/src/swarmkit_runtime/mcp/_client.py - Docs reader · 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 · Persistent service mode with jobs, streaming, and workspace-backed APIs.
packages/runtime/src/swarmkit_runtime/server.py - Auth · API key, JWT, and no-auth request boundary for the service surface.
packages/runtime/src/swarmkit_runtime/auth/_registry.py - Triggers · Webhook and scheduler ingress that routes events to topologies.
packages/runtime/src/swarmkit_runtime/triggers/_webhook.py - Canary · Routes or splits traffic across topologies for canary-style operation.
packages/runtime/src/swarmkit_runtime/canary/_router.py - Dashboard · 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 · Canonical production-grade archetypes, skills, and topologies for common patterns.
reference/workspace.yaml - Examples · Runnable sample workspaces including hello-world, content, multimodal, and enterprise workflows.
examples/README.md
Connections 23
- 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.