Skip to content

rebornix/acp-swift-sdk

Repository files navigation

ACP Swift SDK

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.

Features

  • 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

Requirements

  • Swift 6.0+
  • macOS 13+, iOS 16+, watchOS 9+, tvOS 16+, visionOS 1+

Installation

Swift Package Manager

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"]
)

Examples

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 run

Quick Overview

import 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()

Transports

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

Available Methods

Stable

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

Draft RFD (API may change)

Method Description
SessionList List available sessions
SessionResume Resume a paused session
SessionFork Fork a session

See SCHEMA_VERSION.md for complete API status.

Notifications

Handle streaming updates from the agent:

Notification Description
SessionUpdateNotification Message chunks, tool calls, plans
InitializedNotification Initialization complete

Architecture

  • 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

Documentation

Contributing

Contributions are welcome! Please read the contributing guidelines first: CONTRIBUTING.md

License

MIT License - see LICENSE for details.

About

ACP swift library for https://github.com/rebornix/Agmente

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages