Forge documentation
Library referenceSwift

ForgeAgent

Swift ForgeAgent library product.

Swift ForgeAgent library product.

Package contract

FieldValue
Languageswift
Source versionSwift package source snapshot
Manifestforge-swift/Package.swift
Source files6
EvidenceSource reference; registry publication and runtime conformance are separate checks

Import boundary

import ForgeAgent

Use a source checkout or your verified private registry. Manifest coordinates identify the package; they do not establish that a public registry release exists.

Source reference

Download package reference JSON. Each original source file and generated declaration artifact has its own SHA-256 digest. Function bodies and constant values are omitted from downloads. These are source declaration inventories, not compiler-resolved rustdoc, TypeDoc, DocC, or Dokka output. Private modules can contain public declarations that are not reachable through the package boundary; consult the entry point before importing.

Agent.swift

Read declaration text · 16 declaration entries

public struct AgentConfig: Sendable

public let providerRef: String
/// System instruction for the agent.
public let systemPrompt: String?
/// Maximum number of tool loop steps before stopping.
public let maxSteps: Int
/// Maximum total tokens before stopping.
public let maxTokens: UInt64
/// Generation options for inference calls.
public let options: GenerateOptions
/// Agent name for logging and telemetry.
public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public let systemPrompt: String?
/// Maximum number of tool loop steps before stopping.
public let maxSteps: Int
/// Maximum total tokens before stopping.
public let maxTokens: UInt64
/// Generation options for inference calls.
public let options: GenerateOptions
/// Agent name for logging and telemetry.
public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public let maxSteps: Int
/// Maximum total tokens before stopping.
public let maxTokens: UInt64
/// Generation options for inference calls.
public let options: GenerateOptions
/// Agent name for logging and telemetry.
public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public let maxTokens: UInt64
/// Generation options for inference calls.
public let options: GenerateOptions
/// Agent name for logging and telemetry.
public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public let options: GenerateOptions
/// Agent name for logging and telemetry.
public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public let name: String?

