prompts

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionInfo

type ActionInfo struct {
	Name           string
	Description    string
	RequiresTarget bool
	TargetType     string // "poi_id", "system_name", "none"
	Requirements   string // e.g., "Must be docked", "Requires fuel > 10%"
}

ActionInfo describes an available action

type ActionRecord

type ActionRecord struct {
	Action  string
	Target  string
	Success bool
	Message string
	Tick    int
}

ActionRecord represents a past action

type CargoItem

type CargoItem struct {
	Type     string
	Quantity int
}

CargoItem represents an item in cargo

type Config

type Config struct {
	TemplatesDir string
	ConfigPath   string
}

Config holds Manager configuration

type ConfigYAML

type ConfigYAML struct {
	Global  GlobalConfig            `yaml:"global"`
	Prompts map[string]PromptConfig `yaml:"prompts"`
	Metrics MetricsConfig           `yaml:"metrics"`
}

ConfigYAML represents the prompts configuration file

func LoadConfig

func LoadConfig(path string) (*ConfigYAML, error)

LoadConfig loads the configuration from a YAML file

func (*ConfigYAML) GetActiveVersion

func (c *ConfigYAML) GetActiveVersion(promptType, role string) (int, bool)

GetActiveVersion returns the active version for a prompt type and role

func (*ConfigYAML) GetFallbackVersion

func (c *ConfigYAML) GetFallbackVersion(promptType string) (int, bool)

GetFallbackVersion returns the fallback version for a prompt type

type ErrorRecord

type ErrorRecord struct {
	Timestamp time.Time `yaml:"timestamp"`
	Error     string    `yaml:"error"`
	Context   string    `yaml:"context,omitempty"`
}

ErrorRecord records an error occurrence

type Evolver

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

Evolver handles prompt evolution and improvement

func NewEvolver

func NewEvolver(manager *Manager, registry *Registry, metrics *MetricsCollector, llmClient LLMClient) *Evolver

NewEvolver creates a new prompt evolver

func (*Evolver) AnalyzePrompt

func (e *Evolver) AnalyzePrompt(promptType string, version int) (*ImprovementSuggestion, error)

AnalyzePrompt analyzes a prompt's metrics and suggests improvements

func (*Evolver) CreateDraftVersion

func (e *Evolver) CreateDraftVersion(promptType string, baseVersion int, content string) error

CreateDraftVersion creates a draft version of a prompt

func (*Evolver) PromoteDraft

func (e *Evolver) PromoteDraft(promptType string, version int) error

PromoteDraft promotes a draft version to active

type ExperienceRecord

type ExperienceRecord struct {
	Time        string
	Type        string
	Description string
	Outcome     string
	Location    string
}

ExperienceRecord represents a past experience

type FeedbackContext

type FeedbackContext struct {
	Success   bool
	Action    string
	Target    string
	Message   string
	Error     string
	ErrorType string // e.g., "validation", "execution", "timeout"
}

FeedbackContext contains feedback from the last action

type GlobalConfig

type GlobalConfig struct {
	SelectionStrategy  string `yaml:"selection_strategy"` // "stable", "latest", "role_based"
	FallbackToPrevious bool   `yaml:"fallback_to_previous"`
	CollectMetrics     bool   `yaml:"collect_metrics"`
}

GlobalConfig holds global configuration

type GoalContext

type GoalContext struct {
	Type        string   // Goal type: "wealth", "skill", "exploration", "resource", "reputation"
	Target      string   // Specific target (e.g., "Mining_5", "10000_credits")
	Progress    float64  // Progress towards goal (0.0 to 1.0)
	Priority    int      // Priority level (1-10)
	Reasoning   string   // Why this goal was set
	Focus       string   // Current strategic focus
	Constraints []string // Active constraints
	Urgency     int      // Urgency level (1-10)
}

GoalContext contains the agent's current goal and priorities

type HistoryContext

type HistoryContext struct {
	RecentActions     []ActionRecord
	RecentExperiences []ExperienceRecord
}

HistoryContext contains recent experiences

type ImprovementSuggestion

type ImprovementSuggestion struct {
	PromptType       string
	CurrentVersion   int
	NewVersion       int
	Rationale        string
	Changes          []string
	ExpectedBenefits []string
	CreatedAt        time.Time
}

ImprovementSuggestion represents a suggested improvement to a prompt

type KnowledgeContext

type KnowledgeContext struct {
	KnownSystems       []SystemInfo
	POIsInSystem       []POIInfo
	Connections        []string
	UnknownConnections []string
}

KnowledgeContext contains what the agent knows

type LLMClient

type LLMClient interface {
	// Query sends a prompt to the LLM and returns the response
	Query(prompt string) (string, error)
}

