-
Notifications
You must be signed in to change notification settings - Fork 751
feat(chat): Initial Agentic Chat loop Setup #6844
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
jpinkney-aws
merged 4 commits into
aws:feature/agentic-chat
from
ashishrp-aws:feature/agentic-chat
Mar 25, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3c8e737
Initial Agentic loop Setup
ashishrp-aws f0d6050
Merge branch 'feature/agentic-chat' into feature/agentic-chat
ashishrp-aws b4b7a3d
Removing Environment state objects from converter and addressing othe…
ashishrp-aws 545870e
Removed merge conflicts
ashishrp-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ import { EditorContextCommand } from '../../commands/registerCommands' | |
| import { PromptsGenerator } from './prompts/promptsGenerator' | ||
| import { TriggerEventsStorage } from '../../storages/triggerEvents' | ||
| import { SendMessageRequest } from '@amzn/amazon-q-developer-streaming-client' | ||
| import { CodeWhispererStreamingServiceException } from '@amzn/codewhisperer-streaming' | ||
| import { CodeWhispererStreamingServiceException, Origin, ToolResult } from '@amzn/codewhisperer-streaming' | ||
| import { UserIntentRecognizer } from './userIntent/userIntentRecognizer' | ||
| import { CWCTelemetryHelper, recordTelemetryChatRunCommand } from './telemetryHelper' | ||
| import { CodeWhispererTracker } from '../../../codewhisperer/tracker/codewhispererTracker' | ||
|
|
@@ -81,6 +81,7 @@ import { | |
| } from '../../constants' | ||
| import { ChatSession } from '../../clients/chat/v0/chat' | ||
| import { ChatHistoryManager } from '../../storages/chatHistory' | ||
| import { FsRead, FsReadParams } from '../../tools/fsRead' | ||
|
|
||
| export interface ChatControllerMessagePublishers { | ||
| readonly processPromptChatMessage: MessagePublisher<PromptMessage> | ||
|
|
@@ -577,6 +578,8 @@ export class ChatController { | |
| const newFileDoc = await vscode.workspace.openTextDocument(newFilePath) | ||
| await vscode.window.showTextDocument(newFileDoc) | ||
| telemetry.ui_click.emit({ elementId: 'amazonq_createSavedPrompt' }) | ||
| } else if (message.action.id === 'confirm-tool-use') { | ||
| await this.processToolUseMessage(message) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -834,10 +837,108 @@ export class ChatController { | |
| } | ||
| } | ||
|
|
||
| private async processToolUseMessage(message: CustomFormActionMessage) { | ||
| const tabID = message.tabID | ||
| if (!tabID) { | ||
| return | ||
| } | ||
| this.editorContextExtractor | ||
| .extractContextForTrigger('ChatMessage') | ||
| .then(async (context) => { | ||
| const triggerID = randomUUID() | ||
| this.triggerEventsStorage.addTriggerEvent({ | ||
| id: triggerID, | ||
| tabID: message.tabID, | ||
| message: undefined, | ||
| type: 'chat_message', | ||
| context, | ||
| }) | ||
| const session = this.sessionStorage.getSession(tabID) | ||
| const toolUse = session.toolUse | ||
| if (!toolUse || !toolUse.input) { | ||
| return | ||
| } | ||
| session.setToolUse(undefined) | ||
|
|
||
| let result: any | ||
| const toolResults: ToolResult[] = [] | ||
| try { | ||
| switch (toolUse.name) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you comment things out here intentionally?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes....write tools aren't merged yet. |
||
| // case 'execute_bash': { | ||
| // const executeBash = new ExecuteBash(toolUse.input as unknown as ExecuteBashParams) | ||
| // await executeBash.validate() | ||
| // result = await executeBash.invoke(process.stdout) | ||
| // break | ||
| // } | ||
| case 'fs_read': { | ||
| const fsRead = new FsRead(toolUse.input as unknown as FsReadParams) | ||
| await fsRead.validate() | ||
| result = await fsRead.invoke() | ||
| break | ||
| } | ||
| // case 'fs_write': { | ||
| // const fsWrite = new FsWrite(toolUse.input as unknown as FsWriteParams) | ||
| // const ctx = new DefaultContext() | ||
| // result = await fsWrite.invoke(ctx, process.stdout) | ||
| // break | ||
| // } | ||
| // case 'open_file': { | ||
| // result = await openFile(toolUse.input as unknown as OpenFileParams) | ||
| // break | ||
| // } | ||
| default: | ||
| break | ||
| } | ||
| toolResults.push({ | ||
| content: [ | ||
| result.output.kind === 'text' | ||
| ? { text: result.output.content } | ||
| : { json: result.output.content }, | ||
| ], | ||
| toolUseId: toolUse.toolUseId, | ||
| status: 'success', | ||
| }) | ||
| } catch (e: any) { | ||
| toolResults.push({ content: [{ text: e.message }], toolUseId: toolUse.toolUseId, status: 'error' }) | ||
| } | ||
|
|
||
| this.chatHistoryManager.appendUserMessage({ | ||
| userInputMessage: { | ||
| content: 'Tool Results', | ||
| userIntent: undefined, | ||
| origin: Origin.IDE, | ||
| }, | ||
| }) | ||
ashishrp-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await this.generateResponse( | ||
| { | ||
| message: 'Tool Results', | ||
ashishrp-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| trigger: ChatTriggerType.ChatMessage, | ||
| query: undefined, | ||
| codeSelection: context?.focusAreaContext?.selectionInsideExtendedCodeBlock, | ||
| fileText: context?.focusAreaContext?.extendedCodeBlock, | ||
| fileLanguage: context?.activeFileContext?.fileLanguage, | ||
| filePath: context?.activeFileContext?.filePath, | ||
| matchPolicy: context?.activeFileContext?.matchPolicy, | ||
| codeQuery: context?.focusAreaContext?.names, | ||
| userIntent: undefined, | ||
| customization: getSelectedCustomization(), | ||
| context: undefined, | ||
| toolResults: toolResults, | ||
| origin: Origin.IDE, | ||
| }, | ||
| triggerID | ||
| ) | ||
| }) | ||
| .catch((e) => { | ||
| this.processException(e, tabID) | ||
| }) | ||
| } | ||
|
|
||
| private async processPromptMessageAsNewThread(message: PromptMessage) { | ||
| this.editorContextExtractor | ||
| .extractContextForTrigger('ChatMessage') | ||
| .then((context) => { | ||
| .then(async (context) => { | ||
| const triggerID = randomUUID() | ||
| this.triggerEventsStorage.addTriggerEvent({ | ||
| id: triggerID, | ||
|
|
@@ -850,9 +951,10 @@ export class ChatController { | |
| userInputMessage: { | ||
| content: message.message, | ||
| userIntent: message.userIntent, | ||
| origin: Origin.IDE, | ||
| }, | ||
| }) | ||
| return this.generateResponse( | ||
| await this.generateResponse( | ||
| { | ||
| message: message.message, | ||
| trigger: ChatTriggerType.ChatMessage, | ||
|
|
@@ -867,6 +969,7 @@ export class ChatController { | |
| customization: getSelectedCustomization(), | ||
| context: message.context, | ||
| chatHistory: this.chatHistoryManager.getHistory(), | ||
| origin: Origin.IDE, | ||
| }, | ||
| triggerID | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we don't need to do this anymore because we changed the tool index from
index_schematoindexSchema