Getting Started

Install the Swift SDK and run your first agent in under five minutes.

Installation

Add the package to your Package.swift dependencies:

Package.swiftSwift
dependencies: [
    .package(
        url: "https://github.com/kunal732/strands-agents-swift.git",
        branch: "main"
    )
]

Then add the modules your target needs. At minimum you need StrandsAgents (core) plus a provider:

Package.swiftSwift
.target(
    name: "MyApp",
    dependencies: [
        .product(name: "StrandsAgents",         package: "strands-agents-swift"),
        .product(name: "StrandsBedrockProvider", package: "strands-agents-swift"),
    ]
)

See the Modules page for a full list of available packages.

Quick Start

The simplest possible agent: no tools, just a model and a prompt.

main.swiftSwift
import StrandsAgents
import StrandsBedrockProvider

let provider = try BedrockProvider(config: BedrockConfig(
    modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0"
))

let agent = Agent(model: provider)
let result = try await agent.run("What is the capital of France?")
print(result.output)  // "Paris"

Adding Tools

Use the @Tool macro to give your agent capabilities. The macro generates the JSON schema and boilerplate automatically from the function signature:

main.swiftSwift
/// Count the number of words in a block of text.
@Tool
func wordCount(text: String) -> Int {
    text.split(whereSeparator: \.isWhitespace).count
}

/// Look up the current weather for a city.
@Tool
func getWeather(city: String, unit: String = "celsius") -> String {
    // call your weather API here
    return "22°C, partly cloudy in \(city)"
}

let agent = Agent(model: provider, tools: [wordCount, getWeather])
let result = try await agent.run("How many words are in 'Hello world'? Also, what's the weather in Tokyo?")
print(result.output)
💡

The doc comment above the function becomes the tool description the model sees. Write clear, verb-led descriptions for best results.

Streaming responses

Use agent.stream() to display tokens as they arrive, instead of waiting for the full response:

main.swiftSwift
for try await event in agent.stream("Write a haiku about Swift.") {
    switch event {
    case .textDelta(let token):
        print(token, terminator: "")  // print each token as it arrives
    case .result(let final):
        print("\n\nDone in \(final.metrics.totalLatencyMs)ms")
    default:
        break
    }
}

Next Steps