LLMClient defines the interface for LLM operations

type Manager

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

Manager handles prompt template loading and rendering

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager creates a new PromptManager

func (*Manager) GetAvailableTemplates

func (m *Manager) GetAvailableTemplates() []string

GetAvailableTemplates returns a list of loaded template names

func (*Manager) HasTemplate

func (m *Manager) HasTemplate(promptType string, version int) bool

HasTemplate checks if a template is loaded

func (*Manager) LoadTemplates

func (m *Manager) LoadTemplates() error

LoadTemplates scans and loads all template files

func (*Manager) ReloadTemplates

func (m *Manager) ReloadTemplates() error

ReloadTemplates reloads all templates from disk

func (*Manager) RenderPrompt

func (m *Manager) RenderPrompt(promptType string, version int, ctx *TemplateContext) (string, error)

RenderPrompt renders a prompt template with the given context

func (*Manager) RenderPromptByName

func (m *Manager) RenderPromptByName(templateName string, ctx *TemplateContext) (string, error)

RenderPromptByName renders a prompt using the template name directly

type Metrics

type Metrics struct {
	PromptType    string                 `yaml:"prompt_type"`
	Version       int                    `yaml:"version"`
	TotalUses     int                    `yaml:"total_uses"`
	SuccessCount  int                    `yaml:"success_count"`
	ErrorCount    int                    `yaml:"error_count"`
	AvgConfidence float64                `yaml:"avg_confidence"`
	LastUsed      time.Time              `yaml:"last_used"`
	Errors        []ErrorRecord          `yaml:"errors,omitempty"`
	ByRole        map[string]RoleMetrics `yaml:"by_role,omitempty"`
}

Metrics tracks prompt performance metrics

func (*Metrics) ErrorRate

func (m *Metrics) ErrorRate() float64

ErrorRate calculates error rate for a prompt

func (*Metrics) SuccessRate

func (m *Metrics) SuccessRate() float64

SuccessRate calculates success rate for a prompt

type MetricsCollector

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

MetricsCollector collects and stores prompt metrics

func NewMetricsCollector

func NewMetricsCollector(storagePath string, enabled bool) *MetricsCollector

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) GetAllMetrics

func (mc *MetricsCollector) GetAllMetrics() map[string]*Metrics

GetAllMetrics returns all collected metrics

func (*MetricsCollector) GetMetrics

func (mc *MetricsCollector) GetMetrics(promptType string, version int) *Metrics

GetMetrics returns metrics for a specific prompt version

func (*MetricsCollector) Load

func (mc *MetricsCollector) Load() error

Load loads metrics from disk

func (*MetricsCollector) RecordUse

func (mc *MetricsCollector) RecordUse(promptType string, version int, role string, success bool, confidence float64, err error)

RecordUse records a prompt usage

func (*MetricsCollector) Save

func (mc *MetricsCollector) Save() error

Save saves metrics to disk

type MetricsConfig

type MetricsConfig struct {
	Enabled       bool   `yaml:"enabled"`
	RetentionDays int    `yaml:"retention_days"`
	StoragePath   string `yaml:"storage_path"`
}

MetricsConfig holds metrics collection configuration

type NearbyPlayerInfo

type NearbyPlayerInfo struct {
	Username   string
	ShipClass  string
	FactionTag string
	InCombat   bool
	ClanTag    string
}

NearbyPlayerInfo represents a nearby player

type POIInfo

type POIInfo struct {
	ID       string
	Name     string
	Type     string
	Position string
}

POIInfo represents knowledge about a point of interest

type PersonalityContext

type PersonalityContext struct {
	Name        string
	Role        string
	Traits      []string
	Motivations []string
	Skills      []string
	Background  string
}

PersonalityContext contains agent personality information

type PromptConfig

type PromptConfig struct {
	ActiveVersion   int            `yaml:"active_version"`
	RoleOverrides   map[string]int `yaml:"role_overrides"`
	FallbackVersion int            `yaml:"fallback_version"`
}

PromptConfig holds configuration for a specific prompt type

type PromptStatus

type PromptStatus string

PromptStatus represents the status of a template version

const (
	StatusActive     PromptStatus = "active"
	StatusDraft      PromptStatus = "draft"
	StatusDeprecated PromptStatus = "deprecated"
)

type Registry

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

Registry tracks available prompt templates and their versions

func NewRegistry

func NewRegistry(templatesDir string) (*Registry, error)

NewRegistry creates a new prompt registry

func (*Registry) GetAllPromptTypes

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

GetAllPromptTypes returns all registered prompt types

func (*Registry) GetLatestVersion

func (r *Registry) GetLatestVersion(promptType string) (int, bool)

GetLatestVersion returns the highest version number (excluding drafts)

func (*Registry) GetVersions

func (r *Registry) GetVersions(promptType string) []TemplateVersion

GetVersions returns all versions for a given prompt type

func (*Registry) HasVersion

func (r *Registry) HasVersion(promptType string, version int) bool

HasVersion checks if a specific version exists

func (*Registry) Scan

func (r *Registry) Scan() error

Scan scans the templates directory for all template files

type RoleMetrics

type RoleMetrics struct {
	Uses          int     `yaml:"uses"`
	SuccessCount  int     `yaml:"success_count"`
	AvgConfidence float64 `yaml:"avg_confidence"`
}

RoleMetrics tracks metrics per role

type RouteStepInfo

type RouteStepInfo struct {
	SystemID string
	Name     string
}

RouteStepInfo represents a step in the route home for display in prompts.

type SelectionContext

type SelectionContext struct {
	PromptType       string
	Role             string
	RequestedVersion int // 0 = use configured version
}

SelectionContext holds information for version selection

type Selector

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

Selector chooses the appropriate template version

func NewSelector

func NewSelector(registry *Registry, config *ConfigYAML) *Selector

NewSelector creates a new version selector

func (*Selector) SelectVersion

func (s *Selector) SelectVersion(ctx SelectionContext) (int, error)

SelectVersion chooses the best template version for the given context

type StateContext

type StateContext struct {
	SystemName  string
	SystemID    string
	Location    string // e.g., "Sol-Station-Alpha"
	IsDocked    bool
	DockedAt    string
	Fuel        float64
	MaxFuel     float64
	FuelPercent float64
	Hull        float64
	MaxHull     float64
	HullPercent float64
	Cargo       []CargoItem
	CargoCount  int
	MaxCargo    int
	Credits     float64
	Tick        int64

	// Combat & Tactical
	Shield         float64
	MaxShield      float64
	ShieldPercent  float64
	ShieldRecharge float64
	Armor          float64
	InCombat       bool
	NearbyPlayers  int
	NearbyHostiles int
	NearbyList     []NearbyPlayerInfo

	// Ship Technical
	CPUUsed       float64
	CPUCapacity   float64
	CPUPercent    float64
	PowerUsed     float64
	PowerCapacity float64
	PowerPercent  float64
	Speed         float64
	ShipClass     string
	Modules       []string

	// Cargo Details
	CargoUsed    float64
	CargoPercent float64

	// Travel & Location
	Traveling      bool
	TravelProgress *TravelProgressContext
	POIDescription string
	SystemSecurity string
	SystemEmpire   string

	// Safe Haven
	SafeSystem     string // System ID of the agent's safe haven
	SafeSystemName string // Display name of the safe system

	// Route Home
	RouteHome      []RouteStepInfo // Cached route to safe system
	RouteHomeJumps int             // Total jumps to safe system
}

StateContext contains current game state information

type SystemContext

type SystemContext struct {
	AvailableActions []ActionInfo
	CurrentTick      int64
	ServerTime       string
}

SystemContext contains system-level information

type SystemInfo

type SystemInfo struct {
	ID          string
	Name        string
	PoliceLevel int
	Empire      string
	VisitCount  int
}

SystemInfo represents knowledge about a system

type TemplateContext

type TemplateContext struct {
	AgentID      string
	AgentName    string
	Role         string
	Personality  *PersonalityContext
	State        *StateContext
	Knowledge    *KnowledgeContext
	History      *HistoryContext
	LastFeedback *FeedbackContext
	System       *SystemContext
	Goal         *GoalContext
}

TemplateContext holds all data available to templates

func NewTemplateContext

func NewTemplateContext(
	agentID string,
	agentName string,
	role string,
	personality map[string]interface{},
	state *game.State,
	knowledge *KnowledgeContext,
	history *HistoryContext,
	lastFeedback *FeedbackContext,
	goal *GoalContext,
) *TemplateContext

NewTemplateContext creates a TemplateContext from game state and agent data

type TemplateVersion

type TemplateVersion struct {
	Name    string // e.g., "decision"
	Version int    // e.g., 1, 2, 3
	Status  PromptStatus
	Path    string
	IsDraft bool // Derived from filename (e.g., decision.v1-draft.tmpl)
}

TemplateVersion represents a specific version of a prompt template

type TravelProgressContext

type TravelProgressContext struct {
	Progress    float64
	Destination string
	Type        string // "travel" or "jump"
	ArrivalTick int64
	ETA         int64 // Ticks remaining
}

TravelProgressContext represents travel state

Jump to

Keyboard shortcuts

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