-
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
[Theia AI] Support prompt fragments #14899
Comments
VS Code also introduced prompt management and reusable prompts. We should evaluate whether we want to align Theia's prompt management. |
I had a look. It is pretty similar, but I like our UI integration a lot better for now. |
We could allow to place prompt variables in the context, though so they get part of the system prompt. @planger WDYT? |
The VS Code concept for prompt templates is pretty similar indeed. I only see two real differences:
TL;DR:
Turning Prompt Template Variables into Context VariableMaking prompt variables context variables in addition, could be a nice extra feature and would lead to consistency with VS Code. |
@JonasHelming For the UI part, should we also add auto completion in the chat for the prompt template ids? With just defining the variable, users need to know and type the full prompt template id. |
Yes, and I believe this is conceptionally introduced in #14787 so it might make sense to branch of this PR. Added to the description |
In VS Code
Therefore
Edit: The |
@sdirix You are right, the file-relative links (and the MD syntactic sugar) is indeed what we would be missing at the moment. I missed that part. I think however that we aim at additional purposes with the #prompt variable (beyond the purposes that you could achieve with putting prompts into #files):
For both of these use cases, we don't want to use #file, because file is just pulling the file into the context, but doesn't replace the actual variable occurrence with the actual file content. (edit: so that's to me the main difference between #prompt and #file) Unrelated thought: |
I think eventually, we should support both. Reasoning: Prompts in Theia can come from various sources:
|
I think we can't keep it this way, in VS Code it seems it will evaluate the prompt as they specifically state
Once people use that they will complain that in Theia we just include the file without evaluating it. |
I will add this to our discussion agenda and post the results here |
Well I think this is up to the agent and in Theia AI we can keep it this way, imho. For Theia IDE default agents (which are the ones that will be in comparison to VS Code Copilot), we just have to make sure to incorporate the referenced files in one way or another. |
Yes, we have to be aware that specific agents, specifically Coder can actually resolve these file themselve, which I claim to be beneficial compared to just adding them somewhere in the user prompt. I would claim the input is much more structured in the prompt then. for universal, we should likely resolve the files indeed. This will be posible with a variable btw. (e.g. #resolvedContext) |
@JonasHelming For the initial version of being able to reference prompt templates in the chat with auto-completion:
EDIT: The difference in implementation is very small. prompt templates from both services: prompt templates from prompt customization service only (my test template loaded from configured folder): |
Following the law of least suprise we should add all prompts I guess, but put the custom onces on top and maybe with a different symbol, WDYT? If you find the ordering strange than at least different symbol |
@JonasHelming With using a different icon, sorting custom first, and adding a detail text it would look like this: prompt-template-autocomplete.webm |
Looks very good to me! |
During implementation in #14985 it was discovered that functions referenced in prompt templates should be resolved in the end when the final prompt or chat message is resolved because functions require handling of function objects in addition to inline replacements. See #14985 (comment) For prompts, this is quite easy to do because the prompt service can simply be adapted to first resolve all variables and then resolve all functions based on the prompt with already resolved variables. For chat message, there is no clear solution with the current approach of the chat request parser. Furthermore, it seems beneficial to unify the parsing and resolving of chat messages and prompts to avoid duplicate code adaptions like in this case. Unification of Prompt and Chat Message Parsing in TheiaAIObjectiveExplore the possibility of unifying the parsing logic for prompts and chat messages while allowing a distinction in how variables and functions are specified, i.e. prompts use Chat Parser Issues and Limitations
Difference to Prompt ServiceThe prompt service does not follow the same parsing approach as chat messages. In the prompt service, resolution occurs inline, and additional data (such as functions) are returned separately. This raises the question whether the part approach is really necessary for chat parsing. IdeaAnalyse whether we can unify parsing of prompts and chat messages. The parsed result could contain the full unresolved text and the fully resolved text (prompt text). At the core, this is what the parts provide: Access to the unresolved and resolved text. |
Thanks for bringing this up! Consolidation indeed seems to make sense here, however, aside from the slight variations in the patterns The chat service has those track-and-replace patterns (like This is in contrast to variable parsing, which don't need to be tracked, but resolved recursively, handling potentially cyclic dependencies, and ideally involving caching to avoid multiple resolutions for one overall message (see also #15000). The other dimension is whether the parsing takes place in the context of a chat session or outside. In a chat session currently there is the additional agent parsing (like Another side requirement to the parsing might be, especially in the chat case, that it'd be great to know afterwards which patterns where successfully matched at which character indexes. This is useful to e.g. highlight the respective parts of the chat request in the chat UI. Currently I think we plainly highlight all occurrences that match the pattern, but not if those were actually successful: I certainly don't want to overload this issue, but I think this may be helpful to capture the current differences, requirements, and clients of the parser. |
In summary: it looks like we may consider actually split the parsing of variables and all other patterns, because they differ in their nature. They should be resolved before the track-and-replace patterns are matched, they should be resolved recursively, we may need to guard cycles, and may need caching. This feels different from parsing the track-and-replace patterns once the message was completely unfolded. |
SummaryI think we can cover the requirements by having a unified, configurable parser that tracks all resolved patterns including matching ranges in the original text. Consumers (i.e. chat ui or prompt consumers) can then just use the tracked information they need. DetailsThanks for the extensive elaboration! Here are my thoughts on this.
At least for functions, the same is done in the prompt service. I could see unifying this in two ways:
Generally, I think parsing could even be an extensible concept where dev users of Theia Ai can contribute new patterns and parser logic to be added to the parsed result. Custom agents could then access this information.
I agree with this except for the no-tracking need for chat ui reasons (as you elaborated, see more later). As I see it, the resolving, caching, etc. can be implemented independently of the other changes because resolving variables goes through the AIVariableService already. The service implementation could and should hide implementing the details.
This certainly is an important point. I think we could still solve this with the approach above where you tell the parser which patterns to parse. With this, we could have one unified parser that only parses relevant patterns. Or even if everything is parsed, the tracking results could just be ignored depending on the use case.
I think this is also the origin of the parts returned by the chat request parser. However, I'm not sure we need the part approach to achieve this. If we just generally track this information, this could IMO also be used in a unified way. The downside for the prompt case would be that more information is tracked than needed. However, storing the tracking results should not be that much overhead because we have to do the resolving anyway.
I agree that we might need to split them. For the chat ui, we still might want to track the variables, too, as elaborated earlier. Essentially, I think we apply a similar approach as with the track-and-replace patters with the one exception that we need to resolve and replace variables first. Recursive resolving of variables should IMO be handled by the variable service to encapsulate this behavior. Also, the chat ui (probably?!) does not need to know about the recursive variable resolutions as only the initial one can be highlighted in the chat window. |
Prompt fragments allow to define parts of prompts in a reusable way. You can embed these prompts then via a variable in the chat or in our prompt templates. This also allows to have a set of prompts available in the chat without always defining a custom agent.
Step 1: Allow referencing prompt fragments
The PromptCustomizationService should already load any file in the prompt service. When we add a file there which does not have the id of an agent, we assume it is a resuable prompt.
We now need a variable "#prompt:${promptId}" that resolves to the prompt with the specified id. We need to check the resolvement logic in the prompt service so that variables and function occuring in injected prompt fragments are resolved , too. same applies for chat messages.
With this, the user can add a prompt fragment by just placing a file e.g. myprompt.prompttemplate in the prompt templates directory and then use it via "#prompt:myprompt". "myPrompt" gets auto completed.
Step 2: Add UI
Add a new tab to the AI configuration view showing a list of all loaded prompt templates allowing to:
The text was updated successfully, but these errors were encountered: