Skip to content

Repository files navigation

swift-a2a

English | 日本語

A Swift implementation of the A2A (Agent2Agent) protocol — client, server, and an in-process binding for testing.

Unofficial. Not affiliated with or endorsed by the authors of the A2A protocol. Conforming to the specification is not a goal of this project.

Swift A2A Platforms License

Features

  • Two bindings, one API — REST (HTTP+JSON, spec §11) and JSON-RPC 2.0 (§9), which the spec requires to be functionally equivalent. Pick whichever an agent's card advertises; nothing else changes
  • ProtoJSON-shaped wire formatROLE_USER-style enum names, camelCase fields, discriminator-less oneofs, RFC 3339 timestamps. Where a type departs from the Protocol Buffer definition on purpose, that type's own documentation says so
  • Write a server by writing one type — conform to AgentExecutor, hand it to DefaultRequestHandler, serve it through a transport-agnostic dispatcher
  • Test without a networkA2AClient.inProcess(handler:) connects a client straight to a handler, no HTTP and no serialization
  • SSE streamingmessage:stream and tasks:subscribe, with a parser that does not lose event boundaries
  • Type-safe and idiomatic — oneofs as enums, typed identifiers, @resultBuilder message construction
  • Two dependencies — Foundation and swift-structured-data. No gRPC, no swift-syntax, no macros

Quick Start

import A2AClientREST   // or A2AClientJSONRPC

let client = A2AClient.rest(
    baseURL: URL(string: "https://agent.example.com/a2a/v1")!,
    authentication: .bearer("your-token")
)

let response = try await client.sendMessage(.user("Create a sales report"))

switch response {
case .task(let task):
    print(task.status.state)
    print(task.artifacts.first?.parts.first?.text ?? "")
case .message(let message):
    print(message.text)
}

Streaming, task operations, push notification configuration, and the server side are covered in the documentation.

Documentation

Each library has its own DocC page:

Installation

Add the package to your Package.swift:

dependencies: [
    .package(url: "https://github.com/no-problem-dev/swift-a2a.git", .upToNextMinor(from: "0.8.0"))
]

Then add the products you need — the client binding for talking to an agent, the server ones for hosting:

.target(name: "YourTarget", dependencies: [
    .product(name: "A2AClientREST", package: "swift-a2a"),
    // .product(name: "A2AClientJSONRPC", package: "swift-a2a"),
])

Requirements

swift-a2a Swift Platforms
0.x 6.2+ iOS 17+ · macOS 14+ · tvOS 17+ · watchOS 10+ · visionOS 1+ · Linux

Targets A2A revision 1.0.1. The gRPC binding is not implemented.

License

MIT. See LICENSE.

About

Swift implementation of the A2A (Agent2Agent) protocol v1.0 — client, server, and in-process, with REST and JSON-RPC bindings and SSE streaming

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages