Skip to content

Add the DynamicInstructions builder - #293

Merged
mattt merged 2 commits into
mainfrom
mattt/dynamic-instructions-builder
Oct 4, 2026
Merged

mattt merged 2 commits into
mainfrom
mattt/dynamic-instructions-builder

Conversation

@mattt

@mattt mattt commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

This PR is the second of three that bring in #273 by @qoli. It adds the DynamicInstructions protocol and its result builder, following Foundation Models 27: DynamicInstructionsBuilder, AnyDynamicInstructions, TupleDynamicInstructions, ConditionalDynamicInstructions, EmptyDynamicInstructions, and DynamicInstructionsForEach, with instructions and tools as building blocks. Nothing uses it yet; the next PR adds sessions that resolve dynamic instructions before each request.

The builder is @qoli's, unchanged except for documentation notes that mark it as following Foundation Models 27.

@mattt
mattt requested a balanced review from Copilot October 3, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Composition can discard meaningful whitespace, and collection resolution introduces quadratic copying overhead.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds the Foundation Models 27-shaped dynamic-instructions API. Session integration is deferred to the next PR.

Changes:

  • Adds composable instructions and tools with conditionals, collections, and type erasure.
  • Adds resolution tests for composition, empty content, and repeated body evaluation.
File Description
Tests/​AnyLanguageModelTests/​DynamicInstructionsBuilderTests.swift Tests builder composition and resolution.
Sources/​AnyLanguageModel/​DynamicInstructions.swift Defines the builder, supporting types, and internal resolution.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/AnyLanguageModel/DynamicInstructions.swift Outdated
Comment thread Sources/AnyLanguageModel/DynamicInstructions.swift Outdated
@mattt
mattt requested a balanced review from Copilot October 3, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No blocking issues were identified in the additive API, resolution logic, or accompanying tests.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@mattt
mattt merged commit 4627327 into main Oct 4, 2026
8 checks passed
@mattt
mattt deleted the mattt/dynamic-instructions-builder branch October 4, 2026 03:07
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.

2 participants