Skip to content

Make tool schema inclusion behavior consistent with Foundation Models#129

Merged
mattt merged 4 commits intomainfrom
mattt/include-schema-in-instructions
Feb 17, 2026
Merged

Make tool schema inclusion behavior consistent with Foundation Models#129
mattt merged 4 commits intomainfrom
mattt/include-schema-in-instructions

Conversation

@mattt
Copy link
Owner

@mattt mattt commented Feb 17, 2026

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 SystemLanguageModel conversion path synthesized instructions with toolDefinitions: [], 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.

LanguageModelSession now only injects tool definitions for tools that opt in via includesSchemaInInstructions, and SystemLanguageModel now 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).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LanguageModelSession to filter tools by includesSchemaInInstructions when synthesizing transcript instructions
  • Modified SystemLanguageModel conversion 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.

}
}

private func waitUntil(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 Well folks, just wait until you see #130

@mattt mattt merged commit 0a4c94e into main Feb 17, 2026
3 checks passed
@mattt mattt deleted the mattt/include-schema-in-instructions branch February 17, 2026 11:58
@mattt
Copy link
Owner Author

mattt commented Feb 17, 2026

This is now available in 0.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support Reading Transcript Entries and/or Modifications

2 participants