Skip to content

fix: keep pre-tool assistant text in tool-call history - #21

Merged
davehorton merged 2 commits into
mainfrom
fix/tool-call-assistant-text
Sep 21, 2026
Merged

davehorton merged 2 commits into
mainfrom
fix/tool-call-assistant-text

Conversation

@xquanluu

Copy link
Copy Markdown
Contributor

xquanluu and others added 2 commits September 18, 2026 10:18
When a model emitted text before calling a tool, every adapter dropped
it: the appended assistant turn went on the wire with content null (or
with only tool_use/functionCall blocks). On the post-tool re-prompt the
model had no record of having spoken, so it said the same sentence
again — and since that turn is streamed to TTS, the caller hears it
twice.

appendAssistantToolCall now takes the pre-tool text and each adapter
carries it in its native shape: OpenAI content alongside tool_calls,
Anthropic and Bedrock a text block before the tool_use blocks, Gemini a
text part before the functionCall part. Blank text is omitted rather
than sent as an empty block, which Anthropic and Bedrock reject.

The argument is optional, so existing callers keep compiling and get
the old behaviour until they pass it.

Contract tests [22] and [23] cover both paths for every adapter.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Releasing is a separate step owned by someone else; this branch should
not carry a version bump.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@xquanluu
xquanluu marked this pull request as ready for review September 21, 2026 12:10
@davehorton
davehorton merged commit 7503c3c into main Sep 21, 2026
2 checks passed
@xquanluu
xquanluu deleted the fix/tool-call-assistant-text branch September 21, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants