A Swift client library for the Agent Client Protocol (ACP).
This repo exists to save you SOTA model tokens (and your sanity) by not regenerating a Swift client from the ACP spec yourself. It’s agent‑native and agent‑first: we actively use agents to maintain this library, so test coverage matters and the agent harness must stay current. For contributions, please file an issue first with enough context for both the implementation/fix and agent validation.
ACP is a JSON-RPC 2.0 protocol for communication between ACP clients and agents.
- Type-safe RPC methods with Swift generics
- Actor-based concurrency for thread safety
- Multiple transport options (WebSocket, Stdio)
- Full protocol support including streaming updates
- Swift 6 strict concurrency
- Swift 6.0+
- macOS 13+, iOS 16+, watchOS 9+, tvOS 16+, visionOS 1+
Add the following to your Package.swift:
dependencies: [
.package(url: "https://github.com/rebornix/acp-swift-sdk.git", from: "1.0.0")
]Then add ACP to your target dependencies:
.target(
name: "YourTarget",
dependencies: ["ACP"]
)See the Examples directory for runnable code samples:
| Example | Description |
|---|---|
| BasicUsage | Connect to an ACP agent and send prompts with streaming |
| WebSocketUsage | Connect to a remote ACP agent over WebSocket |
To run an example:
cd Examples/BasicUsage
swift runimport ACP
// Create a client
let client = Client(name: "MyApp", version: "1.0.0")
// Connect via stdio (ACP standard transport)
let transport = StdioTransport()
let initResult = try await client.connect(transport: transport)
// Create a session and send a prompt
let session = try await client.send(SessionNew.request(id: .random, ...))
let result = try await client.send(SessionPrompt.request(id: .random, ...))
// Disconnect when done
await client.disconnect()ACP uses stdio as the standard transport - agents run as subprocesses.
| Transport | Use Case |
|---|---|
StdioTransport |
Standard ACP transport (subprocess stdin/stdout) |
WebSocketTransport |
Custom transport for WebSocket servers |
InMemoryTransport |
Testing with paired transports |
| Method | Description |
|---|---|
Initialize |
Negotiate versions and capabilities |
SessionNew |
Create a new session |
SessionLoad |
Load an existing session |
SessionPrompt |
Send a prompt |
SessionCancel |
Cancel an active prompt |
SessionSetMode |
Set session mode |
| Method | Description |
|---|---|
SessionList |
List available sessions |
SessionResume |
Resume a paused session |
SessionFork |
Fork a session |
See SCHEMA_VERSION.md for complete API status.
Handle streaming updates from the agent:
| Notification | Description |
|---|---|
SessionUpdateNotification |
Message chunks, tool calls, plans |
InitializedNotification |
Initialization complete |
- Transport Protocol - Abstraction for connection types
- Method Protocol - Type-safe RPC with associated types
- Actor-based Client - Thread-safe operation handling
- Handler Boxes - Type erasure for notification handlers
- AGENTS.md - Instructions for AI coding agents
- SCHEMA_VERSION.md - API stability status
- .github/skills/ - Agent skills (schema-sync, test-agents, etc.)
Contributions are welcome! Please read the contributing guidelines first: CONTRIBUTING.md
MIT License - see LICENSE for details.