Documentation
¶
Index ¶
- func BindFlags(flags *pflag.FlagSet)
- func CleanupJSONResponse(response string) string
- func ListModels(ctx context.Context, config *AgentConfig) error
- func UnmarshalWithCleanup(data string, v interface{}) error
- func ValidateConfig(config AgentConfig) error
- type Agent
- type AgentConfig
- type AgentManager
- type AgentType
- type AiderAgent
- func (aa *AiderAgent) Close() error
- func (aa *AiderAgent) ExecuteBatch(ctx context.Context, requests []PromptRequest) (map[string]*PromptResponse, error)
- func (aa *AiderAgent) ExecutePrompt(ctx context.Context, request PromptRequest) (*PromptResponse, error)
- func (aa *AiderAgent) GetConfig() AgentConfig
- func (aa *AiderAgent) GetCosts() Costs
- func (aa *AiderAgent) GetType() AgentType
- func (aa *AiderAgent) ListModels(ctx context.Context) ([]Model, error)
- type AiderResponse
- type ClaudeAgent
- func (ca *ClaudeAgent) Close() error
- func (ca *ClaudeAgent) ExecuteBatch(ctx context.Context, requests []PromptRequest) (map[string]*PromptResponse, error)
- func (ca *ClaudeAgent) ExecutePrompt(ctx context.Context, request PromptRequest) (*PromptResponse, error)
- func (ca *ClaudeAgent) GetConfig() AgentConfig
- func (ca *ClaudeAgent) GetCosts() Costs
- func (ca *ClaudeAgent) GetType() AgentType
- func (ca *ClaudeAgent) ListModels(ctx context.Context) ([]Model, error)
- type ClaudeExecutor
- type ClaudeOptions
- type ClaudeResponse
- type Cost
- type CostInterface
- type Costs
- type Model
- type ModelUsageDetail
- type PromptRequest
- type PromptResponse
- type Session
- type Tokens
- type TypedPromptRequest
- type TypedPromptResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupJSONResponse ¶
CleanupJSONResponse attempts to extract and clean JSON from LLM responses that may contain markdown formatting, explanatory text, or other noise.
It tries the following strategies in order: 1. Extract JSON from markdown code blocks (```json or ```) 2. Extract the first JSON object {...} 3. Extract the first JSON array [...] 4. Return the trimmed original string
After extraction, it validates that the result is valid JSON.
func ListModels ¶
func ListModels(ctx context.Context, config *AgentConfig) error
ListModels lists all available models from configured AI agents
func UnmarshalWithCleanup ¶
UnmarshalWithCleanup attempts to unmarshal JSON with automatic cleanup
func ValidateConfig ¶
func ValidateConfig(config AgentConfig) error
ValidateConfig validates the agent configuration
Types ¶
type Agent ¶
type Agent interface {
// GetType returns the agent type
GetType() AgentType
// GetConfig returns the agent configuration
GetConfig() AgentConfig
// ListModels returns available models for this agent
ListModels(ctx context.Context) ([]Model, error)
// ExecutePrompt processes a single prompt
ExecutePrompt(ctx context.Context, request PromptRequest) (*PromptResponse, error)
// ExecuteBatch processes multiple prompts
ExecuteBatch(ctx context.Context, requests []PromptRequest) (map[string]*PromptResponse, error)
GetCosts() Costs
// Close cleans up resources
Close() error
}
Agent interface defines the contract for AI agents
func GetDefaultAgent ¶
type AgentConfig ¶
type AgentConfig struct {
Type AgentType `json:"type"`
Model string `json:"model"`
CacheDBPath string `json:"cache_db_path,omitempty"`
ProjectName string `json:"project_name,omitempty"`
SessionID string `json:"session_id,omitempty"`
CacheTTL time.Duration `json:"cache_ttl,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens"`
MaxConcurrent int `json:"max_concurrent"`
Debug bool `json:"debug"`
Verbose bool `json:"verbose"`
StrictMCPConfig bool `json:"strict_mcp_config"`
NoCache bool `json:"no_cache,omitempty"`
}
AgentConfig holds configuration for AI agents
func DefaultConfig ¶
func DefaultConfig() AgentConfig
DefaultConfig returns a default agent configuration
func (AgentConfig) Pretty ¶
func (a AgentConfig) Pretty() api.Text
type AgentManager ¶
type AgentManager struct {
// contains filtered or unexported fields
}
AgentManager manages AI agents
func NewAgentManager ¶
func NewAgentManager(config AgentConfig) *AgentManager
NewAgentManager creates a new agent manager
func (*AgentManager) Close ¶
func (am *AgentManager) Close() error
Close closes all agents and the cache
func (*AgentManager) GetAgent ¶
func (am *AgentManager) GetAgent(agentType AgentType) (Agent, error)
GetAgent returns an agent of the specified type, creating it if needed
func (*AgentManager) GetCache ¶
func (am *AgentManager) GetCache() *cache.Cache
GetCache returns the cache instance
func (*AgentManager) GetDefaultAgent ¶
func (am *AgentManager) GetDefaultAgent() (Agent, error)
GetDefaultAgent returns the default agent based on config
func (*AgentManager) ListAllModels ¶
func (am *AgentManager) ListAllModels(ctx context.Context) map[AgentType][]Model
ListAllModels returns models from all available agents
type AiderAgent ¶
type AiderAgent struct {
// contains filtered or unexported fields
}
AiderAgent implements the Agent interface for Aider
func NewAiderAgent ¶
func NewAiderAgent(config AgentConfig) (*AiderAgent, error)
NewAiderAgent creates a new Aider agent
func (*AiderAgent) ExecuteBatch ¶
func (aa *AiderAgent) ExecuteBatch(ctx context.Context, requests []PromptRequest) (map[string]*PromptResponse, error)
ExecuteBatch processes multiple prompts
func (*AiderAgent) ExecutePrompt ¶
func (aa *AiderAgent) ExecutePrompt(ctx context.Context, request PromptRequest) (*PromptResponse, error)
ExecutePrompt processes a single prompt
func (*AiderAgent) GetConfig ¶
func (aa *AiderAgent) GetConfig() AgentConfig
GetConfig returns the agent configuration
func (*AiderAgent) GetCosts ¶
func (aa *AiderAgent) GetCosts() Costs
func (*AiderAgent) GetType ¶
func (aa *AiderAgent) GetType() AgentType
GetType returns the agent type
func (*AiderAgent) ListModels ¶
func (aa *AiderAgent) ListModels(ctx context.Context) ([]Model, error)
ListModels returns available Aider models
type AiderResponse ¶
type AiderResponse struct {
FilesChanged []string `json:"files_changed,omitempty"`
Result string `json:"result"`
Error string `json:"error,omitempty"`
}
AiderResponse represents the response from Aider
type ClaudeAgent ¶
type ClaudeAgent struct {
// contains filtered or unexported fields
}
ClaudeAgent implements the Agent interface for Claude
func NewClaudeAgent ¶
func NewClaudeAgent(config AgentConfig) (*ClaudeAgent, error)
NewClaudeAgent creates a new Claude agent
func (*ClaudeAgent) ExecuteBatch ¶
func (ca *ClaudeAgent) ExecuteBatch(ctx context.Context, requests []PromptRequest) (map[string]*PromptResponse, error)
ExecuteBatch processes multiple prompts
func (*ClaudeAgent) ExecutePrompt ¶
func (ca *ClaudeAgent) ExecutePrompt(ctx context.Context, request PromptRequest) (*PromptResponse, error)
ExecutePrompt processes a single prompt
func (*ClaudeAgent) GetConfig ¶
func (ca *ClaudeAgent) GetConfig() AgentConfig
GetConfig returns the agent configuration
func (*ClaudeAgent) GetCosts ¶
func (ca *ClaudeAgent) GetCosts() Costs
func (*ClaudeAgent) GetType ¶
func (ca *ClaudeAgent) GetType() AgentType
GetType returns the agent type
func (*ClaudeAgent) ListModels ¶
func (ca *ClaudeAgent) ListModels(ctx context.Context) ([]Model, error)
ListModels returns available Claude models
type ClaudeExecutor ¶
type ClaudeExecutor struct {
// contains filtered or unexported fields
}
ClaudeExecutor manages Claude API calls with TaskManager integration
func NewClaudeExecutor ¶
func NewClaudeExecutor(options ClaudeOptions) *ClaudeExecutor
NewClaudeExecutor creates a new Claude executor
func (*ClaudeExecutor) ExecutePrompt ¶
func (ce *ClaudeExecutor) ExecutePrompt(_ context.Context, name, prompt string) (*ClaudeResponse, error)
ExecutePrompt executes a single Claude prompt with progress tracking
func (*ClaudeExecutor) ExecutePromptBatch ¶
func (ce *ClaudeExecutor) ExecutePromptBatch(ctx context.Context, prompts map[string]string) (map[string]*ClaudeResponse, error)
ExecutePromptBatch executes multiple prompts in parallel with concurrency control
func (*ClaudeExecutor) GetTaskManager ¶
func (ce *ClaudeExecutor) GetTaskManager() *clicky.TaskManager
GetTaskManager returns the global task manager
type ClaudeOptions ¶
type ClaudeOptions struct {
Model string
MaxTokens int
Debug bool
StrictMCPConfig bool
OutputFormat string
MaxConcurrent int
}
ClaudeOptions contains configuration for Claude API calls
type ClaudeResponse ¶
type ClaudeResponse struct {
Type string `json:"type"`
Subtype string `json:"subtype,omitempty"`
Result string `json:"result"`
IsError bool `json:"is_error"`
DurationMs int `json:"duration_ms"`
DurationAPIMs int `json:"duration_api_ms,omitempty"`
NumTurns int `json:"num_turns,omitempty"`
SessionID string `json:"session_id,omitempty"`
TotalCostUSD float64 `json:"total_cost_usd"`
UUID string `json:"uuid,omitempty"`
PermissionDenials []string `json:"permission_denials,omitempty"`
Usage struct {
InputTokens int `json:"input_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens"`
CacheReadInputTokens int `json:"cache_read_input_tokens"`
OutputTokens int `json:"output_tokens"`
ServerToolUse struct {
WebSearchRequests int `json:"web_search_requests"`
} `json:"server_tool_use,omitempty"`
ServiceTier string `json:"service_tier,omitempty"`
CacheCreation struct {
Ephemeral1hInputTokens int `json:"ephemeral_1h_input_tokens"`
Ephemeral5mInputTokens int `json:"ephemeral_5m_input_tokens"`
} `json:"cache_creation,omitempty"`
} `json:"usage"`
ModelUsage map[string]ModelUsageDetail `json:"modelUsage,omitempty"`
}
ClaudeResponse represents the response from Claude CLI
func (*ClaudeResponse) GetAllTokens ¶
func (r *ClaudeResponse) GetAllTokens() int
GetAllTokens returns all tokens including cache reads
func (ClaudeResponse) GetCosts ¶
func (cr ClaudeResponse) GetCosts() Costs
func (*ClaudeResponse) GetTotalTokens ¶
func (r *ClaudeResponse) GetTotalTokens() int
GetTotalTokens returns the total billable tokens (excluding cache reads)
func (ClaudeResponse) Pretty ¶
func (r ClaudeResponse) Pretty() api.Text
type Cost ¶
type CostInterface ¶
type CostInterface interface {
GetTotalCost() Cost
}
type Model ¶
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
Provider string `json:"provider"`
Metadata map[string]string `json:"metadata,omitempty"`
InputPrice float64 `json:"input_price_per_token,omitempty"`
OutputPrice float64 `json:"output_price_per_token,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
}
Model represents an AI model
type ModelUsageDetail ¶
type ModelUsageDetail struct {
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CacheReadInputTokens int `json:"cacheReadInputTokens"`
CacheCreationInputTokens int `json:"cacheCreationInputTokens"`
WebSearchRequests int `json:"webSearchRequests"`
CostUSD float64 `json:"costUSD"`
ContextWindow int `json:"contextWindow"`
}
ModelUsageDetail represents per-model usage information
type PromptRequest ¶
type PromptRequest struct {
Context map[string]string `json:"context,omitempty"`
Name string `json:"name"`
Prompt string `json:"prompt"`
StructuredOutput interface{} `json:"structured_output,omitempty"` // Schema for structured JSON output
}
PromptRequest represents a request to process a prompt
type PromptResponse ¶
type PromptResponse struct {
Request PromptRequest `json:"request,omitempty"`
Result string `json:"result"`
StructuredData interface{} `json:"structured_data,omitempty"` // Populated if structured output was requested
Costs Costs `json:"costs,omitempty"`
Model string `json:"model,omitempty"`
Error string `json:"error,omitempty"`
// Total wall-clock duration of the request
Duration time.Duration `json:"duration,omitempty"`
// Duration spent in the model processing as reported by the API
DurationModel time.Duration `json:"duration_model,omitempty"`
CacheHit bool `json:"cache_hit,omitempty"`
}
PromptResponse represents the response from processing a prompt
func (PromptResponse) IsOK ¶
func (pr PromptResponse) IsOK() bool
func (PromptResponse) Pretty ¶
func (pr PromptResponse) Pretty() api.Text
func (PromptResponse) PrettyFull ¶
func (pr PromptResponse) PrettyFull() api.Text
type Session ¶
type Session struct {
ID string
ProjectName string
Costs Costs
// contains filtered or unexported fields
}
Session tracks costs across multiple agent calls
func NewSession ¶
NewSession creates a new session for tracking costs
func (*Session) GetCostsByModel ¶
GetCostsByModel returns costs grouped by model
func (*Session) GetTotalCost ¶
GetTotalCost returns the aggregated cost across all entries
type Tokens ¶
type TypedPromptRequest ¶
type TypedPromptRequest[T any] struct { Context map[string]string `json:"context,omitempty"` Name string `json:"name"` Prompt string `json:"prompt"` }
TypedPromptRequest represents a type-safe request with structured output
type TypedPromptResponse ¶
type TypedPromptResponse[T any] struct { Request TypedPromptRequest[T] `json:"request,omitempty"` Data T `json:"data"` Costs Costs `json:"costs,omitempty"` Model string `json:"model,omitempty"` Error string `json:"error,omitempty"` Duration time.Duration `json:"duration,omitempty"` DurationModel time.Duration `json:"duration_model,omitempty"` CacheHit bool `json:"cache_hit,omitempty"` }
TypedPromptResponse represents a type-safe response with structured output
func ExecutePromptTyped ¶
func ExecutePromptTyped[T any](ctx context.Context, agent Agent, request TypedPromptRequest[T]) (*TypedPromptResponse[T], error)
ExecutePromptTyped is a generic helper that executes a prompt with type-safe structured output. It automatically cleans up the JSON response before unmarshaling into the target type.
func (TypedPromptResponse[T]) IsOK ¶
func (tr TypedPromptResponse[T]) IsOK() bool