Repository navigation
0.4.0
Breaking Changes
-
Renamed
ProvidertoAdapter: The core abstraction for AI model integrations has been renamed fromProvidertoAdapterfor better clarity. Update all references to use the new naming:// Before let agent = Agent<OpenAIProvider, Context>() // Now let agent = Agent<OpenAIAdapter, Context>()
-
Renamed
TranscripttoAgentTranscript: To avoid naming conflicts with FoundationModels, theTranscripttype has been renamed toAgentTranscript:// Before public var transcript: Transcript // Now public var transcript: AgentTranscript<Adapter.Metadata, Context>
Added
-
Prompt Context System: Introduced a new
PromptContextprotocol that enables separation of user input from contextual information (such as vector embeddings or retrieved documents). This provides cleaner transcript organization and better prompt augmentation:enum PromptContext: SwiftAgent.PromptContext { case vectorEmbedding(String) case documentContext(String) } let agent = OpenAIAgent(supplying: PromptContext.self, tools: tools) // User input and context are now separated in the transcript let response = try await agent.respond( to: "What is the weather like?", supplying: [.vectorEmbedding("relevant weather data")] ) { input, context in PromptTag("context", items: context) input }
-
Tool Resolver: Added a powerful type-safe tool resolution system that combines tool calls with their outputs. The
ToolResolverenables compile-time access to tool arguments and outputs:// Define a resolved tool run enum enum ResolvedToolRun { case getFavoriteNumbers(AgentToolRun<GetFavoriteNumbersTool>) } // Tools must implement the resolve method func resolve(_ run: AgentToolRun<GetFavoriteNumbersTool>) -> ResolvedToolRun { .getFavoriteNumbers(run) } // Use the tool resolver in your UI code let toolResolver = agent.transcript.toolResolver(for: tools) for entry in agent.transcript.entries { if case let .toolCalls(toolCalls) = entry { for toolCall in toolCalls.calls { let resolvedTool = try toolResolver.resolve(toolCall) switch resolvedTool { case let .getFavoriteNumbers(run): print("Count:", run.arguments.count) if let output = run.output { print("Numbers:", output.numbers) } } } } }
-
Convenience Initializers: Added streamlined initializers that reduce generic complexity. The new
OpenAIAgenttypealias and convenience initializers make agent creation more ergonomic:// Simplified initialization with typealias let agent = OpenAIAgent(supplying: PromptContext.self, tools: tools) // No context needed let agent = OpenAIAgent(tools: tools) // Even simpler for basic usage let agent = OpenAIAgent()
Enhanced
- AgentTool Protocol: Extended the
AgentToolprotocol with an optionalResolvedToolRunassociated type to support the new tool resolver system - Type Safety: Improved compile-time type safety for tool argument and output access through the tool resolver
- Transcript Organization: Better separation of concerns in transcript entries, with user input and context clearly distinguished
Migration Guide
- Update Provider references: Replace all instances of
ProviderwithAdapterin your code - Update Transcript references: Replace
TranscriptwithAgentTranscriptwhere needed - Consider adopting PromptContext: If you're currently building prompts with embedded context outside the agent, consider migrating to the new
PromptContextsystem for cleaner separation - Adopt Tool Resolver: For better type safety in UI code that displays tool runs, implement the
resolvemethod in your tools and use the transcript'stoolResolver - Use convenience initializers: Simplify your agent initialization code using the new
OpenAIAgenttypealias and convenience initializers