SKILL.md--- name: agent-squad-swift description: >- Use when building or modifying a Swift app that uses the AgentSquad Swift framework — on-device multi-agent orchestration for iOS 16+ / macOS 14+: orchestrator, agents (Agent, GroundedAgent), classifier routing, LLM clients (OpenAI-compatible), tools (native + MCP), tool UIs/widgets, on-device storage, tracing, and realtime voice — built-in types and custom implementations. --- # AgentSquad Swift — assistant guide Protocol-driven, on-device multi-agent framework (Swift 6.2, iOS 16+ / macOS 14+; persistence via `FileChatStorage` on iOS 16+, `DeviceChatStorage` on iOS 17+). This is guidance and a map — **not an API reference**. Read the exact signatures from the source (`swift/Sources/AgentSquad/`) and the worked recipes from the docs site sources (`docs/src/content/docs/swift/`); this file tells you *what to use, when, and what to watch out for*. ## When to use what - **One assistant** → an `Agent` (or `GroundedAgent`) + an `Orchestrator` with no classifier. No routing hop. - **Several specialists** → multiple agents + an `LLMClassifier`; the orchestrator routes each turn. - **Answers must not drift from data** (prices, stock, balances) → `GroundedAgent`: a Brain calls tools, an isolated Presenter speaks only from the curated results (it can be a smaller/local model). - **Voice** → a `VoiceAssistant` (a peer of the orchestrator, not an agent): `OpenAIVoiceAssistant` (single LLM + tools, speaks directly — the spoken analog of `Agent`) or `OpenAIGroundedVoiceAssistant` (Brain → Presenter, can't drift from data — analog of `GroundedAgent`). Every component is a `Sendable` protocol with one built-in implementation — swap in your own anywhere. ## Modules (import only what you use) | Import | Pulls in | Contents | |---|---|---| | `AgentSquad` | nothing external | protocols, `Agent`, `GroundedAgent`, `Orchestrator`, `LLMClassifier`, `ChatCompletionsClient`, `DakeraRetriever`, `FileChatStorage`, `DeviceChatStorage`, `InMemoryChatStorage`, `TransformingChatStorage`, `SummarizingChatStorage`, `OSLogTracer`, OTLP export | | `AgentSquadMCP` | MCP Swift SDK | `MCPServer` (= `MCPToolProvider`), `SDKMCPClient` | | `AgentSquadAudio` | AVFoundation | `VoiceProcessedAudioIO` (capture+playback, one engine, AEC — the recommended wiring), `MicCapture` (voice-processed/AEC by default), `AudioPlayback`, `VoiceProcessing`, `AudioSessionPolicy` (needs `NSMicrophoneUsageDescription`) | SwiftPM: `.package(url: "https://github.com/2FastLabs/agent-squad", branch: "main")`. ## How a turn works Two peer runtimes share contracts but not a control loop: a turn-based **`Orchestrator`** (`classify? → run agent → stream → persist`) and a long-lived **`VoiceAssistant`** for voice. Either way you consume an `AsyncThrowingStream<AgentEvent, any Error>` — the one idiom worth memorizing: ```swift for try await event in orchestrator.route(.text("h