Code Agent SDK for Swift
May 7, 2026 ยท View on GitHub
SwiftPM package for building Autohand-style code agents in Swift. It provides
Agent, Runner, async streams, provider abstractions, tools, hooks, loop
strategies, and permission controls.
Beta: this SDK is actively evolving while the Agent SDK APIs stabilize. Pin versions in production and review release notes before upgrading.
Other Programming Languages (Beta)
The Agent SDK is available in multiple beta language packages. Use the same Autohand code-agent model from another programming language:
- TypeScript -
Agent,Run, streaming, and JSON helpers for Node and Bun hosts. - Go - idiomatic Go package with
context.Context, typed events, and channel-based streaming. - Python - async Python package with
async forevent streams and typed Pydantic models. - Java - Java 21 records, sealed events, and virtual-thread-ready APIs.
- Swift - this SwiftPM package.
Requirements
- Swift 6.0+
- macOS 14+ or iOS 17+
- An OpenAI-compatible provider key for live provider-backed runs
Installation
Add the package to Package.swift:
dependencies: [
.package(url: "https://github.com/autohandai/code-agent-sdk-swift.git", branch: "main"),
]
Then depend on AgentSDK from your target:
.executableTarget(
name: "MyAgentApp",
dependencies: ["AgentSDK"]
)
Quick Start
import AgentSDK
import Foundation
let provider = OpenAIProvider(apiKey: ProcessInfo.processInfo.environment["OPENAI_API_KEY"]!)
let agent = Agent(
name: "Reviewer",
instructions: "Review code for correctness and maintainability.",
tools: [.readFile, .bash],
maxTurns: 10,
model: ModelID("gpt-4o"),
provider: provider,
cwd: FileManager.default.currentDirectoryPath
)
let result = try await Runner.runSync(
agent: agent,
prompt: "Summarize this package"
)
print(result)
Streaming
let stream = Runner.runStream(
agent: agent,
prompt: "Review Sources/Types.swift"
)
for try await event in stream {
switch event.type {
case .content:
print(event.data ?? "", terminator: "")
case .toolCall:
print("\n[tool: \(event.tool?.rawValue ?? "unknown")]")
case .done:
print("\nDone")
default:
break
}
}
Documentation
- Getting Started
- API Reference
- Configuration
- Event Streaming
- Error Handling
- Advanced Patterns
- Permissions
- Plan Mode
- Memory
- Migration
- SDLC Workflows
- Examples
Development
swift build
swift test