Skip to content

Commit 44a7dbc

Browse files
authored
fix(chat): preserve context in agentic loop
1 parent ab8ba5e commit 44a7dbc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/core/src/codewhispererChat/clients/chat/v0/chat.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ import { ToolkitError } from '../../../../shared/errors'
1414
import { createCodeWhispererChatStreamingClient } from '../../../../shared/clients/codewhispererChatClient'
1515
import { createQDeveloperStreamingClient } from '../../../../shared/clients/qDeveloperChatClient'
1616
import { UserWrittenCodeTracker } from '../../../../codewhisperer/tracker/userWrittenCodeTracker'
17+
import { PromptMessage } from '../../../controllers/chat/model'
1718

1819
export class ChatSession {
1920
private sessionId?: string
2021
/**
2122
* _readFiles = list of files read from the project to gather context before generating response.
2223
* _showDiffOnFileWrite = Controls whether to show diff view (true) or file context view (false) to the user
24+
* _context = Additional context to be passed to the LLM for generating the response
2325
*/
2426
private _readFiles: string[] = []
2527
private _toolUse: ToolUse | undefined
2628
private _showDiffOnFileWrite: boolean = false
29+
private _context: PromptMessage['context']
2730

2831
contexts: Map<string, { first: number; second: number }[]> = new Map()
2932
// TODO: doesn't handle the edge case when two files share the same relativePath string but from different root
@@ -41,6 +44,14 @@ export class ChatSession {
4144
this._toolUse = toolUse
4245
}
4346

47+
public get context(): PromptMessage['context'] {
48+
return this._context
49+
}
50+
51+
public setContext(context: PromptMessage['context']) {
52+
this._context = context
53+
}
54+
4455
public tokenSource!: vscode.CancellationTokenSource
4556

4657
constructor() {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ export class ChatController {
709709
toolResults: toolResults,
710710
origin: Origin.IDE,
711711
chatHistory: this.chatHistoryManager.getHistory(),
712-
context: [],
712+
context: session.context ?? [],
713713
relevantTextDocuments: [],
714714
additionalContents: [],
715715
documentReferences: [],
@@ -1081,6 +1081,10 @@ export class ChatController {
10811081
type: 'chat_message',
10821082
context,
10831083
})
1084+
1085+
// Save the context for the agentic loop
1086+
session.setContext(message.context)
1087+
10841088
await this.generateResponse(
10851089
{
10861090
message: message.message ?? '',

0 commit comments

Comments
 (0)