惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
D
DataBreaches.Net
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Y
Y Combinator Blog
博客园 - 【当耐特】
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
量子位
C
Check Point Blog
F
Fortinet All Blogs
罗磊的独立博客
Last Week in AI
Last Week in AI
GbyAI
GbyAI
L
LangChain Blog
博客园 - 司徒正美

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Open Agent SDK (Swift): Build AI Agent Applications with ...
NEE · 2026-04-27 · via DEV Community

If you're a Swift developer looking to integrate AI Agent capabilities into your macOS apps, the options are slim. Most Agent frameworks are built for Python or TypeScript, leaving the Swift ecosystem with virtually no mature solutions. Open Agent SDK (Swift) was created to fill that gap.

What Is It?

Open Agent SDK is written in Swift 6.1 and requires macOS 13+. It runs the entire Agent Loop in-process: sending prompts, parsing responses, executing tool calls, feeding results back to the LLM, and repeating until a final answer is reached. The whole process is driven by native Swift concurrency (async/await, AsyncStream).

The project is inspired by open-agent-sdk-typescript, bringing the same Agent architecture to the Swift ecosystem. A Go version also exists in the same family.

Quick Start

Add the dependency in your Package.swift:

dependencies: [
    .package(url: "https://github.com/terryso/open-agent-sdk-swift.git", from: "0.1.0")
]

Enter fullscreen mode Exit fullscreen mode

A few lines of code to get an Agent running:

import OpenAgentSDK

let agent = createAgent(options: AgentOptions(
    apiKey: "sk-...",
    model: "claude-sonnet-4-6",
    systemPrompt: "You are a helpful assistant.",
    maxTurns: 10
))

let result = await agent.prompt("Explain Swift concurrency in one paragraph.")
print(result.text)
print("Used \(result.usage.inputTokens) input + \(result.usage.outputTokens) output tokens")

Enter fullscreen mode Exit fullscreen mode

prompt() is blocking — a single call completes the entire Agent Loop. For streaming output, use stream():

for await message in agent.stream("Read Package.swift and summarize it.") {
    switch message {
    case .partialMessage(let data):
        print(data.text, terminator: "")
    case .toolUse(let data):
        print("Using tool: \(data.toolName)")
    case .result(let data):
        print("\nDone (\(data.numTurns) turns, $\(String(format: "%.4f", data.totalCostUsd)))")
    default:
        break
    }
}

Enter fullscreen mode Exit fullscreen mode

Core Architecture

Your App (import OpenAgentSDK)
  └── Agent (prompt() / stream())
        └── Agentic Loop (API call → tool execution → repeat)
              ├── LLMClient Protocol (AnthropicClient / OpenAIClient)
              ├── 34 Built-in Tools
              ├── MCP Server Integration
              ├── Session Store (JSON Persistence)
              └── Hook Registry (20+ Lifecycle Events)

Enter fullscreen mode Exit fullscreen mode

  • LLMClient Protocol: Abstracts LLM providers. Currently supports Anthropic (Claude) and OpenAI-compatible APIs (GLM, Ollama, OpenRouter, etc.). Supports runtime model switching with per-model billing.
  • Agent Loop: Automatically manages multi-turn conversations, tool calls, budget control, and auto-compaction.
  • Tool System: 34 built-in tools organized in three tiers — Core (10), Advanced (11), and Specialist (13). Supports defineTool() for custom tools with automatic Codable decoding.
  • MCP Integration: Supports stdio, SSE, HTTP, and in-process transports. MCP tools are automatically discovered and merged into the tool pool.
  • Multi-Agent Collaboration: Generate sub-agents via AgentTool (built-in Explore and Plan types), track task progress with the Task system, and support inter-agent communication via Team + Mailbox.
  • Session Persistence: Save, restore, and fork conversation history with three recovery strategies.
  • Permissions & Security: 6 permission modes + composable policies (allowlist, denylist, read-only) + sandboxing (path and command filtering) + Hook system (24 lifecycle events with interception and input modification).
  • Skills System: 5 built-in Skills (Commit, Review, Simplify, Debug, Test) with filesystem auto-discovery for custom Skills.
  • Thinking/Effort Configuration: Control LLM deep thinking capability and token budgets, with runtime dynamic adjustment.

Project Status

The SDK comes with 31 example projects covering basic usage, streaming, custom tools, MCP integration, session management, multi-agent collaboration, permission control, sandboxing, model switching, and more. The codebase is organized into nine modules — API, Core, Hooks, MCP, Skills, Stores, Tools, Types, and Utils — totaling approximately 90 Swift source files, released under the MIT license.

Subsequent articles in this series will dive deep into each subsystem's implementation details.


Deep Dive into Open Agent SDK (Swift) Series:

GitHub: terryso/open-agent-sdk-swift