Examples
Short, complete programs you can drop into an executable SwiftPM target and run. Unlike the focused snippets on the capability pages, each example here is a whole program: imports, model, tools, agent, and one turn streamed to stdout.
| Example | Shows |
|---|---|
| Local tool | ToolKit + Tool.local — Swift functions as tools |
| API tools | HTTPToolGroup — REST endpoints as tools, no handler code |
| MCP server | MCPServer(url:) + Orchestrator — tools from a remote MCP server |
Running an example
Section titled “Running an example”Add an executable target that depends on AgentSquad (and AgentSquadMCP for the MCP example):
.executableTarget(name: "demo", dependencies: [ .product(name: "AgentSquad", package: "agent-squad"),])Then set your key and run:
OPENAI_API_KEY=sk-… swift run demoEach example reads OPENAI_API_KEY from the environment and points ChatCompletionsClient at OpenAI by default — pass a baseURL: to target Azure, OpenRouter, Groq, or a local Ollama/llama.cpp.