Make tool schema inclusion behavior consistent with Foundation Models#129
Merged
Make tool schema inclusion behavior consistent with Foundation Models#129
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes inconsistent tool schema inclusion behavior to align with Foundation Models conventions. Tools have a property includesSchemaInInstructions (defaulting to true) that determines whether their schemas should be included in session instructions, but the implementation wasn't consistently honoring opt-out requests.
Changes:
- Updated
LanguageModelSessionto filter tools byincludesSchemaInInstructionswhen synthesizing transcript instructions - Modified
SystemLanguageModelconversion to pass filtered tool definitions instead of an empty array when creating Foundation Models transcript - Added comprehensive tests to verify filtering behavior and equivalence between different initialization paths
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Sources/AnyLanguageModel/LanguageModelSession.swift | Filters tools by includesSchemaInInstructions when creating instructions entries from string-based instructions |
| Sources/AnyLanguageModel/Models/SystemLanguageModel.swift | Passes filtered tool definitions to transcript conversion in both respond and streamResponse methods, and uses them when synthesizing instructions |
| Tests/AnyLanguageModelTests/MockLanguageModelTests.swift | Adds test tool that opts out of schema injection and three new tests verifying filtering behavior, initialization path equivalence, and explicit transcript preservation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mattt
commented
Feb 17, 2026
| } | ||
| } | ||
|
|
||
| private func waitUntil( |
Owner
Author
|
This is now available in 0.7.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #122
As discussed in #122, there was a mismatch between expected Foundation Models behavior and the current implementation: tools default to
includesSchemaInInstructions = true, so their schemas should be available through instructions. But in practice, this was inconsistent.Tool definitions were being added to transcript-seeded instructions without honoring opt-out, while a key
SystemLanguageModelconversion path synthesized instructions withtoolDefinitions: [], effectively dropping schema metadata in some session setups. This made it look like schemas were missing when inspecting instructions and created divergent behavior between instruction-based and transcript-based initialization.This PR makes schema injection explicit and consistent across paths.
LanguageModelSessionnow only injects tool definitions for tools that opt in viaincludesSchemaInInstructions, andSystemLanguageModelnow passes those filtered definitions into transcript conversion so synthesized Foundation Models instructions include them instead of an empty array. Explicit transcript instruction entries remain pass-through (unchanged).