-
Notifications
You must be signed in to change notification settings - Fork 6k
Dynamic system prompt templating #3202
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
base: dev
Are you sure you want to change the base?
Conversation
- Add Template utility for processing bash commands in ! syntax - Support file:// URLs in agent prompts for loading external files - Enable dynamic content generation in system prompts using same logic as commands - Add comprehensive tests covering templating, file loading, and error handling - Backward compatible with existing static prompts
- Extend Template utility to support both shell (!) and file (@file) templating - Handle non-git repositories by falling back to Instance.directory when worktree is root - Add comprehensive tests for file references, directory listings, and combined templating - Support tilde paths (~/.file) and graceful error handling for missing files - Enable full command-style templating capabilities in agent system prompts
- Inline file:// URL processing and templating directly in resolveSystemPrompt - Remove unnecessary resolveAgentPrompt helper function and _internal export - Focus tests on Template utility rather than internal implementation details - Maintain full functionality while improving code organization - Clean up test structure and remove code smells
- Remove file:// URL handling as it's already processed elsewhere in the pipeline - Keep only the Template.process call for bash commands and file references - Simplify implementation to focus on core templating functionality
|
This is a good start, I will branch off and change it to be a little more in line with what i had in mind, thanks for PR |
| agent, | ||
| system: input.system, | ||
| }) | ||
|
|
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.
Just an fyi for your branch, I've been using this locally for a few days with opencode run "" --print-logs and found it useful to add some logs here to help debug system prompts:
log.info(`Agent name: ${agent.name}`);
log.info("Agent parameters", {
name: agent.name,
temperature: agent.temperature,
topP: agent.topP,
options: agent.options,
});
log.info(`Resolved System Prompt: ${system.join("\n")}`);
| })(), | ||
| })()), | ||
| ) | ||
| system.push(...(await SystemPrompt.environment())) |
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.
There's a separate issue around allowing environment to be optional in system prompts #1894 (saw this when logging) - code pointer should be here
772b621 to
eb855e1
Compare
f1dc981 to
3e15a39
Compare
f8ee907 to
6a9856d
Compare
|
Will this be resolved only at session start or on each new message? There are use-cases for both and I would wish for not limiting to only do it at session start. One problem is of course overhead if if the stuff being executed are expensive. Options
|
|
rn we do resolve the system prompt stuff every time you send a prompt, I do see what you mean tho.. |
Well, to be clear: I do not want that possibility removed! Resolving on each message enables me to do things that would not be possible otherwise. So please do not remove this pattern of resolving on each message. Either keep it as-is and document the behaviour or make it configurable as a part of the agent/global config. |
|
Any plans for this? @rekram1-node wrote
As I understand it doing ! I think it should be supported universally, including
This would unlock a lot. For example I have a skill which I use to create anki style flashcards. I would like it to include valid tags i use for my cards automatically whenever the skill is invoked/loaded. |
|
Was looking through the docs for if there was a way to do this, and found this PR. Would love this feature so I can include other files dynamically as context within the custom agents instructions. (or if there's another way to do that, I'd like to know) |
Summary:
Adding the ability to parse markdown templating for agent system prompts. Specifically adds ability to parse
!and@references inside of agent prompts.This PR adds a helper util/template.ts that handles both bash & file reference templates, then uses this inside of session/prompt.ts. The rest is just automated testing for the functionality.
This is specifically for #3195
Test plan:
Manually tested by making a custom agent inside of
.opencode/agent/test.mdwith the following contents:Then opening opencode dev mode:
bun dev, switching to the test agent via/agents, then asking "What is your magic phrase" and it responded with myusername-magicas expected.