Documentation
¶
Overview ¶
Package prompt provides template-based prompt management and assembly.
This package implements a registry system for loading, caching, and assembling prompt templates via repository interfaces:
- Fragment-based prompt composition
- Variable substitution with required/optional vars
- Model-specific overrides (template modifications only)
- Tool allowlist integration
- Version tracking and content hashing
The Registry uses the repository pattern to load prompt configs, avoiding direct file I/O. It resolves fragment references, performs template variable substitution, and generates AssembledPrompt objects ready for LLM execution.
Architecture ¶
For system architecture and design patterns, see:
- Architecture overview: https://github.com/AltairaAI/promptkit-wip/blob/main/docs/architecture.md
- Prompt assembly pipeline: https://github.com/AltairaAI/promptkit-wip/blob/main/docs/prompt-assembly.md
- Repository pattern: https://github.com/AltairaAI/promptkit-wip/blob/main/docs/persistence-layer-proposal.md
Usage ¶
Create a registry with a repository (config-first pattern):
repo := memory.NewRepository()
registry := prompt.NewRegistryWithRepository(repo)
assembled := registry.LoadWithVars("task_type", vars, "gpt-4")
See package github.com/AltairaLabs/PromptKit/sdk for higher-level APIs.
Index ¶
- Constants
- func ExtractVariablesFromTemplate(template string) []string
- func GetDefaultPipelineConfig() map[string]interface{}
- func GetUsedVars(vars map[string]string) []stringdeprecated
- func SupportsMediaType(config *MediaConfig, mediaType string) bool
- func ValidateMediaConfig(config *MediaConfig) error
- type AssembledPrompt
- type AudioConfig
- type ChangelogEntry
- type CompilationInfo
- type Config
- type CostEstimate
- type ExampleContentPart
- type ExampleMedia
- type FileWriter
- type Fragment
- type FragmentRef
- type FragmentRepository
- type FragmentResolver
- type ImageConfig
- type Info
- type Loader
- type MediaConfig
- type Metadata
- type MetadataBuilder
- func (mb *MetadataBuilder) AddChangelogEntry(version, author, description string)
- func (mb *MetadataBuilder) BuildCompilationInfo(compilerVersion string) *CompilationInfo
- func (mb *MetadataBuilder) BuildMetadata(domain, language string, tags []string, testResults []TestResultSummary) *Metadata
- func (mb *MetadataBuilder) SetDomain(domain string)
- func (mb *MetadataBuilder) SetLanguage(language string)
- func (mb *MetadataBuilder) SetTags(tags []string)
- func (mb *MetadataBuilder) UpdateFromCostInfo(costs []types.CostInfo)
- func (mb *MetadataBuilder) ValidateMetadata() []string
- type ModelOverride
- type ModelTestResultRef
- type MultimodalExample
- type Pack
- func (p *Pack) GetOptionalVariables(taskType string) map[string]string
- func (p *Pack) GetPrompt(taskType string) *PackPrompt
- func (p *Pack) GetRequiredVariables(taskType string) []string
- func (p *Pack) GetToolNames(taskType string) []string
- func (p *Pack) ListPrompts() []string
- func (p *Pack) Summary() string
- func (p *Pack) Validate() []string
- type PackCompiler
- func (pc *PackCompiler) Compile(taskType, compilerVersion string) (*Pack, error)
- func (pc *PackCompiler) CompileFromRegistry(packID, compilerVersion string) (*Pack, error)
- func (pc *PackCompiler) CompileFromRegistryWithParsedTools(packID, compilerVersion string, parsedTools []ParsedTool) (*Pack, error)
- func (pc *PackCompiler) CompileFromRegistryWithTools(packID, compilerVersion string, toolData []ToolData) (*Pack, error)
- func (pc *PackCompiler) CompileToFile(taskType, outputPath, compilerVersion string) error
- func (pc *PackCompiler) MarshalPack(pack *Pack) ([]byte, error)
- func (pc *PackCompiler) WritePack(pack *Pack, outputPath string) error
- type PackPrompt
- type PackTool
- type ParametersPack
- type ParsedTool
- type PerformanceMetrics
- type Registry
- func (r *Registry) ClearCache()
- func (r *Registry) GetAvailableRegions() []string
- func (r *Registry) GetAvailableTaskTypes() []string
- func (r *Registry) GetCachedFragments() []string
- func (r *Registry) GetCachedPrompts() []string
- func (r *Registry) GetInfo(taskType string) (*Info, error)
- func (r *Registry) GetLoadedFragments() []string
- func (r *Registry) GetLoadedPrompts() []string
- func (r *Registry) ListTaskTypes() []string
- func (r *Registry) Load(activity string) *AssembledPrompt
- func (r *Registry) LoadConfig(activity string) (*Config, error)
- func (r *Registry) LoadWithVars(activity string, vars map[string]string, model string) *AssembledPrompt
- func (r *Registry) RegisterConfig(taskType string, config *Config) error
- type Repository
- type Spec
- type TemplateEngineInfo
- type TestResultSummary
- type TimeProvider
- type ToolData
- type ToolPolicyPack
- type ValidatorConfig
- type VariableMetadata
- type VideoConfig
Constants ¶
const PromptPackSchemaURL = "https://promptpack.org/schema/latest/promptpack.schema.json"
PromptPackSchemaURL is the JSON Schema URL for validating PromptPack files
Variables ¶
This section is empty.
Functions ¶
func ExtractVariablesFromTemplate ¶
ExtractVariablesFromTemplate analyzes a template string and extracts variable names This helps auto-generate variable metadata when not explicitly specified
func GetDefaultPipelineConfig ¶
func GetDefaultPipelineConfig() map[string]interface{}
GetDefaultPipelineConfig returns the default Arena pipeline configuration Returns as map to avoid import cycle with pipeline package
func GetUsedVars
deprecated
func SupportsMediaType ¶ added in v1.1.0
func SupportsMediaType(config *MediaConfig, mediaType string) bool
SupportsMediaType checks if a MediaConfig supports a specific media type
func ValidateMediaConfig ¶ added in v1.1.0
func ValidateMediaConfig(config *MediaConfig) error
ValidateMediaConfig validates a MediaConfig for correctness and completeness
Types ¶
type AssembledPrompt ¶
type AssembledPrompt struct {
TaskType string `json:"task_type"`
SystemPrompt string `json:"system_prompt"`
AllowedTools []string `json:"allowed_tools,omitempty"` // Tools this prompt can use
Validators []ValidatorConfig `json:"validators,omitempty"` // Validators to apply at runtime
}
AssembledPrompt represents a complete prompt ready for LLM execution.
func (*AssembledPrompt) UsesTools ¶
func (ap *AssembledPrompt) UsesTools() bool
UsesTools returns true if this prompt has tools configured
type AudioConfig ¶ added in v1.1.0
type AudioConfig struct {
// Maximum audio size in MB (0 = unlimited)
MaxSizeMB int `yaml:"max_size_mb,omitempty" json:"max_size_mb,omitempty"`
// Allowed formats: ["mp3", "wav", "ogg", "webm"]
AllowedFormats []string `yaml:"allowed_formats,omitempty" json:"allowed_formats,omitempty"`
// Max duration in seconds (0 = unlimited)
MaxDurationSec int `yaml:"max_duration_sec,omitempty" json:"max_duration_sec,omitempty"`
// Whether metadata (duration, bitrate) is required
RequireMetadata bool `yaml:"require_metadata,omitempty" json:"require_metadata,omitempty"`
}
AudioConfig contains audio-specific configuration
func GetAudioConfig ¶ added in v1.1.0
func GetAudioConfig(config *MediaConfig) *AudioConfig
GetAudioConfig returns the audio configuration if audio is supported
type ChangelogEntry ¶
type ChangelogEntry struct {
Version string `yaml:"version"` // Version number
Date string `yaml:"date"` // Date of change (YYYY-MM-DD)
Author string `yaml:"author,omitempty"` // Author of change
Description string `yaml:"description"` // Description of change
}
ChangelogEntry records a change in the prompt configuration
type CompilationInfo ¶
type CompilationInfo struct {
CompiledWith string `yaml:"compiled_with" json:"compiled_with"` // Compiler version
CreatedAt string `yaml:"created_at" json:"created_at"` // Timestamp (RFC3339)
Schema string `yaml:"schema,omitempty" json:"schema,omitempty"` // Pack schema version (e.g., "v1")
}
CompilationInfo contains information about prompt compilation
type Config ¶ added in v1.1.3
type Config struct {
APIVersion string `yaml:"apiVersion" json:"apiVersion"`
Kind string `yaml:"kind" json:"kind"`
Metadata metav1.ObjectMeta `yaml:"metadata,omitempty" json:"metadata,omitempty"`
Spec Spec `yaml:"spec" json:"spec"`
}
Config represents a YAML prompt configuration file in K8s-style manifest format
func ParseConfig ¶ added in v1.1.3
ParseConfig parses a prompt config from YAML data. This is a package-level utility function for parsing prompt configs in the config layer. The config layer should read files using os.ReadFile and pass the data to this function. Returns the parsed Config or an error if parsing/validation fails.
func (*Config) GetAllowedTools ¶ added in v1.1.5
GetAllowedTools returns the allowed tools from the prompt config
func (*Config) GetTaskType ¶ added in v1.1.5
GetTaskType returns the task type from the prompt config
type CostEstimate ¶
type CostEstimate struct {
MinCostUSD float64 `yaml:"min_cost_usd"` // Minimum cost per execution
MaxCostUSD float64 `yaml:"max_cost_usd"` // Maximum cost per execution
AvgCostUSD float64 `yaml:"avg_cost_usd"` // Average cost per execution
}
CostEstimate provides estimated costs for prompt execution
type ExampleContentPart ¶ added in v1.1.0
type ExampleContentPart struct {
// Content type: "text", "image", "audio", "video"
Type string `yaml:"type" json:"type"`
// Text content (for type=text)
Text string `yaml:"text,omitempty" json:"text,omitempty"`
// For media content
Media *ExampleMedia `yaml:"media,omitempty" json:"media,omitempty"`
}
ExampleContentPart represents a content part in an example (simplified for YAML)
type ExampleMedia ¶ added in v1.1.0
type ExampleMedia struct {
// Relative path to media file
FilePath string `yaml:"file_path,omitempty" json:"file_path,omitempty"`
// External URL
URL string `yaml:"url,omitempty" json:"url,omitempty"`
// MIME type
MIMEType string `yaml:"mime_type" json:"mime_type"`
// Detail level for images
Detail string `yaml:"detail,omitempty" json:"detail,omitempty"`
// Optional caption
Caption string `yaml:"caption,omitempty" json:"caption,omitempty"`
}
ExampleMedia represents media references in examples
type FileWriter ¶ added in v1.1.0
FileWriter abstracts file writing for testing
type Fragment ¶
type Fragment struct {
Type string `yaml:"fragment_type"`
Version string `yaml:"version"`
Description string `yaml:"description"`
Content string `yaml:"content"`
SourceFile string `yaml:"source_file,omitempty"` // Source file path (for pack compilation)
ResolvedAtCompile bool `yaml:"resolved_at_compile,omitempty"` // Whether resolved at compile time
}
Fragment represents a reusable prompt fragment
type FragmentRef ¶
type FragmentRef struct {
Name string `yaml:"name"`
Path string `yaml:"path,omitempty"` // Optional: relative path to fragment file
Required bool `yaml:"required"`
}
FragmentRef references a prompt fragment for assembly
type FragmentRepository ¶
type FragmentRepository interface {
LoadFragment(name string, relativePath string, baseDir string) (*Fragment, error)
}
FragmentRepository interface for loading fragments (to avoid import cycles)
type FragmentResolver ¶
type FragmentResolver struct {
// contains filtered or unexported fields
}
FragmentResolver handles fragment loading, resolution, and variable substitution using the repository pattern
func NewFragmentResolverWithRepository ¶
func NewFragmentResolverWithRepository(repository FragmentRepository) *FragmentResolver
NewFragmentResolverWithRepository creates a new fragment resolver with a repository
func (*FragmentResolver) AssembleFragments ¶
func (fr *FragmentResolver) AssembleFragments( fragments []FragmentRef, vars map[string]string, configFilePath string, ) (map[string]string, error)
AssembleFragments loads and assembles prompt fragments into variables. Resolves dynamic names and paths using the provided variable map.
func (*FragmentResolver) LoadFragment ¶
func (fr *FragmentResolver) LoadFragment(name, relativePath, configFilePath string) (*Fragment, error)
LoadFragment loads a fragment from the repository with caching. Uses name as cache key, or path if provided.
type ImageConfig ¶ added in v1.1.0
type ImageConfig struct {
// Maximum image size in MB (0 = unlimited)
MaxSizeMB int `yaml:"max_size_mb,omitempty" json:"max_size_mb,omitempty"`
// Allowed formats: ["jpeg", "png", "webp", "gif"]
AllowedFormats []string `yaml:"allowed_formats,omitempty" json:"allowed_formats,omitempty"`
// Default detail level: "low", "high", "auto"
DefaultDetail string `yaml:"default_detail,omitempty" json:"default_detail,omitempty"`
// Whether captions are required
RequireCaption bool `yaml:"require_caption,omitempty" json:"require_caption,omitempty"`
// Max images per message (0 = unlimited)
MaxImagesPerMsg int `yaml:"max_images_per_msg,omitempty" json:"max_images_per_msg,omitempty"`
}
ImageConfig contains image-specific configuration
func GetImageConfig ¶ added in v1.1.0
func GetImageConfig(config *MediaConfig) *ImageConfig
GetImageConfig returns the image configuration if images are supported
type Info ¶ added in v1.1.3
type Info struct {
TaskType string
Version string
Description string
FragmentCount int
RequiredVars []string
OptionalVars []string
ToolAllowlist []string
ModelOverrides []string
}
Info provides summary information about a prompt configuration
type MediaConfig ¶ added in v1.1.0
type MediaConfig struct {
// Enable multimodal support for this prompt
Enabled bool `yaml:"enabled" json:"enabled"`
// Supported content types: "image", "audio", "video"
SupportedTypes []string `yaml:"supported_types,omitempty" json:"supported_types,omitempty"`
// Image-specific configuration
Image *ImageConfig `yaml:"image,omitempty" json:"image,omitempty"`
// Audio-specific configuration
Audio *AudioConfig `yaml:"audio,omitempty" json:"audio,omitempty"`
// Video-specific configuration
Video *VideoConfig `yaml:"video,omitempty" json:"video,omitempty"`
// Example multimodal messages
Examples []MultimodalExample `yaml:"examples,omitempty" json:"examples,omitempty"`
}
MediaConfig defines multimodal media support configuration for a prompt
type Metadata ¶ added in v1.1.3
type Metadata struct {
Domain string `yaml:"domain,omitempty"` // Domain/category (e.g., "customer-support")
Language string `yaml:"language,omitempty"` // Primary language (e.g., "en")
Tags []string `yaml:"tags,omitempty"` // Tags for categorization
CostEstimate *CostEstimate `yaml:"cost_estimate,omitempty"` // Estimated cost per execution
Performance *PerformanceMetrics `yaml:"performance,omitempty"` // Performance benchmarks
Changelog []ChangelogEntry `yaml:"changelog,omitempty"` // Version history
}
Metadata contains additional metadata for the pack format
type MetadataBuilder ¶
type MetadataBuilder struct {
// contains filtered or unexported fields
}
MetadataBuilder helps construct pack format metadata from prompt configs and test results
func NewMetadataBuilder ¶
func NewMetadataBuilder(spec *Spec) *MetadataBuilder
NewMetadataBuilder creates a new metadata builder for a prompt spec
func (*MetadataBuilder) AddChangelogEntry ¶
func (mb *MetadataBuilder) AddChangelogEntry(version, author, description string)
AddChangelogEntry adds a new entry to the prompt's changelog
func (*MetadataBuilder) BuildCompilationInfo ¶
func (mb *MetadataBuilder) BuildCompilationInfo(compilerVersion string) *CompilationInfo
BuildCompilationInfo generates compilation metadata
func (*MetadataBuilder) BuildMetadata ¶ added in v1.1.3
func (mb *MetadataBuilder) BuildMetadata(domain, language string, tags []string, testResults []TestResultSummary) *Metadata
BuildMetadata generates Metadata from test execution results
func (*MetadataBuilder) SetDomain ¶
func (mb *MetadataBuilder) SetDomain(domain string)
SetDomain sets the domain for the prompt metadata
func (*MetadataBuilder) SetLanguage ¶
func (mb *MetadataBuilder) SetLanguage(language string)
SetLanguage sets the language for the prompt metadata
func (*MetadataBuilder) SetTags ¶
func (mb *MetadataBuilder) SetTags(tags []string)
SetTags sets the tags for the prompt metadata
func (*MetadataBuilder) UpdateFromCostInfo ¶
func (mb *MetadataBuilder) UpdateFromCostInfo(costs []types.CostInfo)
UpdateFromCostInfo updates cost estimate from types.CostInfo
func (*MetadataBuilder) ValidateMetadata ¶
func (mb *MetadataBuilder) ValidateMetadata() []string
ValidateMetadata checks that metadata fields are properly populated
type ModelOverride ¶
type ModelOverride struct {
SystemTemplate string `yaml:"system_template,omitempty"`
SystemTemplateSuffix string `yaml:"system_template_suffix,omitempty"`
}
ModelOverride contains model-specific template modifications. Note: Temperature and MaxTokens should be configured at the scenario or provider level, not in the prompt configuration.
type ModelTestResultRef ¶
type ModelTestResultRef struct {
Provider string `yaml:"provider"`
Model string `yaml:"model"`
Date string `yaml:"date"`
SuccessRate float64 `yaml:"success_rate"`
AvgTokens int `yaml:"avg_tokens,omitempty"`
AvgCost float64 `yaml:"avg_cost,omitempty"`
AvgLatencyMs int `yaml:"avg_latency_ms,omitempty"`
}
ModelTestResultRef is a simplified reference to model test results The full ModelTestResult type is in pkg/engine for tracking test execution
func AggregateTestResults ¶
func AggregateTestResults(results []TestResultSummary, provider, model string) *ModelTestResultRef
AggregateTestResults computes ModelTestResultRef from test execution summaries
type MultimodalExample ¶ added in v1.1.0
type MultimodalExample struct {
// Example name/identifier
Name string `yaml:"name" json:"name"`
// Human-readable description
Description string `yaml:"description,omitempty" json:"description,omitempty"`
// Message role: "user", "assistant"
Role string `yaml:"role" json:"role"`
// Content parts for this example
Parts []ExampleContentPart `yaml:"parts" json:"parts"`
}
MultimodalExample represents an example multimodal message for testing/documentation
type Pack ¶
type Pack struct {
// Schema reference for validation
Schema string `json:"$schema,omitempty"` // JSON Schema URL for validation
// Identity
ID string `json:"id"` // Pack ID (e.g., "customer-support")
Name string `json:"name"` // Human-readable name
Version string `json:"version"` // Pack version
Description string `json:"description"` // Pack description
// Template Engine (shared across all prompts in pack)
TemplateEngine *TemplateEngineInfo `json:"template_engine"`
// Prompts - Map of task_type -> PackPrompt
Prompts map[string]*PackPrompt `json:"prompts"`
// Tools - Map of tool_name -> PackTool (per PromptPack spec Section 9)
// Tools are defined at pack level and referenced by name in prompts
Tools map[string]*PackTool `json:"tools,omitempty"`
// Shared fragments (can be referenced by any prompt)
Fragments map[string]string `json:"fragments,omitempty"` // Resolved fragments: name -> content
// Metadata
Metadata *Metadata `json:"metadata,omitempty"`
Compilation *CompilationInfo `json:"compilation,omitempty"`
}
Pack represents the complete JSON pack format containing MULTIPLE prompts for different task types.
DESIGN DECISION: Why separate Pack types in runtime vs sdk?
This runtime Pack is optimized for COMPILATION:
- Created by PackCompiler from prompt registry
- Includes Compilation and Metadata for tracking provenance
- Returns validation warnings ([]string) for compiler feedback
- No thread-safety needed (single-threaded compilation)
- Simple types (VariableMetadata, ValidatorConfig) for JSON serialization
The sdk.Pack is optimized for LOADING & EXECUTION:
- Loaded from .pack.json files for application use
- Includes Tools map and filePath for execution context
- Thread-safe with sync.RWMutex for concurrent access
- Returns validation errors for application error handling
- Rich types (*Variable, *Validator) with additional methods
- Has CreateRegistry() to convert back to runtime.Registry for pipeline
Both serialize to/from the SAME JSON format (.pack.json files), ensuring full interoperability. The type duplication is intentional and prevents circular dependencies while allowing each module to evolve independently.
See sdk/pack.go for the corresponding SDK-side documentation.
func (*Pack) GetOptionalVariables ¶
GetOptionalVariables returns all optional variable names with defaults for a specific prompt
func (*Pack) GetPrompt ¶
func (p *Pack) GetPrompt(taskType string) *PackPrompt
GetPrompt returns a specific prompt by task type
func (*Pack) GetRequiredVariables ¶
GetRequiredVariables returns all required variable names for a specific prompt
func (*Pack) GetToolNames ¶
GetToolNames returns the list of allowed tool names for a specific prompt
func (*Pack) ListPrompts ¶
ListPrompts returns all prompt task types in the pack
type PackCompiler ¶
type PackCompiler struct {
// contains filtered or unexported fields
}
PackCompiler compiles Config to Pack format
func NewPackCompiler ¶
func NewPackCompiler(registry *Registry) *PackCompiler
NewPackCompiler creates a new pack compiler with default dependencies
func NewPackCompilerWithDeps ¶ added in v1.1.0
func NewPackCompilerWithDeps(loader Loader, timeProvider TimeProvider, fileWriter FileWriter) *PackCompiler
NewPackCompilerWithDeps creates a pack compiler with injected dependencies (for testing)
func (*PackCompiler) Compile ¶
func (pc *PackCompiler) Compile(taskType, compilerVersion string) (*Pack, error)
Compile compiles a single prompt config to Pack format (for backward compatibility)
func (*PackCompiler) CompileFromRegistry ¶
func (pc *PackCompiler) CompileFromRegistry(packID, compilerVersion string) (*Pack, error)
CompileFromRegistry compiles ALL prompts from the registry into a single Pack
func (*PackCompiler) CompileFromRegistryWithParsedTools ¶ added in v1.1.5
func (pc *PackCompiler) CompileFromRegistryWithParsedTools( packID, compilerVersion string, parsedTools []ParsedTool, ) (*Pack, error)
CompileFromRegistryWithParsedTools compiles ALL prompts from the registry into a single Pack and includes pre-parsed tool definitions. Use this when YAML parsing happens externally.
func (*PackCompiler) CompileFromRegistryWithTools ¶ added in v1.1.5
func (pc *PackCompiler) CompileFromRegistryWithTools( packID, compilerVersion string, toolData []ToolData, ) (*Pack, error)
CompileFromRegistryWithTools compiles ALL prompts from the registry into a single Pack and includes tool definitions from the provided tool data. This method satisfies PromptPack spec Section 9 which requires tools to be defined at pack level with name, description, and parameters.
func (*PackCompiler) CompileToFile ¶
func (pc *PackCompiler) CompileToFile(taskType, outputPath, compilerVersion string) error
CompileToFile compiles a prompt config to a JSON pack file
func (*PackCompiler) MarshalPack ¶ added in v1.1.0
func (pc *PackCompiler) MarshalPack(pack *Pack) ([]byte, error)
MarshalPack marshals pack to JSON (testable without I/O)
type PackPrompt ¶
type PackPrompt struct {
// Identity
ID string `json:"id"` // Prompt ID (task_type)
Name string `json:"name"` // Human-readable name
Description string `json:"description"` // Prompt description
Version string `json:"version"` // Prompt version
// Prompt
SystemTemplate string `json:"system_template"`
// Variables
Variables []VariableMetadata `json:"variables,omitempty"`
// Tools
Tools []string `json:"tools,omitempty"` // Allowed tool names
ToolPolicy *ToolPolicyPack `json:"tool_policy,omitempty"` // Tool usage policy
// Multimodal media configuration
MediaConfig *MediaConfig `json:"media,omitempty"`
// Pipeline
Pipeline map[string]interface{} `json:"pipeline,omitempty"` // Pipeline configuration
// Parameters
Parameters *ParametersPack `json:"parameters,omitempty"` // Model-specific parameters
// Validators
Validators []ValidatorConfig `json:"validators,omitempty"`
// Model Testing
TestedModels []ModelTestResultRef `json:"tested_models,omitempty"`
// Model Overrides
ModelOverrides map[string]ModelOverride `json:"model_overrides,omitempty"`
}
PackPrompt represents a single prompt configuration within a pack
type PackTool ¶ added in v1.1.5
type PackTool struct {
Name string `json:"name"` // Tool function name (required)
Description string `json:"description"` // Tool description (required)
Parameters interface{} `json:"parameters"` // JSON Schema for input parameters (required)
}
PackTool represents a tool definition in the pack (per PromptPack spec Section 9) Tools are defined at pack level and referenced by prompts via the tools array
func ConvertToolToPackTool ¶ added in v1.1.5
func ConvertToolToPackTool(name, description string, inputSchema json.RawMessage) *PackTool
ConvertToolToPackTool converts a tool descriptor to a PackTool This is the preferred method when tool parsing happens externally
type ParametersPack ¶
type ParametersPack struct {
Temperature *float64 `json:"temperature,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
}
ParametersPack represents model parameters in pack format
type ParsedTool ¶ added in v1.1.5
type ParsedTool struct {
Name string
Description string
InputSchema json.RawMessage
}
ParsedTool holds pre-parsed tool information for compilation Use this when YAML parsing happens in the calling package
type PerformanceMetrics ¶
type PerformanceMetrics struct {
AvgLatencyMs int `yaml:"avg_latency_ms"` // Average latency in milliseconds
P95LatencyMs int `yaml:"p95_latency_ms"` // 95th percentile latency
AvgTokens int `yaml:"avg_tokens"` // Average tokens used
SuccessRate float64 `yaml:"success_rate"` // Success rate (0.0-1.0)
}
PerformanceMetrics provides performance benchmarks
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages prompt templates, versions, and variable substitution.
func NewRegistryWithRepository ¶
func NewRegistryWithRepository(repository Repository) *Registry
NewRegistryWithRepository creates a registry with a repository (new preferred method). This constructor uses the repository pattern for loading prompts, avoiding direct file I/O.
func (*Registry) ClearCache ¶
func (r *Registry) ClearCache()
ClearCache clears all cached prompts and fragments
func (*Registry) GetAvailableRegions ¶
GetAvailableRegions returns a list of all available regions from prompt fragments
func (*Registry) GetAvailableTaskTypes ¶
GetAvailableTaskTypes is deprecated: use ListTaskTypes instead
func (*Registry) GetCachedFragments ¶
GetCachedFragments returns a list of currently cached fragment keys.
func (*Registry) GetCachedPrompts ¶
GetCachedPrompts returns a list of currently cached prompt task types. For a complete list including uncached prompts, use ListTaskTypes instead.
func (*Registry) GetInfo ¶ added in v1.1.3
GetInfo returns detailed information about a prompt configuration
func (*Registry) GetLoadedFragments ¶
GetLoadedFragments is deprecated: use GetCachedFragments instead
func (*Registry) GetLoadedPrompts ¶
GetLoadedPrompts is deprecated: use GetCachedPrompts instead
func (*Registry) ListTaskTypes ¶
ListTaskTypes returns all available task types from the repository. Falls back to cached task types if repository is unavailable or returns empty.
func (*Registry) Load ¶
func (r *Registry) Load(activity string) *AssembledPrompt
Load returns an assembled prompt for the specified activity with variable substitution.
func (*Registry) LoadConfig ¶
LoadConfig is deprecated: use loadConfig directly (internal use) or use Load/LoadWithVars
func (*Registry) LoadWithVars ¶
func (r *Registry) LoadWithVars(activity string, vars map[string]string, model string) *AssembledPrompt
LoadWithVars loads a prompt with variable substitution and optional model override.
func (*Registry) RegisterConfig ¶
RegisterConfig registers a Config directly into the registry. This allows programmatic registration of prompts without requiring disk files. Useful for loading prompts from compiled packs or other in-memory sources. If a repository is configured, the config is persisted there as well.
type Repository ¶ added in v1.1.3
type Repository interface {
LoadPrompt(taskType string) (*Config, error)
LoadFragment(name string, relativePath string, baseDir string) (*Fragment, error)
ListPrompts() ([]string, error)
SavePrompt(config *Config) error
}
Repository interface defines methods for loading prompts (to avoid import cycles) This should match persistence.Repository interface
type Spec ¶ added in v1.1.3
type Spec struct {
TaskType string `yaml:"task_type" json:"task_type"`
Version string `yaml:"version" json:"version"`
Description string `yaml:"description" json:"description"`
TemplateEngine *TemplateEngineInfo `yaml:"template_engine,omitempty" json:"template_engine,omitempty"` // Template engine configuration
Fragments []FragmentRef `yaml:"fragments,omitempty" json:"fragments,omitempty"` // New: fragment assembly
SystemTemplate string `yaml:"system_template" json:"system_template"`
Variables []VariableMetadata `yaml:"variables,omitempty" json:"variables,omitempty"` // Variable definitions with rich metadata
ModelOverrides map[string]ModelOverride `yaml:"model_overrides,omitempty" json:"model_overrides,omitempty"`
AllowedTools []string `yaml:"allowed_tools,omitempty" json:"allowed_tools,omitempty"` // Tools this prompt can use
MediaConfig *MediaConfig `yaml:"media,omitempty" json:"media,omitempty"` // Multimodal media configuration
Validators []ValidatorConfig `yaml:"validators,omitempty" json:"validators,omitempty"` // Validators/Guardrails for production runtime
TestedModels []ModelTestResultRef `yaml:"tested_models,omitempty" json:"tested_models,omitempty"` // Model testing metadata
Metadata *Metadata `yaml:"metadata,omitempty" json:"metadata,omitempty"` // Additional metadata for pack format
Compilation *CompilationInfo `yaml:"compilation,omitempty" json:"compilation,omitempty"` // Compilation information
}
Spec contains the actual prompt configuration
type TemplateEngineInfo ¶
type TemplateEngineInfo struct {
Version string `yaml:"version" json:"version"` // Template engine version (e.g., "v1")
Syntax string `yaml:"syntax" json:"syntax"` // Template syntax (e.g., "{{variable}}")
Features []string `yaml:"features,omitempty" json:"features,omitempty"` // Supported features
}
TemplateEngineInfo describes the template engine used for variable substitution
type TestResultSummary ¶
TestResultSummary contains summarized test execution data
type TimeProvider ¶ added in v1.1.0
TimeProvider allows injecting time for deterministic tests
type ToolPolicyPack ¶
type ToolPolicyPack struct {
ToolChoice string `json:"tool_choice,omitempty"`
MaxRounds int `json:"max_rounds,omitempty"`
MaxToolCallsPerTurn int `json:"max_tool_calls_per_turn,omitempty"`
Blocklist []string `json:"blocklist,omitempty"`
}
ToolPolicyPack represents tool policy in pack format
type ValidatorConfig ¶
type ValidatorConfig struct {
// Embed base config (Type, Params)
validators.ValidatorConfig `yaml:",inline" json:",inline"`
// Enable/disable validator (default: true)
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
// Fail execution on violation (default: true)
FailOnViolation *bool `yaml:"fail_on_violation,omitempty" json:"fail_on_violation,omitempty"`
}
ValidatorConfig extends validators.ValidatorConfig with prompt-pack specific fields
type VariableMetadata ¶
type VariableMetadata struct {
Name string `yaml:"name" json:"name"`
Type string `yaml:"type,omitempty" json:"type,omitempty"` // "string", "number", "boolean", "object", "array"
Required bool `yaml:"required" json:"required"`
Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Example interface{} `yaml:"example,omitempty" json:"example,omitempty"`
Validation map[string]interface{} `yaml:"validation,omitempty" json:"validation,omitempty"`
}
VariableMetadata contains enhanced metadata for a variable VariableMetadata defines a template variable with validation rules This struct matches the SDK Variable type for PromptPack spec compliance
type VideoConfig ¶ added in v1.1.0
type VideoConfig struct {
// Maximum video size in MB (0 = unlimited)
MaxSizeMB int `yaml:"max_size_mb,omitempty" json:"max_size_mb,omitempty"`
// Allowed formats: ["mp4", "webm", "ogg"]
AllowedFormats []string `yaml:"allowed_formats,omitempty" json:"allowed_formats,omitempty"`
// Max duration in seconds (0 = unlimited)
MaxDurationSec int `yaml:"max_duration_sec,omitempty" json:"max_duration_sec,omitempty"`
// Whether metadata (resolution, fps) is required
RequireMetadata bool `yaml:"require_metadata,omitempty" json:"require_metadata,omitempty"`
}
VideoConfig contains video-specific configuration
func GetVideoConfig ¶ added in v1.1.0
func GetVideoConfig(config *MediaConfig) *VideoConfig
GetVideoConfig returns the video configuration if video is supported