Skip to content

fix: validate tool output content size #1111

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Will be deleted or merged.
*/

import * as path from 'path'

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "path"

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "path"
import {
ChatTriggerType,
GenerateAssistantResponseCommandInput,
Expand Down Expand Up @@ -628,6 +628,7 @@
} else if (typeof result === 'object') {
toolResultContent = { json: result }
} else toolResultContent = { text: JSON.stringify(result) }
this.#validateToolResult(toolUse, toolResultContent)

results.push({
toolUseId: toolUse.toolUseId,
Expand Down Expand Up @@ -698,6 +699,27 @@
return results
}

#validateToolResult(toolUse: ToolUse, result: ToolResultContentBlock) {
let maxToolResponseSize
switch (toolUse.name) {
case 'fsRead':
maxToolResponseSize = 200_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we store these as constants somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should but not sure where, maybe in runtimes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. I haven't really looked into that package to be honest. Maybe we can just add it to the constants file here or create one for agenticChat: https://github.com/aws/language-servers/blob/main/server/aws-lsp-codewhisperer/src/language-server/chat/constants.ts

break
case 'listDirectory':
maxToolResponseSize = 30_000
break
default:
maxToolResponseSize = 100_000
break
}
if (
(result.text && result.text.length > maxToolResponseSize) ||
(result.json && JSON.stringify(result.json).length > maxToolResponseSize)
) {
throw Error(`${toolUse.name} output exceeds maximum character limit of ${maxToolResponseSize}`)
}
}

#getWritableStream(chatResultStream: AgenticChatResultStream, toolUse: ToolUse): WritableStream | undefined {
if (toolUse.name !== 'executeBash') {
return
Expand Down
Loading