Documentation
¶
Overview ¶
Package prompt provides system prompt generation for the agent.
Package prompt provides system prompt generation for the agent.
Index ¶
- func CreateTemplatesDir(baseDir string) error
- func Environment(workspaceRoot string) string
- type Generator
- type PromptContext
- type RegistryInterface
- type TemplateConfig
- type TemplateEngine
- func (e *TemplateEngine) HasTemplate(name string) bool
- func (e *TemplateEngine) ListTemplates() []string
- func (e *TemplateEngine) Reload() error
- func (e *TemplateEngine) Render(name string, ctx any) (string, error)
- func (e *TemplateEngine) RenderString(tmplStr string, ctx PromptContext) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTemplatesDir ¶
CreateTemplatesDir creates the prompts directory structure for custom templates.
func Environment ¶
Environment describes where this session is running, so the model does not have to spend its first three tool calls finding out. None of it is derivable from the tool documentation, and all of it changes per session, which is exactly what belongs in a prompt and not in a template.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds system prompts based on enabled tools and configuration
func NewGenerator ¶
func NewGenerator(registry RegistryInterface, cfg *config.Config) (*Generator, error)
NewGenerator creates a new prompt generator. Returns an error if templates are enabled but fail to load.
func NewGeneratorWithEngine ¶
func NewGeneratorWithEngine(registry RegistryInterface, cfg *config.Config, engine *TemplateEngine) *Generator
NewGeneratorWithEngine creates a prompt generator with a specific template engine. Useful for testing or when the engine is already initialized.
func (*Generator) GenerateSystemPrompt ¶
GenerateSystemPrompt builds the complete system prompt. Returns an error if templates are enabled but fail to render.
type PromptContext ¶
type PromptContext struct {
// Configuration
WorkspaceRoot string
// Strong is the agent profile. Under it the prompt says what the schema
// cannot and stops there: no numbered workflow, no worked example, and the
// short form of each tool's documentation. Under the weak profile the
// longer prompts stay, so a run on a weaker model is unchanged.
Strong bool
// Environment describes where this session is running: platform, shell,
// working directory, date, git branch and status, and what is in the
// workspace root.
Environment string
EditMode string // "searchreplace", "patch", "lines"
PreviewMode bool
HasRead bool
HasEdit bool
HasWrite bool
HasSearch bool
HasGlob bool
HasShell bool
// Derived
Capabilities []string
SearchCommand string // "rg" or "grep"
// Tool categories for iteration
EnabledCategories []string
// Config reference for advanced template logic
Config *config.Config
}
PromptContext contains all data available to prompt templates.
func NewPromptContext ¶
func NewPromptContext(registry RegistryInterface, cfg *config.Config) PromptContext
NewPromptContext creates a PromptContext from the registry and config.
func (*PromptContext) CapabilitiesString ¶
func (c *PromptContext) CapabilitiesString() string
CapabilitiesString returns capabilities as a comma-separated string.
type RegistryInterface ¶
type RegistryInterface interface {
IsEnabled(name string) bool
GenerateToolPrompt() string
ToolsInCategory(category string) []toolsPkg.Tool
EnabledCategories() []string
}
RegistryInterface defines the registry methods needed for prompt generation
type TemplateConfig ¶
type TemplateConfig struct {
// TemplatesDir overrides embedded templates with filesystem directory
TemplatesDir string
// HotReload enables template reloading (dev mode)
HotReload bool
}
TemplateConfig holds configuration for template loading.
type TemplateEngine ¶
type TemplateEngine struct {
// contains filtered or unexported fields
}
TemplateEngine wraps Go's text/template with prompt-specific functionality.
func LoadTemplates ¶
func LoadTemplates(cfg TemplateConfig) (*TemplateEngine, error)
LoadTemplates creates a template engine, preferring filesystem override if configured. When templates_dir is set, it layers custom templates over embedded ones. Override templates should be structured as sections/*.tmpl and tools/*.tmpl (without the "prompts/" prefix that embedded templates have).
func NewTemplateEngine ¶
func NewTemplateEngine(templatesFS fs.FS) (*TemplateEngine, error)
NewTemplateEngine creates a new template engine from the given filesystem. The filesystem should contain template files in the expected directory structure.
func (*TemplateEngine) HasTemplate ¶
func (e *TemplateEngine) HasTemplate(name string) bool
HasTemplate checks if a template with the given name exists.
func (*TemplateEngine) ListTemplates ¶
func (e *TemplateEngine) ListTemplates() []string
ListTemplates returns all loaded template names.
func (*TemplateEngine) Reload ¶
func (e *TemplateEngine) Reload() error
Reload re-parses all templates from the filesystem. Useful for hot-reload during development.
func (*TemplateEngine) Render ¶
func (e *TemplateEngine) Render(name string, ctx any) (string, error)
Render executes the named template with the given context.
func (*TemplateEngine) RenderString ¶
func (e *TemplateEngine) RenderString(tmplStr string, ctx PromptContext) (string, error)
RenderString renders a template string directly (for dynamic tool prompts).