Skip to content

autohandai/code-agent-sdk-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Agent SDK for Swift

SwiftPM package for building Autohand-style code agents in Swift. It provides Agent, Runner, async streams, provider abstractions, tools, hooks, loop strategies, and permission controls.

Beta: this SDK is actively evolving while the Agent SDK APIs stabilize. Pin versions in production and review release notes before upgrading.

Other Programming Languages (Beta)

The Agent SDK is available in multiple beta language packages. Use the same Autohand code-agent model from another programming language:

  • TypeScript - Agent, Run, streaming, and JSON helpers for Node and Bun hosts.
  • Go - idiomatic Go package with context.Context, typed events, and channel-based streaming.
  • Python - async Python package with async for event streams and typed Pydantic models.
  • Java - Java 21 records, sealed events, and virtual-thread-ready APIs.
  • Swift - this SwiftPM package.

Requirements

  • Swift 6.0+
  • macOS 14+ or iOS 17+
  • An OpenAI-compatible provider key for live provider-backed runs

Installation

Add the package to Package.swift:

dependencies: [
    .package(url: "https://github.com/autohandai/code-agent-sdk-swift.git", branch: "main"),
]

Then depend on AgentSDK from your target:

.executableTarget(
    name: "MyAgentApp",
    dependencies: ["AgentSDK"]
)

Quick Start

import AgentSDK
import Foundation

let provider = OpenAIProvider(apiKey: ProcessInfo.processInfo.environment["OPENAI_API_KEY"]!)

let agent = Agent(
    name: "Reviewer",
    instructions: "Review code for correctness and maintainability.",
    tools: [.readFile, .bash],
    maxTurns: 10,
    model: ModelID("gpt-4o"),
    provider: provider,
    cwd: FileManager.default.currentDirectoryPath
)

let result = try await Runner.runSync(
    agent: agent,
    prompt: "Summarize this package"
)

print(result)

Streaming

let stream = Runner.runStream(
    agent: agent,
    prompt: "Review Sources/Types.swift"
)

for try await event in stream {
    switch event.type {
    case .content:
        print(event.data ?? "", terminator: "")
    case .toolCall:
        print("\n[tool: \(event.tool?.rawValue ?? "unknown")]")
    case .done:
        print("\nDone")
    default:
        break
    }
}

Documentation

Development

swift build
swift test

About

Autohand Code Agent SDK for Swift: SwiftPM package for code agents with async streams, tools, hooks, permissions, and examples.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages