feat: first-class Foundation Models with native tools and dynamic profiles#112
feat: first-class Foundation Models with native tools and dynamic profiles#112christopherkarani wants to merge 1 commit into
Conversation
β¦namic profiles Make Apple Foundation Models a first-class Swarm path that no longer depends on Conduit for on-device inference. Bridge Swarm tool schemas to FoundationModels.Tool with guided generation, capture tool calls for the agent loop, and add WWDC 2026-aligned Dynamic Profiles for phase-based instructions, tool filters, generation overrides, and history policy. Deprecate the Conduit FM selection path, document Tool naming clashes, and cover the new provider/bridge/profile surface with unit and live tests.
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fff133e593
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let first = messages.first, first.role == .system { | ||
| // Replace / strengthen leading system message for this phase. | ||
| var copy = messages | ||
| copy[0] = .system(instructions) |
There was a problem hiding this comment.
Preserve the existing system prompt
When a dynamic profile is used through Agent, the first message is already the agent's system prompt, but this replacement discards it and keeps only the profile/configuration instructions. In calls like Agent("You are a billing bot", inferenceProvider: .foundationModels(profile: ...)), the Foundation Models turn no longer receives the agent instructions unless the caller duplicates them in the provider configuration; merge the new instructions with the existing system content instead of replacing it.
Useful? React with πΒ / π.
| let effectiveTools: [ToolSchema] | ||
| if resolved.options.toolChoice == ToolChoice.none { | ||
| effectiveTools = [] | ||
| } else { | ||
| effectiveTools = resolved.tools | ||
| } |
There was a problem hiding this comment.
Honor specific tool choice before bridging
This only removes tools for .none; for ToolChoice.specific(toolName:) it still bridges every resolved tool to FoundationModels. Because the later prompt text is only a hint, requests that are supposed to force search can still let the native model call calc or any other provided tool; filter effectiveTools down to the named tool for this case.
Useful? React with πΒ / π.
Summary
Makes Apple Foundation Models a first-class Swarm path for macOS/iOS and unblocks engineers who hit Conduit coupling, prompt-emulated tools, and
Toolname clashes when mixing Swarm with Apple Intelligence.Foundation Models (main change)
FoundationModelsInferenceProviderthat talks toLanguageModelSessionwithout ConduitToolSchemaβ Apple'sFoundationModels.Toolusing guided generation (DynamicGenerationSchema/GenerationSchema).foundationModels()/conduitFoundationModels()for migration onlySwarm.ToolvsFoundationModels.Toolclash guidanceDynamic Profiles (WWDC 2026βaligned)
Profile,DynamicProfile,DynamicInstructions,ProfileMode, andModeSwitchingDynamicProfile.foundationModels(profile:)LanguageModelSession.DynamicProfileis not in the macOS 26.2 SDK yet; this is the portable Swarm layer ready to bridge when the SDK shipsAlso on this branch
MembraneHiveimportTest plan
swift buildswift test --filter DynamicProfileswift test --filter FoundationModelsNativeToolBridgeTests|FoundationModelsInferenceProviderTests|FoundationModelsToolCallingTests|LanguageModelSessionTool|ConduitProviderSelection|AgentDefaultSWARM_RUN_LIVE_FOUNDATION_MODELS_TESTS=1(native tool capture + profile mode switch)Agent("β¦", inferenceProvider: .foundationModels()) { MyTool() }Example