A Swift framework for building AI agents with support for Model Context Protocol (MCP) and Agent-to-Agent (A2A) communication.
SwiftAgentKit provides a modular foundation for building AI agents that can:
- Connect to MCP-compliant model servers and tools
- Communicate with other A2A-compliant agents
- Register local function tools with EasyJSON arguments
- Make HTTP requests and handle streaming responses
- Execute shell commands and manage subprocesses
- Use structured logging for debugging and monitoring
- Integrate with popular AI providers (OpenAI, Anthropic, Gemini)
- Build composable tool-aware adapters with A2A and MCP capabilities
- Extend agents with Agent Skills for modular, on-demand instruction sets
The framework is designed with a simple, direct API - no unnecessary abstractions or configuration objects.
| Module | Description | Documentation |
|---|---|---|
| SwiftAgentKit | Core networking and utilities | SwiftAgentKit.md · LLM state & observation (StatefulLLM, QueuedLLM, state types) |
| SwiftAgentKitMCP | Model Context Protocol support | MCP.md |
| SwiftAgentKitA2A | Agent-to-Agent communication | A2A.md |
| SwiftAgentKitAdapters | AI provider adapters and tool-aware architecture | SwiftAgentKitAdapters.md |
| SwiftAgentKitOrchestrator | LLM orchestrator with MCP and A2A support | SwiftAgentKitOrchestrator.md · README |
| SwiftAgentKitSkills | Agent Skills specification support | SwiftAgentKitSkills.md |
Add SwiftAgentKit to your project:
dependencies: [
.package(url: "https://github.com/JamieScanlon/SwiftAgentKit.git", from: "0.1.3")
]Add the products you want to use to your target dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "SwiftAgentKit", package: "SwiftAgentKit"),
.product(name: "SwiftAgentKitA2A", package: "SwiftAgentKit"), // Optional
.product(name: "SwiftAgentKitMCP", package: "SwiftAgentKit"), // Optional
.product(name: "SwiftAgentKitAdapters", package: "SwiftAgentKit"), // Optional
.product(name: "SwiftAgentKitSkills", package: "SwiftAgentKit"), // Optional
]
)import SwiftAgentKit
import SwiftAgentKitMCP
import SwiftAgentKitA2A
import SwiftAgentKitAdapters
// Use the modules as needed
let apiManager = RestAPIManager()
let mcpManager = MCPManager()
let a2aManager = A2AManager()
// Create AI adapters with tool capabilities
let adapter = AdapterBuilder()
.withLLM(OpenAIAdapter(apiKey: "your-key"))
.build()
print("SwiftAgentKit initialized")import SwiftAgentKit
let localConfig = LocalFunctionToolsConfig(functions: [
LocalFunctionDefinition(
name: "get_weather",
description: "Get weather by city",
parameters: [
.init(name: "city", description: "City name", type: "string", required: true)
]
)
])
let provider = LocalFunctionToolProvider(config: localConfig) { toolName, arguments, toolCallId in
guard case .object(let args) = arguments,
case .string(let city) = args["city"] else {
return ToolResult(success: false, content: "", toolCallId: toolCallId, error: "Missing city argument")
}
return ToolResult(success: true, content: "Weather in \(city): sunny", toolCallId: toolCallId)
}
let toolManager = ToolManager(providers: [provider])Run the examples to see SwiftAgentKit in action:
# Basic networking example
swift run BasicExample
# MCP client example
swift run MCPExample
# A2A client example
swift run A2AExample
# AI adapters example
swift run AdaptersExample
# Tool-aware adapters example
swift run ToolAwareExample
# LLM orchestrator example
swift run OrchestratorExample
# Raw function tools example
swift run RawFunctionToolsExampleLLM wrappers & state (read this when integrating an app):
- LLM state and observation —
StatefulLLM,QueuedLLM,LLMRuntimeState,LLMRequestState,AgenticLoopState, and what to subscribe to.
Module guides:
- SwiftAgentKit Module — Core networking, utilities, logging bootstrap
- LLMProtocolAdapter — A2A adapter,
agenticLoopUpdates, per-call FIFO notes - Agentic loop pattern — Tool loop behavior inside
LLMProtocolAdapter - SwiftAgentKitOrchestrator — Orchestrator,
agenticLoopUpdates - MCP Module — Model Context Protocol
- A2A Module — Agent-to-Agent
- SwiftAgentKitAdapters Module — Provider adapters and tool-aware architecture
- SwiftAgentKitSkills Module — Agent Skills specification
All modules use Swift Logging for structured logging, providing cross-platform logging capabilities for debugging and monitoring.
- macOS 13.0+
- Swift 5.9+
MIT License - see LICENSE file for details.