From cd4372368efad706c67f775819af9d3749bcebe3 Mon Sep 17 00:00:00 2001 From: maxiaoyang <2768753269@qq.com> Date: Wed, 29 Apr 2026 21:04:37 +0800 Subject: [PATCH] feat(providers/anthropic): prefix user content with sender name Sibling change to the anthropic_messages adapter, this time for the SDK-based path that talks to the official Anthropic endpoint via anthropic-sdk-go. The Messages API there is the same shape, so the fix is identical: wrap user content with messageutil.ApplyUserNamePrefix when the message carries Name attribution; tool result blocks pass through unchanged. The prefix is applied at marshal time only; the persisted message is not mutated. Existing single-user / direct-channel flows are unaffected because Name is empty there. Existing provider tests continue to pass; behavior is exercised by the messageutil unit tests (which cover ApplyUserNamePrefix exhaustively) and the agent-level integration tests added earlier. Refs #2702. --- pkg/providers/anthropic/provider.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/providers/anthropic/provider.go b/pkg/providers/anthropic/provider.go index 6f4aadb8b..a3704cdf3 100644 --- a/pkg/providers/anthropic/provider.go +++ b/pkg/providers/anthropic/provider.go @@ -11,6 +11,7 @@ import ( "github.com/anthropics/anthropic-sdk-go/option" "github.com/sipeed/picoclaw/pkg/providers/common" + "github.com/sipeed/picoclaw/pkg/providers/messageutil" "github.com/sipeed/picoclaw/pkg/providers/protocoltypes" ) @@ -170,8 +171,11 @@ func buildParams( anthropic.NewUserMessage(anthropic.NewToolResultBlock(msg.ToolCallID, msg.Content, false)), ) } else { + // Anthropic has no per-message author identity; render any + // sender attribution as a `[name] ` prefix without mutating + // the persisted message. anthropicMessages = append(anthropicMessages, - anthropic.NewUserMessage(anthropic.NewTextBlock(msg.Content)), + anthropic.NewUserMessage(anthropic.NewTextBlock(messageutil.ApplyUserNamePrefix(msg))), ) } case "assistant":