Skip to content

Think: pruneMessages is too agressive "before-last-2-messages", breaks client-side tool workflows #1455

Closed

Description

@abhagsain

Client-side tool outputs (tools without execute — user provides output via addToolOutput) lose context after just 5 messages. The AI has zero memory of what the user chose and starts the flow
from scratch.

Root Cause

_runInferenceLoop hardcodes:
const messages = pruneMessages({
    messages: await convertToModelMessages(truncateOlderMessages(this.session.getHistory()), { tools }),
    toolCalls: "before-last-2-messages"
});

Verified in both @cloudflare/[email protected] and @0.5.3 (latest). There is no subclass hook to configure the pruning options.

With 5 UIMessages → ~7 model messages, all tool-call and tool-result parts from earlier tools get stripped. For client-side tools, user decisions (e.g., clarification answers, setup config) live only in those tool-result messages — so they're permanently lost.

Why client-side tools are uniquely affected

Server-side tools (with execute) resolve in the same turn — their results are always in the last 2 model messages and survive pruning. Client-side tools span multiple turns by design (LLM
proposes → user provides output → auto-continuation), so their results naturally fall outside the 2-message window on any follow-up message.

Reproduction

  1. Define 2+ client-side tools (no execute)
  2. User sends a message → AI calls tool 1 → user provides output via addToolOutput → AI auto-continues → calls tool 2 → user provides output → AI auto-continues
  3. User sends any follow-up text message
  4. AI has no memory of tool 1 or tool 2 outputs

Expected behavior

Tool results from client-side tools should not be silently stripped from a 5-message conversation.

Current workaround

  1. The only escape hatch is overriding messages via TurnConfig in beforeTurn, but ctx.messages is already pruned at that point, so you have to rebuild from this.messages
  2. In the client, we send the user answers as separate user messages so they stay in the conversation
  3. Keep adding to context blocks, but context blocks feel like they're designed for high-signal, long-term facts — "this project uses Python 3.12. and the user always uses Mac."

Environment

  • @cloudflare/think: 0.4.1 (also verified in 0.5.3)
  • ai: 6.0.57

Activity

  1. changed the title [-]Think: pruneMessages with toolCalls: "before-last-2-messages" is hardcoded in _runInferenceLoop, breaks client-side tool workflows[/-] [+]Think: pruneMessages is too agressive "before-last-2-messages", breaks client-side tool workflows[/+] on May 4, 2026
  2. added
    bug
    on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions