Documentation
¶
Overview ¶
Package promptopt implements prompt A/B testing and optimization for cloop. Variants are named alternatives to role-specific system prompts. Outcomes are recorded per variant and the best-performing variant is selected via the lower bound of the Wilson score confidence interval (95 %).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OutcomeRecord ¶
type OutcomeRecord struct {
VariantID string `json:"variant_id"`
Role string `json:"role"`
Success bool `json:"success"`
LatencyMs int `json:"latency_ms"`
Ts time.Time `json:"ts"`
}
OutcomeRecord is a single A/B outcome entry persisted in the variants JSONL file.
func LoadOutcomes ¶
func LoadOutcomes(workDir string) ([]OutcomeRecord, error)
LoadOutcomes reads all outcome records from the JSONL file. Returns nil, nil when the file does not exist yet.
type Variant ¶
type Variant struct {
// ID is a short unique identifier (e.g. "backend-default", "backend-concise").
ID string
// Role is the task role this variant applies to (empty = generic).
Role pm.AgentRole
// Name is a human-readable label shown in `cloop perf`.
Name string
// SystemPrompt is the text prepended to the task execution prompt in place of
// the role's default RoleSystemPrompt. Empty strings inherit the default.
SystemPrompt string
}
Variant is a named prompt variant for a specific agent role.
func BestVariant ¶
BestVariant returns the variant with the highest Wilson lower-bound score for the given role, using outcome data recorded in workDir. It falls back to the default variant when there is no data yet.
func LoadVariants ¶
LoadVariants returns all registered prompt variants for the given role. Pass an empty role string to get variants that apply to every task.
func NextBestVariant ¶
NextBestVariant returns the next best variant that is NOT the currently active variantID. Used by the orchestrator when switching on heal attempts.
func VariantByID ¶
VariantByID returns the variant with the given ID, or the zero Variant if not found.