Fix agent session continuity and tool metadata mapping#5
Conversation
This change addresses the issue where the AI agent would end sessions prematurely instead of maintaining a continuous tool-use loop. Key improvements: 1. Session Continuity: Implemented stable `ConversationId` generation based on the first message of a conversation. This ensures that subsequent turns are associated with the same session on the AWS CodeWhisperer backend. Added support for client-provided `conversation_id` in the Anthropic request. 2. Structured Tool Metadata: Updated the mapping logic to correctly extract and include `tool_use` and `tool_result` blocks into CodeWhisperer's structured fields (`toolUses` and `toolResults`) for both the current message and the conversation history. 3. Expanded Data Structures: Modified `HistoryUserMessage` and `HistoryAssistantMessage` to support full structured metadata storage. 4. Response Continuity: The proxy now returns the `conversation_id` back to the client in the Anthropic response payload. These changes allow the model to correctly reference its previous tool calls and their results, enabling stable agentic behavior. Includes new tests for session continuity and tool mapping. Co-authored-by: alexandephilia <43126944+alexandephilia@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52fe1a142c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Heuristic: Use the first user message as a stable seed for the conversation. | ||
| // Note: We skip potential system prompts or earlier turns to keep it stable. | ||
| firstMsg := anthropicReq.Messages[0] | ||
| cwReq.ConversationState.ConversationId = generateDeterministicUUID(getMessageContent(firstMsg.Content)) |
There was a problem hiding this comment.
Avoid deriving session ID solely from first message
Generating conversationId from only getMessageContent(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 send conversation_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 👍 / 👎.
This change addresses the issue where the AI agent would end sessions prematurely instead of maintaining a continuous tool-use loop.
Key improvements:
ConversationIdgeneration based on the first message of a conversation. This ensures that subsequent turns are associated with the same session on the AWS CodeWhisperer backend. Added support for client-providedconversation_idin the Anthropic request.tool_useandtool_resultblocks into CodeWhisperer's structured fields (toolUsesandtoolResults) for both the current message and the conversation history.HistoryUserMessageandHistoryAssistantMessageto support full structured metadata storage.conversation_idback to the client in the Anthropic response payload.These changes allow the model to correctly reference its previous tool calls and their results, enabling stable agentic behavior.
Includes new tests for session continuity and tool mapping.
PR created automatically by Jules for task 8798216175317638949 started by @alexandephilia