Repository navigation
Resolve a request context before each model request - #292
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The Ollama migration changes static non-streaming request history semantics despite the stated compatibility guarantee.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Introduces request-scoped session context resolution and migrates built-in model adapters to consume context snapshots.
Changes:
- Adds and tests
LanguageModelSession.RequestContext. - Migrates model adapters and tool loops to request-scoped transcripts, instructions, and tools.
- Documents the new integration API.
| File | Description |
|---|---|
README.md |
Documents request-context access. |
LanguageModelSession.swift |
Defines and resolves request contexts. |
AnthropicLanguageModel.swift |
Uses context snapshots during requests and tool rounds. |
CoreMLLanguageModel.swift |
Uses context inputs for generation. |
FoundationLanguageModel.swift |
Builds Foundation Models sessions from contexts. |
GeminiLanguageModel.swift |
Refreshes contexts between tool rounds. |
LlamaLanguageModel.swift |
Applies contexts to prompts and tool execution. |
MLXLanguageModel.swift |
Applies contexts across generation paths. |
OllamaLanguageModel.swift |
Migrates requests and tool handling to contexts. |
OpenAILanguageModel.swift |
Refreshes request inputs per tool round. |
OpenResponsesLanguageModel.swift |
Refreshes request inputs per tool round. |
PrivateCloudComputeLanguageModel.swift |
Uses context for feedback sessions. |
SystemLanguageModel.swift |
Centralizes context-based session creation. |
RequestContextTests.swift |
Tests static context snapshots. |
MockLanguageModel.swift |
Resolves instructions through request contexts. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+131
to
+135
| let requestContext = session.resolvedRequestContext() | ||
| let ollamaTools = try requestContext.tools.map(convertToolToOllamaFormat) | ||
| var messages = try requestContext.transcript.toOllamaMessages() | ||
| if messages.isEmpty { | ||
| messages.append(.init(role: .user, content: prompt.description)) |
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.

This PR is the first of three that bring in #273 by @qoli, which adds Foundation Models 27-style dynamic instructions. It adds
LanguageModelSession.RequestContext, with the transcript, instructions, and tools for one model request, andresolvedRequestContext(), and moves every built-in adapter to read them from a context it resolves before each request. If a request produces tool calls, the adapter runs them with the tools from that same context, and resolves a new context for the continuation.For the sessions that exist today, the context is the session's own transcript, instructions, and tools, so nothing changes. The next two PRs add the
DynamicInstructionsbuilder and sessions whose instructions and tools are resolved for each request.This PR also fixes nonstreaming Ollama requests, which sent only the latest prompt, without the instructions or earlier turns. They now send the whole transcript, like streaming requests already did.
The adapter changes are @qoli's, with
mainmerged in.