Skip to content

Honor ContextOptions.reasoningLevel in the language model executor - #267

Open
stikves wants to merge 2 commits into
apple:mainfrom
stikves:sukru/fm-reasoning-level
Open

stikves wants to merge 2 commits into
apple:mainfrom
stikves:sukru/fm-reasoning-level

Conversation

@stikves

@stikves stikves commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Teaches the CoreAI language model executor to honor ContextOptions.reasoningLevel, so callers can set a reasoning model's thinking budget through DynamicProfile.reasoningLevel(_:) (iOS/macOS 27.0).

What this adds

The executor reads request.contextOptions.reasoningLevel, maps it to a canonical effort string (.light to low, .moderate to medium, .deep to high, .custom verbatim), and injects it as a chat-template keyword argument (reasoning_effort, reasoning_strength, or enable_thinking). A chat template reads only the variables it references, so binding each is safe. Guarded by @available(FoundationModels 2.0).

Behavior

A request without a reasoning level is unchanged, so current behavior is preserved. A reasoning model whose chat template reads one of these variables picks up the level; other models keep their existing output.

Testing

Builds and swift format lint --strict pass. The mapping matches the reasoning-effort logic used on the server side and was verified on device, where a reasoning model's thinking budget scales with the level.

…utor

The executor reads request.contextOptions.reasoningLevel, maps it to a canonical effort
string (light to low, moderate to medium, deep to high, custom verbatim), and injects it as
a chat-template keyword argument. Callers set the reasoning budget through
DynamicProfile.reasoningLevel; requests without a reasoning level are unchanged.
…nded reasoning_strength; add mapping test

reasoningTemplateContext mirrors CoreAILMCommon.ReasoningEffort.templateContext (module layering blocks a direct import). Test covers ReasoningLevel to canonical-string mapping.
@stikves
stikves force-pushed the sukru/fm-reasoning-level branch from f5942c2 to 3ea52cf Compare September 23, 2026 00:52
@stikves
stikves marked this pull request as ready for review September 23, 2026 01:02
@stikves stikves self-assigned this Sep 23, 2026
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.

1 participant