Skip to content

fix(adk): keep assistant text role in Anthropic multi-turn history - #3289

Open
halcyon-r wants to merge 1 commit into
kagent-dev:mainfrom
halcyon-r:fix/anthropic-assistant-text-role
Open

halcyon-r wants to merge 1 commit into
kagent-dev:mainfrom
halcyon-r:fix/anthropic-assistant-text-role

Conversation

@halcyon-r

Copy link
Copy Markdown

Fixes #3026

genaiContentsToAnthropicMessages computed the incoming role once but only used it
on the tool-call branch; the plain-text branch hardcoded
anthropic.MessageParamRoleUser, so a prior assistant text turn in multi-turn
history was replayed to the provider labelled as the user.

Since the Messages API merges consecutive same-role messages into a single turn,
affected sessions don't error out — the model just sees its own earlier replies as
user speech, which silently degrades multi-turn response quality.

  • Use the incoming role on the plain-text path, matching the existing tool-call
    branch mapping (model/assistant → assistant role; anything else keeps the
    user default).
  • Behavior is unchanged for single-turn requests and empty-role contents.
  • Add TestGenaiContentsToAnthropicMessagesKeepsAssistantTextRole covering a
    user/model/user/assistant plain-text history — the reproduction case from [BUG] Go ADK Anthropic adapter labels a prior assistant text turn as "user" in multi-turn history #3026,
    including the assistant role spelling alongside model.

Testing: go test ./pkg/models/... in go/adk (all pass) and go vet clean.

@github-actions github-actions Bot added the bug Something isn't working label Oct 20, 2026
@halcyon-r

Copy link
Copy Markdown
Author

Hi @supreme-gg-gg @dimetron, could you take a look at this PR when you get a chance? The CI workflows are also waiting for maintainer approval to run. Thanks!

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because of no activity in the last 15 days. It will be closed in the next 5 days unless it is tagged "no stalebot" or other activity occurs.

@github-actions github-actions Bot added the stale This issue or PR has become stale label Nov 10, 2026
The plain-text branch of genaiContentsToAnthropicMessages hardcoded the user role, so a prior assistant text turn in multi-turn history was replayed to the provider as a user turn. Use the incoming role the same way the tool-call branch already does.

Fixes kagent-dev#3026

Signed-off-by: hairuiyang <hairuiyang@deeproute.ai>
@halcyon-r
halcyon-r force-pushed the fix/anthropic-assistant-text-role branch from 888c0e2 to 3179a74 Compare November 10, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working stale This issue or PR has become stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Go ADK Anthropic adapter labels a prior assistant text turn as "user" in multi-turn history

1 participant