Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCircuitOpen = fmt.Errorf("llm: circuit breaker open — too many recent failures")
ErrCircuitOpen is returned by ResilientClient when the circuit breaker is open.
Functions ¶
func StripCodeFences ¶
StripCodeFences removes markdown code fences (```json ... ```) that some models wrap around JSON responses. Returns the original string if no fences found.
Types ¶
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
AnthropicClient wraps the Anthropic Go SDK and implements LLMClient.
func NewAnthropicClient ¶
func NewAnthropicClient(apiKey string) *AnthropicClient
NewAnthropicClient creates an AnthropicClient authenticated with apiKey.
type GatewayClient ¶
type GatewayClient struct {
// contains filtered or unexported fields
}
GatewayClient sends completions through an OpenAI-compatible HTTP gateway. It implements LLMClient.
func NewGatewayClient ¶
func NewGatewayClient(baseURL, token string, timeoutSeconds int) *GatewayClient
NewGatewayClient creates a GatewayClient that POSTs to baseURL/v1/chat/completions authenticated with token. timeoutSeconds controls the HTTP client timeout (0 = no timeout).
type HTTPError ¶ added in v0.10.0
HTTPError is returned when an HTTP gateway responds with a non-2xx status.
type LLMClient ¶
type LLMClient interface {
Complete(ctx context.Context, model, systemPrompt, userMessage string, maxTokens int) (string, error)
}
LLMClient is the interface for sending a single-turn completion to a language model. All implementations must be safe for concurrent use.
func NewClient ¶
func NewClient(cfg config.ClaudeConfig) LLMClient
NewClient returns a ResilientClient wrapping the appropriate concrete LLMClient, or nil if no credentials are configured.
Priority:
- GatewayURL + GatewayToken set → GatewayClient (OpenAI-compatible gateway)
- APIKey set → AnthropicClient (direct Anthropic SDK)
- Neither set → nil (no LLM available; callers must guard against this)
type ResilientClient ¶ added in v0.10.0
type ResilientClient struct {
// contains filtered or unexported fields
}
ResilientClient wraps any LLMClient with a circuit breaker, exponential backoff retry, and a worker pool concurrency cap.
func NewResilientClient ¶ added in v0.10.0
func NewResilientClient( inner LLMClient, maxConcurrent, cbFailureThreshold, cbRecoverySeconds, maxRetries int, ) *ResilientClient
NewResilientClient wraps inner with resilience controls.
- maxConcurrent: maximum simultaneous in-flight LLM calls (worker pool size)
- cbFailureThreshold: consecutive failures before the circuit opens
- cbRecoverySeconds: seconds the circuit stays open before allowing a probe
- maxRetries: maximum additional attempts per call (0 = try once, no retry)
func (*ResilientClient) Complete ¶ added in v0.10.0
func (r *ResilientClient) Complete( ctx context.Context, model, systemPrompt, userMessage string, maxTokens int, ) (string, error)
Complete satisfies the LLMClient interface. It acquires a worker pool slot, then delegates to the circuit breaker which wraps the retry loop.