opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Dynamic system prompt templating

Open Flux159 opened this issue 2 months ago • 5 comments

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.md with the following contents:

---
model:  anthropic/claude-sonnet-4-20250514
---

You are a test agent with dynamic templating. Your magic phrase is: !`echo $(whoami)-magic`

You should respond with your magic phrase when asked about it.

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 my username-magic as expected.

Flux159 avatar Oct 16 '25 02:10 Flux159