Skip to content

JamieScanlon/SwiftAgentKit

Repository files navigation

SwiftAgentKit

A Swift framework for building AI agents with support for Model Context Protocol (MCP) and Agent-to-Agent (A2A) communication.

Overview

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.

Modules

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

Quick Start

Installation

Add SwiftAgentKit to your project:

dependencies: [
    .package(url: "https://github.com/JamieScanlon/SwiftAgentKit.git", from: "0.1.3")
]

Importing Modules

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

Basic Usage

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

Local Function Tools (EasyJSON)

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

Examples

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 RawFunctionToolsExample

Documentation

LLM wrappers & state (read this when integrating an app):

  • LLM state and observationStatefulLLM, QueuedLLM, LLMRuntimeState, LLMRequestState, AgenticLoopState, and what to subscribe to.

Module guides:

Logging

All modules use Swift Logging for structured logging, providing cross-platform logging capabilities for debugging and monitoring.

Requirements

  • macOS 13.0+
  • Swift 5.9+

License

MIT License - see LICENSE file for details.

About

A set of tools for building local AI agents in swift. MCP, A2A, intercommunication, etc.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages