-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(ai): Enable Context Variables for Chat Requests #14787
Open
planger
wants to merge
5
commits into
master
Choose a base branch
from
planger/request-context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
99f4536
to
52825d5
Compare
4650527
to
50de13b
Compare
19 tasks
This PR introduces support for adding context elements (e.g., files, symbols, or variables) to chat requests, allowing chat agents to leverage additional context without embedding it directly in user input. - Extended the existing *variable* concept with `AIContextVariable`. - Context variables can provide a dedicated `contextValue` that agents can use separately from the chat request text. - Context variables can be included in chat requests in two ways: 1. Providing `AIVariableResolutionRequest` alongside the `ChatRequest`. 2. Mentioning a context variable directly in the chat request text (e.g., `#file:abc.txt`). - Extended the chat input widget to display and manage context variables. - Users can add context variables via: 1. A `+` button, opening a quick pick list of available context variables. 2. Typing a context variable (`#` prefix), with auto-completion support. - Theia’s label provider is used to display context variables in a user-friendly format. - Enhanced support for variable arguments when adding context variables via the UI. - Introduced: - `AIVariableArgPicker` for UI-based argument selection. - `AIVariableArgCompletionProvider` for auto-completion of variable arguments. - Added a new context variable `#file` that accepts a file path as an argument. - Refactored `QuickFileSelectService` for consistent file path selection across argument pickers and completion providers. - `ChatService` now resolves context variables and attaches `ResolvedAIContextVariable` objects to `ChatRequestModel`. - Variables can both: - Replace occurrences in chat text (`ResolvedAIVariable.value`). - Provide a separate `contextValue` for the chat model. Fixes #14839
b91da8a
to
647ee08
Compare
d2b81c4
to
fb4c2b5
Compare
This was referenced Feb 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What it does
This PR introduces the ability for users to add contextual information to chat requests. This allows manually passing elements such as files, symbols, or other variables, which chat agents can then utilize when generating responses.
Context Variables
To represent contextual elements, we extend the existing variables concept. Previously, variables were placeholders within chat request text (e.g.,
#selectedText
), dynamically resolved by the chat service before processing (ResolvedAIVariable.value
), replacing the occurrence of the variable directly in the user input.With this PR, we introduce context variables (
AIContextVariable
), which enhance the existing variables by not only resolving a value for text replacement but also attaching a dedicated context value (ResolvedAIContextVariable.contextValue
) to the chat request. This enables agents to use contextual information without making it a fixed part of the user’s input.Key Benefits:
Context Variable Resolution
Context variable requests (
AIVariableResolutionRequest
) can be passed alongside aChatRequest
to theChatService
. The chat service then resolves context variables and attaches them to theChatRequestModel
under thecontext
property.If a context variable is referenced in the chat request (e.g.,
#file:abc.txt
), it serves a dual purpose:ResolvedAIVariable.value
replaces the variable in the chat text.ResolvedAIContextVariable.contextValue
is added to the chat request model.Attaching Context Variables
Context variables can be added to a chat request in two ways:
AIVariableResolutionRequest
objects toChatService.sendRequest
alongside theChatRequest
.#file:abc.txt
). The chat service automatically parses it into a variable request and attaches it to the context.User Interface Enhancements
To support context variables, the chat input widget now maintains a list of added context variables. This list appears below the text input and utilizes Theia’s label provider mechanism for user-friendly display (including labels, additional information, and icons). Users can add context variables through:
+
button): Opens a selection dialog listing all registered context variables. To improve usability, theAIVariable
interface now includes optionallabel
andicon
properties.#
prefix): Users can type context variables directly into the chat input. The existing code completion mechanism suggests context variables, and selecting one also adds it to the context variable list.Variable Arguments
Variables support arguments (parameters) that influence their resolution. This PR enhances argument handling by introducing:
AIVariableArgPicker
: Invoked when users add context variables via the Quick Pick dialog (+
button).AIVariableArgCompletionProvider
: Invoked when users type context variables manually.With these two mechanisms, variable providers can choose how to support users in selecting the right arguments via a UI or via auto-completion.
Example: File Context Variable (
#file
)To demonstrate these improvements, we introduce a new context variable
#file
, which accepts a file path as an argument. We also register:#file
via the Quick Pick dialog.#
and get file path suggestions directly.Therefore, we've refactored existing code into a
QuickFileSelectService
to provide a consistent file picker experience for both argument pickers and completion providers as well as for the existing file search (Ctrl-p).Utilizing Chat Request Context
Chat agents can determine how they process the provided context. Common approaches include:
Fixes #14839
How to test
Use the
+
icon to add context filesadding-context-plus.webm
Use the context variable auto complete
adding-context-auto-complete.webm
Use the context variable argument auto complete
adding-context-auto-complete-arg.webm
Use drag and drop to add files to the context
adding-context-drop.webm
Follow-ups
Breaking changes
Attribution
Review checklist
Reminder for reviewers