Documentation
¶
Index ¶
Constants ¶
const ( // ConfigKeyAIProvider is the config key for the AI provider. ConfigKeyAIProvider = "ai.provider" // ConfigKeyOpenAIKey is the config key for the OpenAI API key. ConfigKeyOpenAIKey = "openai.api.key" // ConfigKeyClaudeKey is the config key for the Claude/Anthropic API key. ConfigKeyClaudeKey = "anthropic.api.key" // ConfigKeyGeminiKey is the config key for the Gemini API key. ConfigKeyGeminiKey = "gemini.api.key" )
const ( // EnvAIProvider is the environment variable for overriding the AI provider. EnvAIProvider = "AI_PROVIDER" // EnvOpenAIKey is the environment variable for overriding the OpenAI API key. EnvOpenAIKey = "OPENAI_API_KEY" // EnvClaudeKey is the environment variable for overriding the Claude API key. EnvClaudeKey = "ANTHROPIC_API_KEY" // EnvGeminiKey is the environment variable for overriding the Gemini API key. EnvGeminiKey = "GEMINI_API_KEY" )
const ( // DefaultModelGemini is the default model for the Gemini provider. DefaultModelGemini = "gemini-3-flash-preview" // DefaultModelClaude is the default model for the Claude provider. DefaultModelClaude = "claude-sonnet-4-5" // DefaultModelOpenAI is the default model for the OpenAI provider. DefaultModelOpenAI = openai.ChatModelGPT5 )
const (
// DefaultMaxTokensPerChunk is the default maximum tokens per chunk for OpenAI requests.
DefaultMaxTokensPerChunk = 4096
)
Variables ¶
This section is empty.
Functions ¶
func GenerateSchema ¶
GenerateSchema creates a JSON schema for a given type T. OpenAI's structured outputs feature uses a subset of JSON schema. The reflector is configured with flags to ensure the generated schema complies with this specific subset.
func RegisterProvider ¶
func RegisterProvider(name Provider, factory ProviderFactory)
RegisterProvider registers a factory function for a provider name. Call this from an init() function in your provider file or external package.
Types ¶
type ChatClient ¶
type ChatClient interface {
// Add appends a user message to the conversation history without triggering a completion.
Add(prompt string) error
// Ask sends a question to the chat service and unmarshals the response into the target struct.
Ask(question string, target any) error
// SetTools configures the tools available to the AI.
SetTools(tools []Tool) error
// Chat sends a message and returns the response content.
// If the AI requests tool calls, the provider may handle them internally or return them.
// For the Agent loop, we expect this method to return the AI's text response or trigger tool usage.
Chat(ctx context.Context, prompt string) (string, error)
}
ChatClient defines the interface for interacting with a chat service.
type Claude ¶
type Claude struct {
// contains filtered or unexported fields
}
Claude implements the ChatClient interface using Anthropic's official Go SDK.
func (*Claude) Ask ¶
Ask sends a question to the Claude chat client and expects a structured response.
type ClaudeLocal ¶
type ClaudeLocal struct {
// contains filtered or unexported fields
}
ClaudeLocal implements the ChatClient interface using a locally installed claude CLI binary. This provider is useful in environments where direct API access to api.anthropic.com is blocked but the pre-authenticated claude binary is permitted.
func (*ClaudeLocal) Add ¶
func (c *ClaudeLocal) Add(prompt string) error
Add buffers a user message to be prepended to the next Chat or Ask call.
func (*ClaudeLocal) Ask ¶
func (c *ClaudeLocal) Ask(question string, target any) error
Ask sends a question to the local claude binary and unmarshals the structured response into the target using --json-schema for schema-enforced output.
func (*ClaudeLocal) Chat ¶
Chat sends a message to the local claude binary and returns the text response.
func (*ClaudeLocal) SetTools ¶
func (c *ClaudeLocal) SetTools(_ []Tool) error
SetTools is not supported in Phase 1 of ProviderClaudeLocal. Tool integration via MCP server is planned for a future release.
type Config ¶
type Config struct {
// Provider is the AI service provider to use.
Provider Provider
// Model is the specific model to use (e.g., "gpt-4o", "claude-3-5-sonnet").
Model string
// Token is the API key or token for the service.
Token string
// BaseURL overrides the API endpoint. Required when using ProviderOpenAICompatible.
// Example: "http://localhost:11434/v1" for Ollama, "https://api.groq.com/openai/v1" for Groq.
BaseURL string
// SystemPrompt is the initial system prompt to set the context for the AI.
SystemPrompt string
// ResponseSchema is the JSON schema used to force a structured output from the AI.
ResponseSchema any
// SchemaName is the name of the response schema (e.g., "error_analysis").
SchemaName string
// SchemaDescription is a description of the response schema.
SchemaDescription string
}
Config holds configuration for a chat client.
type Gemini ¶
type Gemini struct {
// contains filtered or unexported fields
}
Gemini implements the ChatClient interface using Google's Generative AI SDK.
func (*Gemini) Ask ¶
Ask sends a question to the Gemini chat client and expects a structured response.
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI implements the ChatClient interface for interacting with OpenAI's API and any OpenAI-compatible API endpoint.
func (*OpenAI) Ask ¶
Ask sends a question to the OpenAI chat client and expects a structured response which is unmarshalled into the target interface.
type Provider ¶
type Provider string
Provider defines the AI service provider.
const ( // ProviderOpenAI uses OpenAI's API. ProviderOpenAI Provider = "openai" // ProviderOpenAICompatible uses any OpenAI-compatible API endpoint (e.g. Ollama, Groq). ProviderOpenAICompatible Provider = "openai-compatible" // ProviderClaude uses Anthropic's Claude API. ProviderClaude Provider = "claude" // ProviderClaudeLocal uses a locally installed claude CLI binary. ProviderClaudeLocal Provider = "claude-local" // ProviderGemini uses Google's Gemini API. ProviderGemini Provider = "gemini" )
type ProviderFactory ¶
ProviderFactory creates a ChatClient for a named provider. Register implementations via RegisterProvider in an init() function to allow external packages to add providers without modifying this file.