Skip to content

feat: 支持通过 GenerateOptions 按轮次动态控制 enableThinking#1494

Open
Janemia wants to merge 4 commits into
agentscope-ai:mainfrom
Janemia:feat/enable-thinking-per-request
Open

feat: 支持通过 GenerateOptions 按轮次动态控制 enableThinking#1494
Janemia wants to merge 4 commits into
agentscope-ai:mainfrom
Janemia:feat/enable-thinking-per-request

Conversation

@Janemia

@Janemia Janemia commented May 26, 2026

Copy link
Copy Markdown

改动说明

GenerateOptions 新增 enableThinking 字段,使 Hook 能够按轮次动态控制 enable_thinking(此前只能控制 thinking_budget)。

修改内容

  • GenerateOptions:新增 enableThinking 字段、getter、Builder 方法及 mergeOptions 合并逻辑
  • DashScopeChatModel.applyThinkingMode():优先取 options 级别的值,未设置时 fallback 到模型级别的固定值

向后兼容

完全向后兼容。当 options.getEnableThinking() 为 null 时,行为与改造前一致,使用模型级别的 this.enableThinking

@Janemia Janemia requested a review from a team May 26, 2026 04:18
@CLAassistant

CLAassistant commented May 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LearningGp

Copy link
Copy Markdown
Member
image

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/core/model Model providers and formatters labels May 28, 2026
@Janemia Janemia force-pushed the feat/enable-thinking-per-request branch from 7678f11 to 6e4cdb7 Compare June 2, 2026 09:19

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR cleanly adds a per-request enableThinking override on GenerateOptions and wires it into DashScopeChatModel.applyThinkingMode, falling back to the model-level value when null. The merge logic and Javadocs are consistent with the rest of the file. However, the change introduces a behavioral gap: the model's stream flag (and the "thinking requires streaming" override) is resolved only at construction time from the model-level enableThinking. When a hook turns thinking on per-request while the model was built with stream=false and enableThinking=null/false, the request is sent in non-streaming mode, which the existing code explicitly warns is invalid. A minor symmetry issue exists for the inverse case (per-request enableThinking=false combined with a default thinkingBudget), which now produces a confusing validation error. The change is also untested.

Comment thread agentscope-core/src/main/java/io/agentscope/core/model/DashScopeChatModel.java Outdated
Janemia added 2 commits June 4, 2026 15:46
Add enableThinking field to GenerateOptions so that hooks can dynamically
control enable_thinking on a per-turn basis, not just thinking_budget.

DashScopeChatModel.applyThinkingMode() now prioritizes the options-level
value over the model-level fixed value, with full backward compatibility.
@Janemia Janemia force-pushed the feat/enable-thinking-per-request branch from 8eec87a to 90c0054 Compare June 4, 2026 07:58
- [major] Add stream validation: throw when per-request enableThinking=true but model stream=false
- [minor] Only throw on thinkingBudget when enableThinking is null (not configured); silently ignore when explicitly false
- [minor] Remove 'via hooks' qualifier from Javadoc
- [nit] Add unit tests for per-request override, stream validation, explicitly-disabled-with-budget, and mergeOptions enableThinking
@Janemia Janemia force-pushed the feat/enable-thinking-per-request branch from 825b052 to 3d752e6 Compare June 4, 2026 08:18

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All previously raised review comments have been addressed.

@LearningGp

Copy link
Copy Markdown
Member

Run 'mvn spotless:apply' to fix these violations.

@Janemia Janemia force-pushed the feat/enable-thinking-per-request branch from a1eab38 to f84fb58 Compare June 10, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/model Model providers and formatters enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants