Repository navigation
feat(chat): change the reasoning level while a run streams - #1022
Merged
Merged
Conversation
The reasoning control was disabled for the whole run on the assumption that the level cannot change mid-turn (#777). pi-agent-core does snapshot `reasoning` into the loop config when a run starts, but AgentSession's prepareRequest / prepareNextTurnWithContext hooks re-read agent.state.thinkingLevel before every model request, and pi's TUI lets Shift+Tab change it during a run. So set_thinking_level mid-run applies from the next request; only the response already streaming keeps its level. The server never refused the command, only the composer did. Keep the control usable while streaming and stop closing its menu when a run starts. The tooltip is unchanged. An integration test drives a real AgentSession with the faux provider and changes the level while the first request streams: the requests go out at low, then high. That pins the SDK behavior the control now relies on across SDK upgrades. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Kano-u
pushed a commit
to Kano-u/pi-web
that referenced
this pull request
Oct 2, 2026
…式中改思考等级) 解决 agegr#1018 之后这两个提交 0 冲突。 - agegr#1021 技能/插件分组标题本身就是开关 - agegr#1022 一次运行流式输出过程中即可修改思考等级(agegr#851)
agegr
added a commit
that referenced
this pull request
Nov 3, 2026
The composer's model selector was disabled while a run streamed, a lock from the first version. pi's TUI keeps Ctrl+P / Ctrl+L working mid-run, and AgentSession hands the agent loop `agent.state.model` before every turn, so `set_model` answers from the run's next request, exactly as the reasoning level already does here (#1022). The selector stays usable now. A switch during a run (or a `!` command) takes the model and level from the live state instead of reading the session file, which would replace the run's messages under the stream; the run's end reads the file as before. An idle switch is unchanged. lib/model-mid-run.integration.test.mjs pins the SDK side with the faux provider, as the thinking-level test does. Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
agegr#1022) The reasoning control was disabled for the whole run on the assumption that the level cannot change mid-turn (agegr#777). pi-agent-core does snapshot `reasoning` into the loop config when a run starts, but AgentSession's prepareRequest / prepareNextTurnWithContext hooks re-read agent.state.thinkingLevel before every model request, and pi's TUI lets Shift+Tab change it during a run. So set_thinking_level mid-run applies from the next request; only the response already streaming keeps its level. The server never refused the command, only the composer did. Keep the control usable while streaming and stop closing its menu when a run starts. The tooltip is unchanged. An integration test drives a real AgentSession with the faux provider and changes the level while the first request streams: the requests go out at low, then high. That pins the SDK behavior the control now relies on across SDK upgrades. Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
agegr#1022) The reasoning control was disabled for the whole run on the assumption that the level cannot change mid-turn (agegr#777). pi-agent-core does snapshot `reasoning` into the loop config when a run starts, but AgentSession's prepareRequest / prepareNextTurnWithContext hooks re-read agent.state.thinkingLevel before every model request, and pi's TUI lets Shift+Tab change it during a run. So set_thinking_level mid-run applies from the next request; only the response already streaming keeps its level. The server never refused the command, only the composer did. Keep the control usable while streaming and stop closing its menu when a run starts. The tooltip is unchanged. An integration test drives a real AgentSession with the faux provider and changes the level while the first request streams: the requests go out at low, then high. That pins the SDK behavior the control now relies on across SDK upgrades. Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
The composer's model selector was disabled while a run streamed, a lock from the first version. pi's TUI keeps Ctrl+P / Ctrl+L working mid-run, and AgentSession hands the agent loop `agent.state.model` before every turn, so `set_model` answers from the run's next request, exactly as the reasoning level already does here (agegr#1022). The selector stays usable now. A switch during a run (or a `!` command) takes the model and level from the live state instead of reading the session file, which would replace the run's messages under the stream; the run's end reads the file as before. An idle switch is unchanged. lib/model-mid-run.integration.test.mjs pins the SDK side with the faux provider, as the thinking-level test does. Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Fixes #851
Problem
During a long agent run the reasoning level cannot be changed: the control next to Stop is greyed out until the run ends. #777 disabled it on the assumption that the level cannot change mid-turn.
That assumption does not hold. pi-agent-core snapshots
reasoninginto the loop config when a run starts, butAgentSessioninstallsprepareRequestandprepareNextTurnWithContexthooks that re-readagent.state.thinkingLevelbefore every model request. pi's own TUI lets Shift+Tab change the level during a run.set_thinking_levelinlib/rpc-manager.tsnever refused the command either — only the composer did.Changes
ChatInputno longer disables the reasoning button (or dims it, or drops its hover state) while a run streams, and no longer force-closes its menu when a run starts. The tool preset dropdown is still hidden and closed while streaming, as before. The tooltip text is unchanged.lib/thinking-level-mid-run.integration.test.mjsdrives a realAgentSessionwith the SDK's faux provider and changes the level while the first request streams; it asserts the requests go out atlow, thenhigh. If an SDK upgrade goes back to freezing the level for the whole run, this fails instead of the control silently doing nothing.Tests
npm test: all pass exceptlib/worktree.test.mjs"forced worktree removal passes Git's force flag", which fails identically on an untouched checkout ofmain(unrelated).tsc --noEmitandnpm run lintpass.PI_CODING_AGENT_DIRand a local OpenAI-compatible endpoint that streams for ~20s and then callsls: sent atlow, opened the menu mid-stream and pickedhigh. The endpoint loggedreasoning_effort: "low"for the first request and"high"for the request after the tool result; the session file got a mid-runthinking_level_changeentry, the run finished normally, and the console had no errors.Known limitation
While a run is active the client reconciles with
GET /api/agent/[id]every 15s. A response that was read on the server just before the change can briefly show the old level in the button; the next poll corrects it. The level the server uses is not affected.🤖 Generated with Claude Code