-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
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.