Skip to content

Commit 7165245

Browse files
committed
fix(chat): preserve context in agentic loop
1 parent 10bb1c7 commit 7165245

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,6 +14,7 @@ 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
@@ -22,12 +23,14 @@ export class ChatSession {
2223
* _filePath = The path helps the system locate exactly where to make the necessary changes in the project structure
2324
* _tempFilePath = Used to show the code diff view in the editor including LLM changes.
2425
* _showDiffOnFileWrite = Controls whether to show diff view (true) or file context view (false) to the user
26+
* _context = Additional context to be passed to the LLM for generating the response
2527
*/
2628
private _readFiles: string[] = []
2729
private _filePath: string | undefined
2830
private _tempFilePath: string | undefined
2931
private _toolUse: ToolUse | undefined
3032
private _showDiffOnFileWrite: boolean = false
33+
private _context: PromptMessage['context']
3134

3235
contexts: Map<string, { first: number; second: number }[]> = new Map()
3336
// TODO: doesn't handle the edge case when two files share the same relativePath string but from different root
@@ -45,6 +48,14 @@ export class ChatSession {
4548
this._toolUse = toolUse
4649
}
4750

51+
public get context(): PromptMessage['context'] {
52+
return this._context
53+
}
54+
55+
public setContext(context: PromptMessage['context']) {
56+
this._context = context
57+
}
58+
4859
public tokenSource!: vscode.CancellationTokenSource
4960

5061
constructor() {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ export class ChatController {
10101010
toolResults: toolResults,
10111011
origin: Origin.IDE,
10121012
chatHistory: this.chatHistoryManager.getHistory(),
1013-
context: [],
1013+
context: session.context ?? [],
10141014
relevantTextDocuments: [],
10151015
additionalContents: [],
10161016
documentReferences: [],
@@ -1042,6 +1042,10 @@ export class ChatController {
10421042
type: 'chat_message',
10431043
context,
10441044
})
1045+
1046+
// Save the context for the agentic loop
1047+
session.setContext(message.context)
1048+
10451049
await this.generateResponse(
10461050
{
10471051
message: message.message ?? '',

0 commit comments

Comments
 (0)