Documentation
¶
Overview ¶
Package council provides multi-model orchestration for Gas Town. The Council layer routes tasks to optimal models based on role and complexity.
Package council provides multi-model orchestration for Gas Town.
Package council provides multi-model orchestration for Gas Town.
Package council provides multi-model orchestration for Gas Town.
Package council provides multi-model orchestration for Gas Town.
Package council provides multi-model orchestration for Gas Town.
Index ¶
- Constants
- Variables
- func AlternateConfigPath(townRoot string) string
- func ApplyProfile(profile *Profile, townRoot string) error
- func ConfigPath(townRoot string) string
- func ExportProfileToFile(profile *Profile, path string) error
- func ListProfiles() []string
- func ModelProvider(model string) string
- func QuickRoute(role string) (string, error)
- func RouteWithComplexity(role string, complexity ComplexityLevel) (string, error)
- func SaveConfig(path string, config *Config) error
- func ValidateProfile(profile *Profile) []string
- type ChainConfig
- type ChainExecutor
- type ChainResult
- type ChainStep
- type CircuitBreaker
- type ComplexityConfig
- type ComplexityLevel
- type Config
- func (c *Config) GetFallbackChain(role string) []string
- func (c *Config) GetModelForComplexity(role string, complexity ComplexityLevel) string
- func (c *Config) GetModelForRole(role string) string
- func (c *Config) GetRationale(role string) string
- func (c *Config) SupportsComplexityRouting(role string) bool
- type DefaultConfig
- type EnsembleConfig
- type EnsembleExecutor
- type EnsembleResult
- type FallbackManager
- func (fm *FallbackManager) CheckHealth(ctx context.Context, provider string) (*ProviderHealth, error)
- func (fm *FallbackManager) GetAllHealth(ctx context.Context) map[string]*ProviderHealth
- func (fm *FallbackManager) GetAvailableProviders() []string
- func (fm *FallbackManager) MaybeRecover(ctx context.Context)
- func (fm *FallbackManager) RecordRequestOutcome(provider string, success bool, err error)
- func (fm *FallbackManager) Reset()
- func (fm *FallbackManager) RouteWithFallback(req *RouteRequest) (*RouteResult, error)
- func (fm *FallbackManager) StartBackgroundRecovery(ctx context.Context)
- type Metrics
- type MetricsStore
- func (s *MetricsStore) CompareModels(model1, model2 string) *ModelComparison
- func (s *MetricsStore) GetMetrics() *Metrics
- func (s *MetricsStore) GetModelMetrics(model string) *ModelMetrics
- func (s *MetricsStore) GetModelRanking() []string
- func (s *MetricsStore) GetProviderMetrics(provider string) *ProviderMetrics
- func (s *MetricsStore) GetRecentTasks(n int) []TaskMetric
- func (s *MetricsStore) GetRoleMetrics(role string) *RoleMetrics
- func (s *MetricsStore) GetSummary() *Summary
- func (s *MetricsStore) RecordRateLimit(provider string) error
- func (s *MetricsStore) RecordTask(task TaskMetric) error
- func (s *MetricsStore) Reset() error
- type ModelComparison
- type ModelExecutor
- type ModelMetrics
- type ModelResponse
- type Pattern
- type Profile
- type ProfileMetrics
- type ProviderConfig
- type ProviderHealth
- type ProviderMetrics
- type RoleConfig
- type RoleMetrics
- type RouteRequest
- type RouteResult
- type Router
- type StepResult
- type Summary
- type TaskInfo
- type TaskMetric
- type VotingStrategy
Constants ¶
const ConfigFileName = "council.toml"
ConfigFileName is the default filename for council configuration.
const CurrentConfigVersion = 1
CurrentConfigVersion is the current schema version.
const CurrentMetricsVersion = 1
CurrentMetricsVersion is the current schema version.
const MaxTaskHistory = 1000
MaxTaskHistory is the maximum number of tasks to keep in history.
const MetricsFileName = "council-metrics.json"
MetricsFileName is the default filename for metrics storage.
Variables ¶
var PredefinedChains = map[string]*ChainConfig{ "code-review": { PassContext: true, StopOnError: false, Steps: []ChainStep{ { Name: "initial-review", Model: "sonnet-4.5", Role: "refinery", Prompt: "Review this code for issues:\n\n{{input}}", }, { Name: "deep-analysis", Model: "opus-4.5-thinking", Role: "refinery", Prompt: "Based on this initial review, provide a detailed analysis:\n\n{{input}}", }, { Name: "final-summary", Model: "gpt-5.2", Role: "refinery", Prompt: "Summarize the code review findings concisely:\n\n{{input}}", }, }, }, "architecture": { PassContext: true, StopOnError: true, Steps: []ChainStep{ { Name: "gather-requirements", Model: "gemini-3-flash", Prompt: "Extract the key requirements from:\n\n{{input}}", }, { Name: "design-options", Model: "opus-4.5-thinking", Prompt: "Based on these requirements, propose 3 architecture options:\n\n{{input}}", }, { Name: "evaluate-tradeoffs", Model: "sonnet-4.5", Prompt: "Evaluate the tradeoffs of each architecture option:\n\n{{input}}", }, { Name: "recommend", Model: "gpt-5.2", Prompt: "Based on the analysis, recommend the best architecture:\n\n{{input}}", }, }, }, "bug-fix": { PassContext: true, StopOnError: false, Steps: []ChainStep{ { Name: "diagnose", Model: "sonnet-4.5", Role: "polecat", Prompt: "Diagnose the root cause of this bug:\n\n{{input}}", }, { Name: "propose-fix", Model: "gpt-5.2", Role: "polecat", Prompt: "Based on this diagnosis, propose a fix:\n\n{{input}}", TransformOutput: "extract_code", }, { Name: "verify-fix", Model: "gemini-3-flash", Role: "witness", Prompt: "Verify this proposed fix addresses the bug:\n\n{{input}}", }, }, }, }
PredefinedChains contains common chain configurations.
var PredefinedEnsembles = map[string]*EnsembleConfig{ "critical-decision": { Models: []string{"opus-4.5-thinking", "gpt-5.2", "sonnet-4.5"}, VotingStrategy: VoteConsensus, Threshold: 0.66, Timeout: 120 * time.Second, MinResponses: 2, }, "fast-consensus": { Models: []string{"sonnet-4.5", "gpt-5.2", "gemini-3-flash"}, VotingStrategy: VoteMajority, Threshold: 0.5, Timeout: 30 * time.Second, MinResponses: 2, }, "quality": { Models: []string{"opus-4.5-thinking", "gpt-5.2"}, VotingStrategy: VoteBest, Threshold: 0.0, Timeout: 90 * time.Second, MinResponses: 1, }, }
PredefinedEnsembles contains common ensemble configurations.
var PredefinedProfiles = map[string]*Profile{ "cost-optimized": { Name: "cost-optimized", Description: "Minimize costs by using cheaper models where possible", Author: "Gas Town", Version: "1.0.0", Tags: []string{"cost", "budget", "efficient"}, UseCase: "Teams on a budget who want to maximize output per dollar", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "sonnet-4.5", Fallback: []string{"gpt-5.2", "gemini-3-flash"}, Rationale: "Sonnet provides good coordination at lower cost than Opus", }, "polecat": { Model: "gemini-3-flash", Fallback: []string{"gpt-5.2", "sonnet-4.5"}, Rationale: "Flash handles routine coding tasks effectively", Complexity: &ComplexityConfig{ High: "sonnet-4.5", Medium: "gpt-5.2", Low: "gemini-3-flash", }, }, "refinery": { Model: "gpt-5.2", Fallback: []string{"sonnet-4.5"}, Rationale: "GPT provides solid code review at moderate cost", }, "witness": { Model: "gemini-3-flash", Fallback: []string{"gpt-5.2"}, Rationale: "Flash is extremely cost-effective for monitoring", }, }, Defaults: &DefaultConfig{ Model: "gemini-3-flash", Fallback: []string{"gpt-5.2", "sonnet-4.5"}, }, }, }, "quality-focused": { Name: "quality-focused", Description: "Maximize output quality using flagship models", Author: "Gas Town", Version: "1.0.0", Tags: []string{"quality", "enterprise", "flagship"}, UseCase: "Critical projects where quality matters more than cost", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "opus-4.5-thinking", Fallback: []string{"gpt-5.2-high", "sonnet-4.5"}, Rationale: "Extended thinking for complex strategic decisions", }, "polecat": { Model: "sonnet-4.5", Fallback: []string{"opus-4.5", "gpt-5.2-high"}, Rationale: "Best-in-class coding with flagship fallbacks", Complexity: &ComplexityConfig{ High: "opus-4.5-thinking", Medium: "sonnet-4.5", Low: "sonnet-4.5", }, }, "refinery": { Model: "opus-4.5", Fallback: []string{"gpt-5.2-high", "sonnet-4.5"}, Rationale: "Flagship model for thorough code review", }, "witness": { Model: "sonnet-4.5", Fallback: []string{"gpt-5.2"}, Rationale: "More capable monitoring for complex systems", }, }, Defaults: &DefaultConfig{ Model: "sonnet-4.5", Fallback: []string{"opus-4.5", "gpt-5.2-high"}, }, }, }, "balanced": { Name: "balanced", Description: "Balance between cost and quality (recommended default)", Author: "Gas Town", Version: "1.0.0", Tags: []string{"balanced", "default", "recommended"}, UseCase: "General purpose configuration suitable for most teams", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "opus-4.5-thinking", Fallback: []string{"sonnet-4.5", "gpt-5.2-high"}, Rationale: "Strategic coordination warrants extended thinking", }, "polecat": { Model: "sonnet-4.5", Fallback: []string{"gpt-5.2", "gemini-3-flash"}, Rationale: "Best coding model for primary work", Complexity: &ComplexityConfig{ High: "opus-4.5", Medium: "sonnet-4.5", Low: "gemini-3-flash", }, }, "refinery": { Model: "gpt-5.2-high", Fallback: []string{"opus-4.5", "sonnet-4.5"}, Rationale: "Different model family for diverse review perspective", }, "witness": { Model: "gemini-3-flash", Fallback: []string{"sonnet-4.5"}, Rationale: "Cost-effective monitoring with capable fallback", }, }, Defaults: &DefaultConfig{ Model: "sonnet-4.5", Fallback: []string{"gpt-5.2", "gemini-3-flash"}, }, }, }, "anthropic-only": { Name: "anthropic-only", Description: "Use only Anthropic models (single-provider setup)", Author: "Gas Town", Version: "1.0.0", Tags: []string{"anthropic", "single-provider", "claude"}, UseCase: "Teams with Anthropic API access only", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "opus-4.5-thinking", Fallback: []string{"sonnet-4.5", "haiku-3.5"}, Rationale: "Flagship Claude for coordination", }, "polecat": { Model: "sonnet-4.5", Fallback: []string{"opus-4.5", "haiku-3.5"}, Rationale: "Sonnet is best Anthropic model for coding", Complexity: &ComplexityConfig{ High: "opus-4.5", Medium: "sonnet-4.5", Low: "haiku-3.5", }, }, "refinery": { Model: "opus-4.5", Fallback: []string{"sonnet-4.5"}, Rationale: "Opus for thorough review", }, "witness": { Model: "haiku-3.5", Fallback: []string{"sonnet-4.5"}, Rationale: "Haiku is fast and cheap for monitoring", }, }, Defaults: &DefaultConfig{ Model: "sonnet-4.5", Fallback: []string{"opus-4.5", "haiku-3.5"}, }, Providers: map[string]*ProviderConfig{ "anthropic": {Enabled: true, Priority: 100}, "openai": {Enabled: false}, "google": {Enabled: false}, }, }, }, "openai-only": { Name: "openai-only", Description: "Use only OpenAI models (single-provider setup)", Author: "Gas Town", Version: "1.0.0", Tags: []string{"openai", "single-provider", "gpt"}, UseCase: "Teams with OpenAI API access only", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "gpt-5.2-high", Fallback: []string{"gpt-5.2", "gpt-4.1"}, Rationale: "High-capacity GPT for coordination", }, "polecat": { Model: "gpt-5.2", Fallback: []string{"gpt-5.2-high", "gpt-4.1"}, Rationale: "GPT-5.2 handles coding well", Complexity: &ComplexityConfig{ High: "gpt-5.2-high", Medium: "gpt-5.2", Low: "gpt-4.1", }, }, "refinery": { Model: "gpt-5.2-high", Fallback: []string{"gpt-5.2"}, Rationale: "High-capacity for thorough review", }, "witness": { Model: "gpt-4.1", Fallback: []string{"gpt-5.2"}, Rationale: "Efficient monitoring with newer GPT", }, }, Defaults: &DefaultConfig{ Model: "gpt-5.2", Fallback: []string{"gpt-5.2-high", "gpt-4.1"}, }, Providers: map[string]*ProviderConfig{ "anthropic": {Enabled: false}, "openai": {Enabled: true, Priority: 100}, "google": {Enabled: false}, }, }, }, "google-only": { Name: "google-only", Description: "Use only Google models (single-provider setup)", Author: "Gas Town", Version: "1.0.0", Tags: []string{"google", "single-provider", "gemini"}, UseCase: "Teams with Google AI access only", Config: &Config{ Version: 1, Roles: map[string]*RoleConfig{ "mayor": { Model: "gemini-3-ultra", Fallback: []string{"gemini-3-pro", "gemini-3-flash"}, Rationale: "Ultra for strategic coordination", }, "polecat": { Model: "gemini-3-pro", Fallback: []string{"gemini-3-ultra", "gemini-3-flash"}, Rationale: "Pro balances capability and cost", Complexity: &ComplexityConfig{ High: "gemini-3-ultra", Medium: "gemini-3-pro", Low: "gemini-3-flash", }, }, "refinery": { Model: "gemini-3-pro", Fallback: []string{"gemini-3-ultra"}, Rationale: "Pro for code review", }, "witness": { Model: "gemini-3-flash", Fallback: []string{"gemini-3-pro"}, Rationale: "Flash is extremely fast and cheap", }, }, Defaults: &DefaultConfig{ Model: "gemini-3-flash", Fallback: []string{"gemini-3-pro", "gemini-3-ultra"}, }, Providers: map[string]*ProviderConfig{ "anthropic": {Enabled: false}, "openai": {Enabled: false}, "google": {Enabled: true, Priority: 100}, }, }, }, }
PredefinedProfiles contains built-in profile configurations.
var ProviderEndpoints = map[string]string{
"anthropic": "https://api.anthropic.com/v1/messages",
"openai": "https://api.openai.com/v1/models",
"google": "https://generativelanguage.googleapis.com/v1/models",
}
ProviderEndpoints maps providers to their health check endpoints.
Functions ¶
func AlternateConfigPath ¶
AlternateConfigPath returns an alternate config path in settings/.
func ApplyProfile ¶
ApplyProfile applies a profile's configuration.
func ConfigPath ¶
ConfigPath returns the path to the council configuration file. By default, it's stored in .beads/council.toml in the town root.
func ExportProfileToFile ¶
ExportProfileToFile exports a profile to a JSON file.
func ModelProvider ¶
ModelProvider returns the provider for a model. Duplicated from cursor package to avoid circular imports.
func QuickRoute ¶
QuickRoute is a convenience function for simple routing.
func RouteWithComplexity ¶
func RouteWithComplexity(role string, complexity ComplexityLevel) (string, error)
RouteWithComplexity routes with explicit complexity level.
func SaveConfig ¶
SaveConfig saves council configuration to the given path. Saves as TOML for human readability.
func ValidateProfile ¶
ValidateProfile validates a profile configuration.
Types ¶
type ChainConfig ¶
type ChainConfig struct {
// Steps defines the sequence of models to use.
Steps []ChainStep `json:"steps" toml:"steps"`
// PassContext determines if each step receives the full conversation history.
PassContext bool `json:"pass_context" toml:"pass_context"`
// StopOnError halts the chain if any step fails.
StopOnError bool `json:"stop_on_error" toml:"stop_on_error"`
}
ChainConfig configures a chain-of-models pattern.
type ChainExecutor ¶
type ChainExecutor struct {
// contains filtered or unexported fields
}
ChainExecutor executes chain-of-models patterns.
func NewChainExecutor ¶
func NewChainExecutor(executor ModelExecutor, config *ChainConfig) *ChainExecutor
NewChainExecutor creates a new chain executor.
func (*ChainExecutor) Execute ¶
func (c *ChainExecutor) Execute(ctx context.Context, initialInput string) (*ChainResult, error)
Execute runs the chain of models.
type ChainResult ¶
type ChainResult struct {
Steps []StepResult `json:"steps"`
FinalOutput string `json:"final_output"`
TotalDuration time.Duration `json:"total_duration"`
TotalCost float64 `json:"total_cost"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
ChainResult represents the result of a chain execution.
type ChainStep ¶
type ChainStep struct {
// Name identifies this step.
Name string `json:"name" toml:"name"`
// Model to use for this step.
Model string `json:"model" toml:"model"`
// Role to apply (e.g., "refinery" for code review).
Role string `json:"role" toml:"role"`
// Prompt template or instruction for this step.
Prompt string `json:"prompt" toml:"prompt"`
// TransformOutput applies a transformation to the output before passing to next step.
TransformOutput string `json:"transform_output" toml:"transform_output"`
}
ChainStep represents a single step in a chain.
type CircuitBreaker ¶
type CircuitBreaker struct {
// State is "closed" (normal), "open" (failing), or "half-open" (testing)
State string
// FailureCount is consecutive failures in current window
FailureCount int
// LastFailure is the timestamp of the last failure
LastFailure time.Time
// LastSuccess is the timestamp of the last success
LastSuccess time.Time
// OpenedAt is when the circuit was opened
OpenedAt time.Time
// Threshold is failures before opening
Threshold int
// ResetTimeout is how long to wait before testing again
ResetTimeout time.Duration
}
CircuitBreaker implements circuit breaker pattern for providers.
type ComplexityConfig ¶
type ComplexityConfig struct {
// High complexity tasks (multi-file, architectural changes).
High string `json:"high" toml:"high"`
// Medium complexity tasks (single file, moderate changes).
Medium string `json:"medium" toml:"medium"`
// Low complexity tasks (small changes, simple fixes).
Low string `json:"low" toml:"low"`
}
ComplexityConfig defines models for different complexity levels.
type ComplexityLevel ¶
type ComplexityLevel int
ComplexityLevel represents task complexity.
const ( ComplexityLow ComplexityLevel = iota ComplexityMedium ComplexityHigh )
func ParseComplexity ¶
func ParseComplexity(s string) ComplexityLevel
ParseComplexity parses a complexity level from string.
func (ComplexityLevel) String ¶
func (c ComplexityLevel) String() string
String returns the string representation of a complexity level.
type Config ¶
type Config struct {
// Version is the schema version.
Version int `json:"version" toml:"version"`
// Roles maps Gas Town roles to their model configurations.
Roles map[string]*RoleConfig `json:"roles" toml:"roles"`
// Defaults contains default settings.
Defaults *DefaultConfig `json:"defaults,omitempty" toml:"defaults"`
// Providers contains provider-specific settings.
Providers map[string]*ProviderConfig `json:"providers,omitempty" toml:"providers"`
}
Config represents the Gas Town Council configuration. This defines role-model mappings and routing rules.
func DefaultCouncilConfig ¶
func DefaultCouncilConfig() *Config
DefaultCouncilConfig returns the default Gas Town Council configuration. This implements the role-model matrix from the Multi-Model Orchestration design.
func LoadConfig ¶
LoadConfig loads council configuration from the given path. Supports both TOML and JSON formats based on file extension.
func LoadOrCreate ¶
LoadOrCreate loads config from the path, creating default if it doesn't exist.
func (*Config) GetFallbackChain ¶
GetFallbackChain returns the fallback models for a role.
func (*Config) GetModelForComplexity ¶
func (c *Config) GetModelForComplexity(role string, complexity ComplexityLevel) string
GetModelForComplexity returns the model for a given complexity level.
func (*Config) GetModelForRole ¶
GetModelForRole returns the configured model for a role.
func (*Config) GetRationale ¶
GetRationale returns the rationale for a role's model selection.
func (*Config) SupportsComplexityRouting ¶
SupportsComplexityRouting checks if a role supports complexity-based routing.
type DefaultConfig ¶
type DefaultConfig struct {
// Model is the default model when no role-specific config exists.
Model string `json:"model" toml:"model"`
// Provider is the default provider.
Provider string `json:"provider,omitempty" toml:"provider"`
// Fallback is the default fallback chain.
Fallback []string `json:"fallback,omitempty" toml:"fallback"`
}
DefaultConfig contains default Council settings.
type EnsembleConfig ¶
type EnsembleConfig struct {
// Models to run in parallel.
Models []string `json:"models" toml:"models"`
// VotingStrategy determines how to combine outputs.
VotingStrategy VotingStrategy `json:"voting_strategy" toml:"voting_strategy"`
// Threshold for consensus (0-1, percentage of models that must agree).
Threshold float64 `json:"threshold" toml:"threshold"`
// Timeout for waiting on all models.
Timeout time.Duration `json:"timeout" toml:"timeout"`
// MinResponses is the minimum number of responses required before voting.
MinResponses int `json:"min_responses" toml:"min_responses"`
}
EnsembleConfig configures an ensemble voting pattern.
type EnsembleExecutor ¶
type EnsembleExecutor struct {
// contains filtered or unexported fields
}
EnsembleExecutor executes ensemble voting patterns.
func NewEnsembleExecutor ¶
func NewEnsembleExecutor(executor ModelExecutor, config *EnsembleConfig) *EnsembleExecutor
NewEnsembleExecutor creates a new ensemble executor.
func (*EnsembleExecutor) Execute ¶
func (e *EnsembleExecutor) Execute(ctx context.Context, prompt string) (*EnsembleResult, error)
Execute runs models in parallel and votes on output.
type EnsembleResult ¶
type EnsembleResult struct {
Responses []ModelResponse `json:"responses"`
Winner string `json:"winner"`
WinnerOutput string `json:"winner_output"`
Votes map[string]int `json:"votes"`
Agreement float64 `json:"agreement"` // 0-1
Duration time.Duration `json:"duration"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
EnsembleResult represents the result of an ensemble execution.
type FallbackManager ¶
type FallbackManager struct {
// contains filtered or unexported fields
}
FallbackManager handles provider availability and automatic fallback.
func NewFallbackManager ¶
func NewFallbackManager(router *Router) *FallbackManager
NewFallbackManager creates a new fallback manager.
func (*FallbackManager) CheckHealth ¶
func (fm *FallbackManager) CheckHealth(ctx context.Context, provider string) (*ProviderHealth, error)
CheckHealth performs a health check on a provider.
func (*FallbackManager) GetAllHealth ¶
func (fm *FallbackManager) GetAllHealth(ctx context.Context) map[string]*ProviderHealth
GetAllHealth returns health status for all providers.
func (*FallbackManager) GetAvailableProviders ¶
func (fm *FallbackManager) GetAvailableProviders() []string
GetAvailableProviders returns a list of currently available providers.
func (*FallbackManager) MaybeRecover ¶
func (fm *FallbackManager) MaybeRecover(ctx context.Context)
MaybeRecover checks if open circuits should be tested.
func (*FallbackManager) RecordRequestOutcome ¶
func (fm *FallbackManager) RecordRequestOutcome(provider string, success bool, err error)
RecordRequestOutcome records the outcome of a request for circuit breaker.
func (*FallbackManager) Reset ¶
func (fm *FallbackManager) Reset()
Reset resets all circuit breakers to closed state.
func (*FallbackManager) RouteWithFallback ¶
func (fm *FallbackManager) RouteWithFallback(req *RouteRequest) (*RouteResult, error)
RouteWithFallback routes a request with automatic fallback handling.
func (*FallbackManager) StartBackgroundRecovery ¶
func (fm *FallbackManager) StartBackgroundRecovery(ctx context.Context)
StartBackgroundRecovery starts a goroutine to periodically check for circuit recovery.
type Metrics ¶
type Metrics struct {
Version int `json:"version"`
UpdatedAt time.Time `json:"updated_at"`
ByRole map[string]*RoleMetrics `json:"by_role"`
ByModel map[string]*ModelMetrics `json:"by_model"`
ByProvider map[string]*ProviderMetrics `json:"by_provider"`
TaskHistory []TaskMetric `json:"task_history,omitempty"`
}
Metrics contains all collected metrics.
type MetricsStore ¶
type MetricsStore struct {
// contains filtered or unexported fields
}
MetricsStore stores and retrieves model performance metrics.
func NewMetricsStore ¶
func NewMetricsStore(townRoot string) (*MetricsStore, error)
NewMetricsStore creates a new metrics store.
func (*MetricsStore) CompareModels ¶
func (s *MetricsStore) CompareModels(model1, model2 string) *ModelComparison
CompareModels compares two models.
func (*MetricsStore) GetMetrics ¶
func (s *MetricsStore) GetMetrics() *Metrics
GetMetrics returns a copy of all metrics.
func (*MetricsStore) GetModelMetrics ¶
func (s *MetricsStore) GetModelMetrics(model string) *ModelMetrics
GetModelMetrics returns metrics for a specific model.
func (*MetricsStore) GetModelRanking ¶
func (s *MetricsStore) GetModelRanking() []string
GetModelRanking returns models ranked by success rate.
func (*MetricsStore) GetProviderMetrics ¶
func (s *MetricsStore) GetProviderMetrics(provider string) *ProviderMetrics
GetProviderMetrics returns metrics for a specific provider.
func (*MetricsStore) GetRecentTasks ¶
func (s *MetricsStore) GetRecentTasks(n int) []TaskMetric
GetRecentTasks returns the N most recent tasks.
func (*MetricsStore) GetRoleMetrics ¶
func (s *MetricsStore) GetRoleMetrics(role string) *RoleMetrics
GetRoleMetrics returns metrics for a specific role.
func (*MetricsStore) GetSummary ¶
func (s *MetricsStore) GetSummary() *Summary
GetSummary returns a high-level summary of metrics.
func (*MetricsStore) RecordRateLimit ¶
func (s *MetricsStore) RecordRateLimit(provider string) error
RecordRateLimit records a rate limit hit for a provider.
func (*MetricsStore) RecordTask ¶
func (s *MetricsStore) RecordTask(task TaskMetric) error
RecordTask records a task execution.
type ModelComparison ¶
type ModelComparison struct {
Model1 string `json:"model1"`
Model2 string `json:"model2"`
TaskDiff int `json:"task_diff"`
SuccessDiff float64 `json:"success_diff"`
DurationDiff time.Duration `json:"duration_diff_ms"`
CostDiff float64 `json:"cost_diff"`
}
CompareModels returns a comparison of two models.
type ModelExecutor ¶
type ModelExecutor interface {
Execute(ctx context.Context, model, prompt string) (*ModelResponse, error)
}
ModelExecutor executes prompts against models.
type ModelMetrics ¶
type ModelMetrics struct {
Model string `json:"model"`
Provider string `json:"provider"`
TotalTasks int `json:"total_tasks"`
CompletedTasks int `json:"completed_tasks"`
FailedTasks int `json:"failed_tasks"`
TotalDuration time.Duration `json:"total_duration_ms"`
TotalTokens int64 `json:"total_tokens"`
TotalCost float64 `json:"total_cost"`
AvgDuration time.Duration `json:"avg_duration_ms"`
SuccessRate float64 `json:"success_rate"`
RoleUsage map[string]int `json:"role_usage"` // role -> count
}
ModelMetrics contains metrics for a specific model.
type ModelResponse ¶
type ModelResponse struct {
Model string `json:"model"`
Output string `json:"output"`
Duration time.Duration `json:"duration"`
Tokens int64 `json:"tokens"`
Cost float64 `json:"cost"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Confidence float64 `json:"confidence"` // 0-1, model's confidence in response
}
ModelResponse represents a response from a single model.
type Pattern ¶
type Pattern string
Pattern represents an orchestration pattern for multi-model execution.
const ( // PatternSingle uses a single model for the task. PatternSingle Pattern = "single" // PatternChain passes output through a sequence of models. PatternChain Pattern = "chain" // PatternEnsemble runs multiple models in parallel and votes on output. PatternEnsemble Pattern = "ensemble" // PatternFallback tries models in sequence until one succeeds. PatternFallback Pattern = "fallback" // PatternSpecialist routes to specialized models based on task type. PatternSpecialist Pattern = "specialist" )
type Profile ¶
type Profile struct {
// Metadata
Name string `json:"name" toml:"name"`
Description string `json:"description" toml:"description"`
Author string `json:"author" toml:"author"`
Version string `json:"version" toml:"version"`
CreatedAt time.Time `json:"created_at" toml:"created_at"`
UpdatedAt time.Time `json:"updated_at" toml:"updated_at"`
// Tags for discovery
Tags []string `json:"tags,omitempty" toml:"tags"`
// Use case description
UseCase string `json:"use_case,omitempty" toml:"use_case"`
// The actual configuration
Config *Config `json:"config" toml:"config"`
// Performance metrics (optional)
Metrics *ProfileMetrics `json:"metrics,omitempty" toml:"metrics"`
}
Profile represents a shareable council configuration profile.
func ExportProfile ¶
ExportProfile exports the current configuration as a shareable profile.
func GetProfile ¶
GetProfile returns a predefined profile by name.
func ImportProfileFromFile ¶
ImportProfileFromFile imports a profile from a JSON file.
func SearchProfiles ¶
SearchProfiles searches profiles by tag.
type ProfileMetrics ¶
type ProfileMetrics struct {
TotalTasks int `json:"total_tasks" toml:"total_tasks"`
SuccessRate float64 `json:"success_rate" toml:"success_rate"`
AvgCostPerTask float64 `json:"avg_cost_per_task" toml:"avg_cost_per_task"`
CostSavings float64 `json:"cost_savings_percent" toml:"cost_savings_percent"`
ReportedIssues int `json:"reported_issues" toml:"reported_issues"`
CommunityRating float64 `json:"community_rating" toml:"community_rating"`
}
ProfileMetrics contains performance data for a profile.
type ProviderConfig ¶
type ProviderConfig struct {
// Enabled indicates if this provider is available.
Enabled bool `json:"enabled" toml:"enabled"`
// RateLimit is the rate limit in requests per minute.
RateLimit int `json:"rate_limit,omitempty" toml:"rate_limit"`
// Priority is used for fallback ordering (higher = preferred).
Priority int `json:"priority,omitempty" toml:"priority"`
// Models lists available models from this provider.
Models []string `json:"models,omitempty" toml:"models"`
}
ProviderConfig contains provider-specific settings.
type ProviderHealth ¶
type ProviderHealth struct {
Provider string `json:"provider"`
Available bool `json:"available"`
LastChecked time.Time `json:"last_checked"`
ResponseTime time.Duration `json:"response_time_ms"`
FailureCount int `json:"failure_count"`
CircuitState string `json:"circuit_state"`
RateLimitHits int `json:"rate_limit_hits"`
}
ProviderHealth represents the health status of a provider.
type ProviderMetrics ¶
type ProviderMetrics struct {
Provider string `json:"provider"`
TotalTasks int `json:"total_tasks"`
CompletedTasks int `json:"completed_tasks"`
FailedTasks int `json:"failed_tasks"`
TotalCost float64 `json:"total_cost"`
RateLimitHits int `json:"rate_limit_hits"`
AvgLatency time.Duration `json:"avg_latency_ms"`
Availability float64 `json:"availability"` // 0-1
}
ProviderMetrics contains metrics for a provider.
type RoleConfig ¶
type RoleConfig struct {
// Model is the primary model for this role.
Model string `json:"model" toml:"model"`
// Fallback is a list of fallback models if the primary is unavailable.
Fallback []string `json:"fallback,omitempty" toml:"fallback"`
// Rationale explains why this model was chosen for the role.
Rationale string `json:"rationale,omitempty" toml:"rationale"`
// ComplexityRouting enables routing based on task complexity.
ComplexityRouting bool `json:"complexity_routing,omitempty" toml:"complexity_routing"`
// Complexity defines model selection based on task complexity.
Complexity *ComplexityConfig `json:"complexity,omitempty" toml:"complexity"`
// Provider overrides the default provider detection.
Provider string `json:"provider,omitempty" toml:"provider"`
}
RoleConfig defines the model configuration for a Gas Town role.
type RoleMetrics ¶
type RoleMetrics struct {
Role string `json:"role"`
TotalTasks int `json:"total_tasks"`
CompletedTasks int `json:"completed_tasks"`
FailedTasks int `json:"failed_tasks"`
TotalDuration time.Duration `json:"total_duration_ms"`
TotalTokens int64 `json:"total_tokens"`
TotalCost float64 `json:"total_cost"`
ModelUsage map[string]int `json:"model_usage"` // model -> count
AvgDuration time.Duration `json:"avg_duration_ms"`
SuccessRate float64 `json:"success_rate"`
}
RoleMetrics contains metrics for a specific Gas Town role.
type RouteRequest ¶
type RouteRequest struct {
// Role is the Gas Town role making the request.
Role string
// Task describes the task (optional, for complexity analysis).
Task *TaskInfo
// PreferredModel is an optional model override.
PreferredModel string
// ExcludeProviders lists providers to exclude (e.g., due to rate limits).
ExcludeProviders []string
}
RouteRequest represents a request for model routing.
type RouteResult ¶
type RouteResult struct {
// Model is the selected model.
Model string
// Provider is the provider for the model.
Provider string
// Rationale explains why this model was selected.
Rationale string
// Complexity is the assessed task complexity.
Complexity ComplexityLevel
// Fallback indicates if this is a fallback selection.
Fallback bool
// FallbackReason explains why fallback was needed.
FallbackReason string
}
RouteResult contains the routing decision.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router selects the optimal model for a given task based on role and complexity.
func (*Router) GetProviderStatus ¶
GetProviderStatus returns a provider's availability status.
func (*Router) ReloadConfig ¶
ReloadConfig reloads the router configuration.
func (*Router) Route ¶
func (r *Router) Route(req *RouteRequest) (*RouteResult, error)
Route selects the optimal model for a request.
func (*Router) SetProviderStatus ¶
SetProviderStatus updates a provider's availability status.
type StepResult ¶
type StepResult struct {
Name string `json:"name"`
Model string `json:"model"`
Input string `json:"input"`
Output string `json:"output"`
Duration time.Duration `json:"duration"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
StepResult represents the result of a single chain step.
type Summary ¶
type Summary struct {
TotalTasks int `json:"total_tasks"`
CompletedTasks int `json:"completed_tasks"`
TotalCost float64 `json:"total_cost"`
AvgSuccessRate float64 `json:"avg_success_rate"`
TopModel string `json:"top_model"`
TopProvider string `json:"top_provider"`
CostSavings float64 `json:"cost_savings_percent"`
}
Summary returns a summary of all metrics.
type TaskInfo ¶
type TaskInfo struct {
// FilesAffected is the number of files the task will touch.
FilesAffected int
// LinesChanged is the estimated lines of code changed.
LinesChanged int
// IsArchitectural indicates if the change affects architecture.
IsArchitectural bool
// HasTests indicates if tests need to be written.
HasTests bool
// Description is a text description of the task.
Description string
}
TaskInfo provides information about the task for complexity analysis.
type TaskMetric ¶
type TaskMetric struct {
ID string `json:"id"`
Role string `json:"role"`
Model string `json:"model"`
Provider string `json:"provider"`
StartedAt time.Time `json:"started_at"`
CompletedAt time.Time `json:"completed_at,omitempty"`
Duration time.Duration `json:"duration_ms"`
Tokens int64 `json:"tokens,omitempty"`
Cost float64 `json:"cost,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Complexity string `json:"complexity,omitempty"`
Fallback bool `json:"fallback"`
}
TaskMetric records a single task execution.
type VotingStrategy ¶
type VotingStrategy string
VotingStrategy determines how ensemble outputs are combined.
const ( // VoteMajority takes the most common response. VoteMajority VotingStrategy = "majority" // VoteConsensus requires all models to agree. VoteConsensus VotingStrategy = "consensus" // VoteWeighted weights votes by model confidence/quality scores. VoteWeighted VotingStrategy = "weighted" // VoteBest selects the best response based on quality metrics. VoteBest VotingStrategy = "best" )