public init(
providerRef: String,
systemPrompt: String?;

public init(
providerRef: String,
systemPrompt: String?;

public struct AgentOutput: Sendable

public let text: String
/// All messages in the conversation (including tool calls and results).
public let messages: [ModelMessage]
/// Total usage across all inference calls.
public let usage: Usage
/// Number of tool loop steps executed.
public let steps: Int
/// The finish reason of the final inference call.
public let finishReason: FinishReason

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public let messages: [ModelMessage]
/// Total usage across all inference calls.
public let usage: Usage
/// Number of tool loop steps executed.
public let steps: Int
/// The finish reason of the final inference call.
public let finishReason: FinishReason

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public let usage: Usage
/// Number of tool loop steps executed.
public let steps: Int
/// The finish reason of the final inference call.
public let finishReason: FinishReason

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public let steps: Int
/// The finish reason of the final inference call.
public let finishReason: FinishReason

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public let finishReason: FinishReason

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public init(
text: String,
messages: [ModelMessage],
usage: Usage,
steps: Int,
finishReason: FinishReason
)

public protocol ForgeAgent: Sendable

LoopControl.swift

Read declaration text · 8 declaration entries

public enum StopCondition: Sendable

public struct LoopState: Sendable

public let step: Int
/// Total tokens consumed so far.
public let totalTokens: UInt64
/// The finish reason from the last inference call.
public let lastFinishReason: FinishReason?
/// The messages accumulated so far.
public let messageCount: Int

public init(step: Int, totalTokens: UInt64, lastFinishReason: FinishReason?, messageCount: Int)

public let totalTokens: UInt64
/// The finish reason from the last inference call.
public let lastFinishReason: FinishReason?
/// The messages accumulated so far.
public let messageCount: Int

public init(step: Int, totalTokens: UInt64, lastFinishReason: FinishReason?, messageCount: Int)

public let lastFinishReason: FinishReason?
/// The messages accumulated so far.
public let messageCount: Int

public init(step: Int, totalTokens: UInt64, lastFinishReason: FinishReason?, messageCount: Int)

public let messageCount: Int

public init(step: Int, totalTokens: UInt64, lastFinishReason: FinishReason?, messageCount: Int)

public init(step: Int, totalTokens: UInt64, lastFinishReason: FinishReason?, messageCount: Int)

public func evaluateStopConditions(
_ conditions: [StopCondition],
state: LoopState
) -> StopCondition?

Messaging.swift

Read declaration text · 13 declaration entries

public struct AgentMessage: Codable, Sendable

public let senderDid: String?
/// The recipient agent identifier.
public let recipientDid: String?
/// The message type.
public let messageType: String
/// The message payload.
public let payload: JSONValue
/// When the message was created.
public let timestamp: Timestamp

public init(
senderDid: String?;

public let recipientDid: String?
/// The message type.
public let messageType: String
/// The message payload.
public let payload: JSONValue
/// When the message was created.
public let timestamp: Timestamp

public init(
senderDid: String?;

public let messageType: String
/// The message payload.
public let payload: JSONValue
/// When the message was created.
public let timestamp: Timestamp

public init(
senderDid: String?;

public let payload: JSONValue
/// When the message was created.
public let timestamp: Timestamp

public init(
senderDid: String?;

public let timestamp: Timestamp

public init(
senderDid: String?;

public init(
senderDid: String?;

public final class AgentMessageChannel: @unchecked Sendable

public init()

public func send(_ message: AgentMessage)

public func receiveAll() -> [AgentMessage]

public var count: Int

public var isEmpty: Bool

SubAgent.swift

Read declaration text · 7 declaration entries

public struct SubAgentConfig: Sendable

public let name: String
/// The system prompt for the sub-agent.
public let systemPrompt: String?
/// Maximum tool loop steps for the sub-agent.
public let maxSteps: Int
/// Tools available to the sub-agent (subset of parent's tools).
public let allowedTools: [String]?

public init(
name: String,
systemPrompt: String?;

public let systemPrompt: String?
/// Maximum tool loop steps for the sub-agent.
public let maxSteps: Int
/// Tools available to the sub-agent (subset of parent's tools).
public let allowedTools: [String]?

public init(
name: String,
systemPrompt: String?;

public let maxSteps: Int
/// Tools available to the sub-agent (subset of parent's tools).
public let allowedTools: [String]?

public init(
name: String,
systemPrompt: String?;

public let allowedTools: [String]?

public init(
name: String,
systemPrompt: String?;

public init(
name: String,
systemPrompt: String?;

public func createSubAgent(
model: any LanguageModel,
config: SubAgentConfig,
parentRegistry: ToolRegistry,
approvalHandler: any ToolApprovalHandler;

ToolLoop.swift

Read declaration text · 8 declaration entries

public final class ToolLoopAgent: ForgeAgent, @unchecked Sendable

public let config: AgentConfig

private let model: any LanguageModel
private let toolRegistry: ToolRegistry
private let approvalHandler: any ToolApprovalHandler
private let telemetry: any TelemetryEmitter
private let lifecycleManager: LifecycleManager
private let healthMonitor: HealthMonitor

/// Creates a new tool loop agent.
///
/// - Parameters:
///   - model: The language model to use.
///   - config: The agent configuration.
///   - toolRegistry: The registry of available tools.
///   - approvalHandler: The tool approval handler. Defaults to auto-approve.
///   - telemetry: The telemetry emitter. Defaults to no-op.
public init(
model: any LanguageModel,
config: AgentConfig,
toolRegistry: ToolRegistry;

public init(
model: any LanguageModel,
config: AgentConfig,
toolRegistry: ToolRegistry;

public func health() -> HealthProfile

public func lifecycle() -> LifecycleState

public func start() throws

public func run(input: String) async throws -> AgentOutput

public func stop() throws

Workflow.swift

Read declaration text · 6 declaration entries

public struct WorkflowStep: Sendable

public let name: String
/// The step execution function.
public let execute: @Sendable (String) async throws -> String

public init(name: String, execute: @escaping @Sendable (String) async throws -> String)

public let execute: @Sendable (String) async throws -> String

public init(name: String, execute: @escaping @Sendable (String) async throws -> String)

public init(name: String, execute: @escaping @Sendable (String) async throws -> String)

public func executeSequentialWorkflow(
steps: [WorkflowStep],
input: String
) async throws -> String

public func executeParallelWorkflow(
steps: [WorkflowStep],
input: String
) async throws -> [String]

Continue

On this page