fix(agent-runtime): restore on-demand tool activations still in context - #231
Merged
Merged
Conversation
Every new prompt and mode switch cleared the active deferred-tool set, but the transcript kept the ToolSearch results that announced those activations and the results the tools produced. The model therefore kept calling tools that were missing from the schema (vastsa#225). Rebuild the active set from the effective session context instead: successful ToolSearch rows contribute their addedToolNames, a successful result of a deferred tool contributes that tool, and only names still in the deferred catalog (already limited to the current mode) are kept. Failed rows and rows without a recorded result are ignored.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Owner
|
Reviewed and merged. The PR addresses the verified #225 regression: successful deferred-tool activations retained in the effective session context are restored after per-prompt reset, while failed/interrupted/missing results and mode-ineligible tools are excluded. Validation on the PR head: 11 deferred-runtime tests passed, agent-runtime typecheck passed, and protocol E2E passed 18/18 (2 live-model scenarios skipped because PI_DESKTOP_TEST_API_KEY was not set). Follow-up spec/ADR/E2E documentation sync landed locally after the merge. |
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 #225
Problem
resetDeferredToolsForPrompt()(called fromprompt()andexecuteApprovedPlan()) andsetMode()clearedactiveDeferredToolNamesoutright. The session context, however, still contained the successfulToolSearchresults ("Activated on-demand tools: Skill.") and the results those tools produced, so the model reasonably believed the tools were still in the schema, called them, and got a failure or re-searched.Change
packages/agent-runtime/src/runtime.tsrestoreDeferredToolsFromContext(): walksbuildSessionContext(this.entriesWithCompaction()).messagesand re-activatesaddedToolNamesof successfulToolSearchresults, andkeeping only names still in
deferredToolNames(whichrebuildToolCatalogalready limits to tools allowed in the current mode).isErrorand rows whose only content is the[no tool result recorded]placeholder are ignored (the placeholder string is now a shared constant so both sites agree). Assistant/user prose is not parsed.resetDeferredToolsForPrompt()clears, restores, then setsagent.state.tools;setMode()restores afterrebuildToolCatalog()so a mode round trip does not drop activations either.Tests
packages/agent-runtime/src/runtime.test.ts, new describe "deferred tool restore (#225)":ToolSearchrow keepsBrowserPreviewactive acrossresetDeferredToolsForPrompt();ToolSearchrow and aBrowserPreviewrow without a recorded result restore nothing, while a successfulBrowserPreviewresult does;setMode("plan")→setMode("agent").The existing "resets deferred capabilities at the beginning of a new prompt" test still passes: its activation was made through a direct
execute()call and never entered the context, so there is nothing to restore.Verified locally:
vitest run src/runtime.test.ts -t deferred(11 passed),tsc -p tsconfig.json --noEmitinpackages/agent-runtime.