feat(chat): refresh the tool set mid-turn on host tool changes - #54
Open
BatLeDev wants to merge 1 commit into
Open
feat(chat): refresh the tool set mid-turn on host tool changes#54BatLeDev wants to merge 1 commit into
BatLeDev wants to merge 1 commit into
Conversation
… tools The tool map was frozen when the turn started: tools registered by a page the agent navigated to only became callable on the next user turn (measured in production: toolCount stays at 17 for the rest of the turn, 21 on the next), and the model concluded it was stuck. The turn loop now snapshots the tool-name signature, watches the aggregated tool set, stops the stream at the next step boundary when the set changes and relaunches streamText on the accumulated history with the re-partitioned tools. Guards: restart only on finishReason tool-calls, at most 2 restarts per turn, and a global 10-step budget across restarts. Pure decision logic lives in tool-refresh.ts with unit tests.
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.
The tool map handed to
streamTextwas frozen when the turn started: tools registered by a page the agent navigated to only became callable on the next user turn (measured in production traces: toolCount stays at 17 for the rest of the turn, 21 on the next), and the model concluded it was stuck.The turn loop now snapshots the tool-name signature, watches the aggregated tool set, stops the stream at the next step boundary when the set changes, and relaunches
streamTexton the accumulated history with the re-partitioned tools (sub-agent resolution and flatten decisions re-run).Guards: restart only on
finishReason: 'tool-calls'(a finished answer is never relaunched), at most 2 restarts per turn, and a global 10-step budget across restarts. The pure decision logic lives intool-refresh.tswith unit tests;docs/architecture/mcp-tools.mddocuments the mechanism.Why: first blocker found by a traced audit of the assistant building a dashboard — it navigated to the creation page, saw no new tools, and gave up.
Heads-up: this touches the heart of the chat loop; most of the
use-agent-chat.tsdiff is re-indentation of the new restart loop (review with whitespace ignored). Two induced fixes: the moderation rollback truncates history viaspliceat the turn's start index, andannouncedThisTurnaccumulates across restarts. No e2e test covers the navigate-then-new-tools scenario yet (needs a host page that changes its tool set mid-turn); 348 unit tests pass, lint and check-types clean.