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.
This commit is contained in:
parent
f89b4cdf48
commit
cd4372368e
1 changed files with 5 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/anthropics/anthropic-sdk-go/option"
|
"github.com/anthropics/anthropic-sdk-go/option"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/providers/common"
|
"github.com/sipeed/picoclaw/pkg/providers/common"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/providers/messageutil"
|
||||||
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -170,8 +171,11 @@ func buildParams(
|
||||||
anthropic.NewUserMessage(anthropic.NewToolResultBlock(msg.ToolCallID, msg.Content, false)),
|
anthropic.NewUserMessage(anthropic.NewToolResultBlock(msg.ToolCallID, msg.Content, false)),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
// Anthropic has no per-message author identity; render any
|
||||||
|
// sender attribution as a `[name] ` prefix without mutating
|
||||||
|
// the persisted message.
|
||||||
anthropicMessages = append(anthropicMessages,
|
anthropicMessages = append(anthropicMessages,
|
||||||
anthropic.NewUserMessage(anthropic.NewTextBlock(msg.Content)),
|
anthropic.NewUserMessage(anthropic.NewTextBlock(messageutil.ApplyUserNamePrefix(msg))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
case "assistant":
|
case "assistant":
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue