$ show christopherkarani/Swarm
Swarm is a production-grade Swift-native agent runtime framework for building multi-agent conversational systems with type-safe tools, on-device Apple Foundation Models, composable workflows, memory, guardrails, and observability. The architecture is modular: core agent execution (Agent, Workflow, Job) with pluggable inference providers (Foundation Models, OpenAI-compatible, mock), memory backends (conversation, sliding window, summary, vector, persistent via SwiftData or Wax SQLite), and tool integration (built-in tools, MCP protocol, web search). Key entry points include Agent.run()/stream(), Workflow.execute(), and the SwarmMCPServerService for exposing tools via MCP. Data flows involve agent turns with tool calls, memory retrieval/consolidation, and durable workflow checkpointing via the HiveCore deterministic runtime. External dependencies include Apple FoundationModels (macOS 26+), swift-log, swift-syntax (for macros), and optional Wax (SQLite vector store) and OpenTelemetry SDK. The framework emphasizes compile-time safety via @Tool and @Agent macros, and provides resilience patterns (retry, fallback, circuit breaker, rate limiting) and observability (tracing, metrics, OpenTelemetry).
The LLM identified 6 files worth highlighting for reuse:
A fixed-size, thread-safe circular buffer implemented as a generic struct with automatic eviction. Demonstrates efficient memory management and safe concurrent access without locks, reusable for any bounded collection need.
A one-shot async race primitive that settles on the first completed outcome (success, timeout, cancellation) with a pre-install replay mechanism. Provides a clean abstraction for timeout/cancellation in agent runs, extractable for any async race scenario.
A pure Swift recursive descent arithmetic expression parser that avoids NSExpression for cross-platform compatibility. Demonstrates tokenization, operator precedence, and error handling without external dependencies, reusable for any expression evaluation.
Standard implementations of common reducers (last-write-wins, sum, min, max, append, set union, dictionary merge) for deterministic state management in the Hive event-sourced runtime. Each reducer is a pure function with clear semantics, reusable for any event-sourced system.
An immutable chain of fallback steps with conditions, guaranteed fallback, and failure callbacks. Provides a fluent builder for composing degradation strategies in agent inference, extractable for any resilience layer.
A tracer implementation that fans out events to multiple child tracers with configurable forwarding (parallel/sequential) and level filtering. Enables multi-channel observability without coupling, reusable for any composite observer pattern.