SwiftAgentKit

A Swift-native SDK for building autonomous AI agents - protocol-based providers for OpenAI, Anthropic, and Apple Foundation Models, with a structured-concurrency agent loop.

Every agent SDK I’d used - Vercel’s AI SDK, LangChain - was built for JavaScript or Python. Swift’s async/await and structured concurrency model is genuinely good for this kind of work, and I wanted the same tool-calling agent loop pattern, but built the way Swift actually wants it written, not ported awkwardly from another language’s concurrency model.

Providers as a protocol, not a hardcoded choice

LanguageModelProvider is the one abstraction everything else builds on - OpenAIProvider, AnthropicProvider, and FoundationProvider (Apple’s on-device Foundation Models) all conform to it, so swapping which model an agent talks to is a matter of passing a different provider, not rewriting the agent.

Tool is the other core protocol: any tool an agent can call declares a JSON schema for its inputs, which get validated before the model’s tool call is actually executed. The Agent type runs the loop itself - select a tool, execute it, feed the result back, continue - with AgentContext holding conversation memory behind a pluggable storage interface, so persistence isn’t hardcoded to one backend.

Fully async, fully structured

Everything is async/await with Swift’s structured concurrency underneath - no callback-based provider APIs, no unstructured Task { } calls scattered through the agent loop. That mirrors the same discipline I ended up using later in Drift for structured concurrency, but here it’s the entire point of the package rather than one part of it.

Key decisions

Built with