Forge documentation
Swift

Swift quickstart

A source-correct, no-network first success in Swift.

Start with an operation that needs no model, network, identity seed, or wallet. This verifies the actual Swift message API before adding a provider or tools.

Prerequisites

The manifest uses Swift tools 5.9, with minimum macOS 13 and iOS 16. Individual dependencies and the selected target still determine the full toolchain requirements.

Use a source checkout

The paths below assume the Forge checkout is beside your application. Adjust the local path to your workspace. Registry publication is not inferred from the package name.

// In Package.swift dependencies:
.package(path: "../forge/forge-swift")

// In the executable target dependencies:
.product(name: "ForgeCore", package: "forge-swift")

First success

Save this in your application's entry point after resolving ForgeCore.

import ForgeCore

let message = ModelMessage.text(.user, "Hello, Forge")
precondition(message.textContent() == "Hello, Forge")
print(message.textContent())

Expected output: Hello, Forge. This checks message construction and text extraction only; it does not call an LLM.

Add an agent

AgentConfig takes providerRef, optional system prompt, limits, generation options, and optional name. ForgeAgent.run(input:) is async throws and returns AgentOutput. Read text, usage, steps, and finishReason; use try await and preserve task cancellation. This differs from the TypeScript initialization API.

Verify the source

The example uses declarations from the message declarations. Package metadata comes from forge-swift/Package.swift.

Next

On this page