Skip to content

[Bug] 新回合清空按需工具激活,历史 ToolSearch 成功记录仍在上下文 / New prompt drops on-demand activations while ToolSearch history remains #225

Description

@xingleiwu

Problem / 问题

On a new user prompt, the runtime clears on-demand tool activations (activeDeferredToolNames.clear()), but the transcript still contains successful ToolSearch results (addedToolNames, “Activated on-demand tools: …”).

The model therefore believes those tools are in the current schema. They are not. The next call fails or the model retries ToolSearch / invents a call.

新用户消息会清空按需激活集,但历史里成功的 ToolSearch 结果还在上下文。模型以为工具可用,实际拿不到。

Stock 0.14.6 (packages/agent-runtime/src/runtime.ts):

private resetDeferredToolsForPrompt(): void {
  this.activeDeferredToolNames.clear();
  this.agent.state.tools = this.activeTools();
}

Called from prompt() and executeApprovedPlan() at the start of every turn.

ToolSearch.execute already writes addedToolNames onto the tool result. Compaction / UI history keep those rows. Nothing reads them back into activeDeferredToolNames.

Repro

  1. Agent mode, catalog with deferred tools (Skill, BrowserPreview, plugin tools, …).
  2. ToolSearch { query: "Skill" } → “Activated on-demand tools: Skill.”
  3. Use Skill successfully.
  4. Send a new user message in the same session.
  5. First provider request of the new turn: Skill is absent from tools. History still shows the activation. Model calls Skill anyway or ToolSearches again.

Proposed change / 期望改动

On each new prompt (and mode switch), rebuild the active deferred set from the effective context, do not start from empty:

  • Walk buildSessionContext messages.
  • Only successful toolResult rows (!isError).
  • For ToolSearch, use addedToolNames; for a direct deferred-tool result, use toolName.
  • Keep a name only if it is still in the current deferred catalog, still in toolCatalog, and allowed in the current mode.
  • Ignore UI placeholders such as [no tool result recorded] / interrupted stubs — those are not evidence the tool ever succeeded.

Do not parse assistant/user prose. After restore, set agent.state.tools = activeTools().

Mode switch should restore after rebuild (clear then restore from context is fine; a bare clear is not).

Alternatives / 其他方案

Additional context / 补充信息

PI-Desktop 0.14.6. packages/agent-runtime resetDeferredToolsForPrompt / buildToolSearchTool / activeTools().

Related: #204 (Skill as core) — even if Skill is core, BrowserPreview / Plugin* / MCP still hit this hole.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions