selfplay

package
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheKey

type CacheKey struct {
	Role      string
	PersonaID string
}

CacheKey represents a structured cache key for user generators

type CacheStats

type CacheStats struct {
	Size        int     // Number of cached entries
	Hits        int     // Number of cache hits
	Misses      int     // Number of cache misses
	HitRate     float64 // Cache hit rate (0.0 to 1.0)
	CachedPairs []CacheKey
}

CacheStats provides observability into cache performance

type ContentGenerator

type ContentGenerator struct {
	// contains filtered or unexported fields
}

ContentGenerator generates user messages using an LLM

func NewContentGenerator

func NewContentGenerator(provider providers.Provider, persona *config.UserPersonaPack) *ContentGenerator

NewContentGenerator creates a new content generator with a specific provider and persona

func (*ContentGenerator) NextUserTurn

func (cg *ContentGenerator) NextUserTurn(
	ctx context.Context,
	history []types.Message,
	scenarioID string,
) (*pipeline.ExecutionResult, error)

NextUserTurn generates a user message using the LLM through a pipeline

type Generator

type Generator interface {
	NextUserTurn(ctx context.Context, history []types.Message, scenarioID string) (*pipeline.ExecutionResult, error)
}

Generator generates user messages for self-play scenarios. Each generator is configured with a specific persona and LLM provider, and produces user turns based on conversation history. Returns the full pipeline ExecutionResult which includes trace data, costs, and metadata.

type Provider

type Provider interface {
	GetContentGenerator(role, personaID string) (Generator, error)
}

Provider provides access to content generators for self-play scenarios. This is the main interface that the engine and turn executors use to obtain content generators based on role and persona.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages self-play providers, personas, and user generator creation

func NewRegistry

func NewRegistry(
	providerRegistry *providers.Registry,
	providerMap map[string]string,
	personas map[string]*config.UserPersonaPack,
	roles []config.SelfPlayRoleGroup,
) *Registry

NewRegistry creates a new self-play registry

func (*Registry) ClearCache

func (r *Registry) ClearCache()

ClearCache clears all cached user generators and resets statistics

func (*Registry) Close

func (r *Registry) Close() error

Close closes the self-play provider registry and cleans up resources

func (*Registry) GetAvailableProviders

func (r *Registry) GetAvailableProviders() []string

GetAvailableProviders returns a list of available providers

func (*Registry) GetAvailableRoles

func (r *Registry) GetAvailableRoles() []string

GetAvailableRoles returns a list of available self-play roles

func (*Registry) GetCacheStats

func (r *Registry) GetCacheStats() CacheStats

GetCacheStats returns current cache statistics

func (*Registry) GetContentGenerator

func (r *Registry) GetContentGenerator(role, personaID string) (Generator, error)

GetContentGenerator implements Provider interface Returns a Generator for the given role and persona (cached for efficiency)

func (*Registry) IsValidRole

func (r *Registry) IsValidRole(role string) bool

IsValidRole checks if a role is configured for self-play

func (*Registry) PrewarmCache

func (r *Registry) PrewarmCache(rolePairs []CacheKey) error

PrewarmCache creates and caches ContentGenerators for common role+persona combinations This can improve performance by avoiding cold starts during actual execution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL