A Swift-only LLM and Agents SDK, modelled after the OpenAI Agents SDK and built around the Responses API shape. Lightweight, no third-party LLM dependencies beyond what the providers themselves require, and intended to work with any LLM that can be coaxed into the Responses protocol.
Early. Split out from the private AgentCorp project so the public agent surface can stand on its own. APIs will move.
Providers— wire-level LLM provider clients: OpenAI (Responses + Chat + Embeddings + Assistants + Conversations + Realtime + Image Generation), Anthropic Messages, Google Gemini, Ollama, and LM Studio (native stateful chat). Cross-platform.Agents— the agent runtime built on top ofProviders:Runner, theAgentprotocol andBasicAgent, handoffs, guardrails, and agent-tier Realtime. The Tool DSL is powered by SwiftMCP;applyDiffhandles V4A-style patches.SwiftAgents— umbrella product;import SwiftAgentsre-exportsProviders,Tracing, andAgents.Tracing— provider-agnostic tracing primitives (TraceProvider,TraceSpan,withSpan, …) thatProvidersandAgentsbuild on.SemanticStore— semantic-search stores behind oneSemanticStoreprotocol: the in-memoryLocalVectorStore, the hostedOpenAIVectorStore, and the persistentSQLiteVectorStore(opt-in via theSQLiteVectorStorepackage trait). See Docs/SemanticStore.md.TerminalUI— ANSI colours, slash-command parser, terminal handler. Used by the bundled CLI; reusable by other tools.Coder— an in-process coding-agent CLI (executable target). Tool surface:bash,read,write,edit,ls,grep,find, plusapply_patchfor models that support it. Also runs as an ACP agent:swift run Coder acpserves the Agent Client Protocol on stdio (via SwiftACP), so editors like Zed can drive it — including the client's per-session MCP servers and per-session model switching (--model,/model, or the nativesession/set_model). Reference implementation of anAgentagainst the Responses API.imagegen— a command-line client for the OpenAI Images API (a Swift port of Codex'simage_gen.py):generate,editandgenerate-batchwith exact control over model (gpt-image-2.5-sunburst,gpt-image-2.5-flare,gpt-image-2), size, quality, background and format. The same client is available to any Swift program asOpenAI.generateImages(_:),editImages(_:)andgenerateImageBatch(_:)inProviders.
There are no tagged releases yet (see Status), so depend on main for now — version tags will follow once the API settles:
.package(url: "https://github.com/Cocoanetics/SwiftAgents", branch: "main")Then in your target — the umbrella product re-exports Providers, Tracing, and Agents:
.product(name: "SwiftAgents", package: "SwiftAgents")(Note that a branch: dependency can't ship inside your own tagged releases; treat it as development-only until SwiftAgents tags a version.)
Define an agent and run it:
import SwiftAgents
let agent = BasicAgent(
name: "Assistant",
model: "gpt-4.1", // or "claude-sonnet-4-5", "gemini-2.5-flash", "lmstudio/qwen3-coder", …
instructions: "You are a helpful assistant. Answer concisely."
)
let result = try await Runner.run(agent: agent, input: "What is an actor in Swift?")
print(result.finalOutput) // BasicAgent's OutputType is StringOr streamed, printing text deltas as they arrive:
let streamed = Runner.runStreamed(agent: agent, input: "Explain Swift concurrency.")
for try await event in streamed.events {
if case let .rawResponseEvent(raw) = event,
case let .outputTextDelta(info) = raw.object {
print(info.delta, terminator: "")
}
}See Docs/Agents.md for the full tour: structured output, tools, conversation continuity, streaming events, and RunConfig.
Tests and the bundled CLI look for these environment variables. The test suite loads them from the nearest .env with its own tolerant loader (Tests/ProvidersTests/APIKey.swift, which skips present-but-empty keys); the Coder CLI loads .env via swift-dotenv on Apple platforms and Linux:
| Variable | Used by |
|---|---|
OPENAI_API_KEY |
OpenAI client + integration tests |
GEMINI_API_KEY |
Google client + integration tests |
ANTHROPIC_API_KEY |
Anthropic client + integration tests |
OLLAMA_URL |
Ollama client (defaults to http://localhost:11434) |
LMSTUDIO_URL |
LM Studio client — local OpenAI-compatible endpoint (defaults to http://localhost:1234) |
LMSTUDIO_MODEL |
Model pin for the LM Studio live tests (tool calls, structured output) |
LMSTUDIO_EMBED_MODEL |
Embedding model for the hybrid-search live tests (default text-embedding-nomic-embed-text-v1.5) |
LMSTUDIO_VISION_MODEL |
Vision model for the LM Studio image-input tests |
LOCAL_LLM_URL |
Generic OpenAI-compatible local server for the embedding live tests |
RUN_OLLAMA_TESTS |
Set to 1 to opt into the live Ollama chat suites (also needs a reachable OLLAMA_URL) |
LIVE_STATE_TESTS |
Set to 1 to opt into live tests that mutate hosted OpenAI state (vector stores, conversations — also needs OPENAI_API_KEY) |
Local-server suites (LM Studio, Ollama, LOCAL_LLM_URL) additionally probe
reachability and skip when nothing is listening, so an offline swift test
passes with keys configured.
A .env.example is provided; copy it to .env and fill in your keys. .env is gitignored.
swift build
swift test # full suite (integration tests need keys)
swift test --filter LocalVectorStore # offline-only
swift run Coder --help # the Coder CLI
swift run Coder acp # serve Coder over ACP on stdio
swift run imagegen generate --prompt "…" --dry-run # the Images API CLIThe agent runtime is a Swift port of the patterns in openai-agents-python. The Responses wire types are aligned with OpenAI's public spec; other providers (Gemini, Ollama) adapt their native shapes into that contract.
MIT — see LICENSE.