Skip to content

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.

ExampleShows
Local toolToolKit + Tool.local — Swift functions as tools
API toolsHTTPToolGroup — REST endpoints as tools, no handler code
MCP serverMCPServer(url:) + Orchestrator — tools from a remote MCP server

Add an executable target that depends on AgentSquad (and AgentSquadMCP for the MCP example):

Package.swift
.executableTarget(name: "demo", dependencies: [
.product(name: "AgentSquad", package: "agent-squad"),
])

Then set your key and run:

Terminal window
OPENAI_API_KEY=sk-… swift run demo

Each 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.