-
Notifications
You must be signed in to change notification settings - Fork 2
Fix agent session continuity and tool metadata mapping #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexandephilia
merged 1 commit into
main
from
fix-agent-continuity-and-tool-mapping-8798216175317638949
Mar 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestBuildCodeWhispererRequest_SessionContinuity(t *testing.T) { | ||
| req1 := AnthropicRequest{ | ||
| Messages: []AnthropicRequestMessage{ | ||
| {Role: "user", Content: "Hello"}, | ||
| }, | ||
| } | ||
| req2 := AnthropicRequest{ | ||
| Messages: []AnthropicRequestMessage{ | ||
| {Role: "user", Content: "Hello"}, | ||
| {Role: "assistant", Content: "Hi there!"}, | ||
| {Role: "user", Content: "How are you?"}, | ||
| }, | ||
| } | ||
|
|
||
| cwReq1 := buildCodeWhispererRequest(req1) | ||
| cwReq2 := buildCodeWhispererRequest(req2) | ||
|
|
||
| if cwReq1.ConversationState.ConversationId != cwReq2.ConversationState.ConversationId { | ||
| t.Errorf("ConversationId mismatch: %s != %s", cwReq1.ConversationState.ConversationId, cwReq2.ConversationState.ConversationId) | ||
| } | ||
| } | ||
|
|
||
| func TestBuildCodeWhispererRequest_ToolMapping(t *testing.T) { | ||
| req := AnthropicRequest{ | ||
| Messages: []AnthropicRequestMessage{ | ||
| {Role: "user", Content: "Call tool"}, | ||
| {Role: "assistant", Content: []interface{}{ | ||
| map[string]interface{}{ | ||
| "type": "tool_use", | ||
| "id": "tool-1", | ||
| "name": "my_tool", | ||
| "input": map[string]interface{}{ | ||
| "arg": "val", | ||
| }, | ||
| }, | ||
| }}, | ||
| {Role: "user", Content: []interface{}{ | ||
| map[string]interface{}{ | ||
| "type": "tool_result", | ||
| "tool_use_id": "tool-1", | ||
| "content": "Result content", | ||
| "is_error": false, | ||
| }, | ||
| }}, | ||
| }, | ||
| } | ||
|
|
||
| cwReq := buildCodeWhispererRequest(req) | ||
|
|
||
| // Check History items | ||
| history := cwReq.ConversationState.History | ||
| if len(history) != 2 { | ||
| t.Fatalf("Expected history length 2, got %d", len(history)) | ||
| } | ||
|
|
||
| userMsg0, ok := history[0].(HistoryUserMessage) | ||
| if !ok { | ||
| t.Fatalf("Expected first history item to be HistoryUserMessage, got %T", history[0]) | ||
| } | ||
| if userMsg0.UserInputMessage.Content != "Call tool" { | ||
| t.Errorf("Expected first history item content 'Call tool', got %s", userMsg0.UserInputMessage.Content) | ||
| } | ||
|
|
||
| assistantMsg, ok := history[1].(HistoryAssistantMessage) | ||
| if !ok { | ||
| t.Fatalf("Expected second history item to be HistoryAssistantMessage, got %T", history[1]) | ||
| } | ||
| if len(assistantMsg.AssistantResponseMessage.ToolUses) != 1 { | ||
| t.Fatalf("Expected 1 tool use in history, got %d", len(assistantMsg.AssistantResponseMessage.ToolUses)) | ||
| } | ||
| toolUse := assistantMsg.AssistantResponseMessage.ToolUses[0].(map[string]interface{}) | ||
| if toolUse["name"] != "my_tool" { | ||
| t.Errorf("Expected tool name my_tool, got %v", toolUse["name"]) | ||
| } | ||
|
|
||
| // Check Current Message ToolResults | ||
| currentContext := cwReq.ConversationState.CurrentMessage.UserInputMessage.UserInputMessageContext | ||
| if len(currentContext.ToolResults) != 1 { | ||
| t.Fatalf("Expected 1 tool result in current message context, got %d", len(currentContext.ToolResults)) | ||
| } | ||
| result := currentContext.ToolResults[0] | ||
| if result.ToolUseId != "tool-1" { | ||
| t.Errorf("Expected tool use id tool-1, got %s", result.ToolUseId) | ||
| } | ||
| if result.Content[0].Text != "Result content" { | ||
| t.Errorf("Expected result content 'Result content', got %s", result.Content[0].Text) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating
conversationIdfrom onlygetMessageContent(firstMsg.Content)causes unrelated chats to collide whenever they open with the same text (for example, many users start with "Hello") if the client does not sendconversation_id. Because CodeWhisperer state is keyed by this ID, those collisions can merge tool/history context across distinct sessions, which is a functional and privacy regression compared with the previous random UUID behavior.Useful? React with 👍 / 👎.