Skip to content

fix: add formatChatHistoryMessage to chatDb #1110

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
merged 1 commit into from
Apr 24, 2025
Merged

Conversation

tsmithsz
Copy link
Contributor

@tsmithsz tsmithsz commented Apr 24, 2025

Related Code on Agentic Chat

https://github.com/aws/aws-toolkit-vscode/blob/feature/agentic-chat/packages/core/src/shared/db/chatDb/chatDb.ts#L298

Problem

We only need the toolResult in the userMessageContext. This is causing validation exceptions as we are not taking the other fields into account when calculating the character count in the history and are hence not getting an accurate figure for the history length. As a result, we think the history is valid.

Solution

Only store the toolResult in userMessageContext

Testing

Verified that the history file now only stores toolResult in userMessageContext:

"messages": [
                    {
                        "body": "run ls && pwd",
                        "type": "prompt",
                        "origin": "IDE",
                        "userInputMessageContext": {}
                    },
                    {
                        "body": "I'll run the `ls` command to list the files in the current directory and then `pwd` to show the current working directory.",
                        "type": "answer",
                        "toolUses": [
                            {
                                "toolUseId": "tooluse_eFrk87EMQ9GSwENNdhvhvw",
                                "name": "executeBash",
                                "input": {
                                    "command": "ls && pwd",
                                    "cwd": "/Users/tsmithsz/Downloads/Metrics",
                                    "explanation": "Running ls to list files and pwd to show the current working directory"
                                }
                            }
                        ]
                    },
                    {
                        "body": "",
                        "type": "prompt",
                        "origin": "IDE",
                        "userInputMessageContext": {
                            "toolResults": [
                                {
                                    "toolUseId": "tooluse_eFrk87EMQ9GSwENNdhvhvw",
                                    "status": "success",
                                    "content": [
                                        {
                                            "json": {
                                                "output": {
                                                    "kind": "json",
                                                    "content": {
                                                        "exitStatus": "0",
                                                        "stdout": "AmazonQ.md\nREADME.md\nSYSTEMPROMPTOVERRIDE.md\ncontroller.ts\ndata\ndata_transform\ninfra\nmanifest_monthly.json\nmanifest_weekly.json\nrequirements.txt\ntable.md\ntests\ntrust-policy.json\n\n/Users/tsmithsz/Downloads/Metrics\n",
                                                        "stderr": ""
                                                    },
                                                    "success": true
                                                }
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "body": "\n\nThe command executed successfully. You're currently in the `/Users/tsmithsz/Downloads/Metrics` directory, which contains:\n\nFiles:\n- AmazonQ.md\n- README.md\n- SYSTEMPROMPTOVERRIDE.md\n- controller.ts\n- manifest_monthly.json\n- manifest_weekly.json\n- requirements.txt\n- table.md\n- trust-policy.json\n\nDirectories:\n- data\n- data_transform\n- infra\n- tests\n\nIs there anything specific about this project you'd like to explore or work on?",
                        "type": "answer",
                        "toolUses": []
                    }
                ]

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@tsmithsz tsmithsz requested a review from a team as a code owner April 24, 2025 05:36
@tsmithsz tsmithsz merged commit 353843a into aws:main Apr 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants