Skip to content

Commit 093d5bc

Browse files
authored
fix(chat): request fails if character limit exceeded (aws#6938)
## Problem Chat request fails if tool output exceeds the character length limit of 800,000. ## Solution Handle this and send a error result instead of a success result back to the LLM. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 5d63306 commit 093d5bc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import {
8888
} from '../../constants'
8989
import { ChatSession } from '../../clients/chat/v0/chat'
9090
import { amazonQTabSuffix } from '../../../shared/constants'
91-
import { OutputKind } from '../../tools/toolShared'
91+
import { maxToolOutputCharacterLength, OutputKind } from '../../tools/toolShared'
9292
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9393
import { ChatStream } from '../../tools/chatStream'
9494
import { ChatHistoryStorage } from '../../storages/chatHistoryStorage'
@@ -674,6 +674,11 @@ export class ChatController {
674674
undefined
675675
)
676676
const output = await ToolUtils.invoke(tool, chatStream)
677+
if (output.output.content.length > maxToolOutputCharacterLength) {
678+
throw Error(
679+
`Tool output exceeds maximum character limit of ${maxToolOutputCharacterLength}`
680+
)
681+
}
677682

678683
toolResults.push({
679684
content: [

packages/core/src/codewhispererChat/tools/toolShared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path'
77
import fs from '../../shared/fs/fs'
88

99
export const maxToolResponseSize = 30720 // 30KB
10+
export const maxToolOutputCharacterLength = 800_000
1011

1112
export enum OutputKind {
1213
Text = 'text',

0 commit comments

Comments
 (0)