Documentation
¶
Index ¶
- Constants
- func ApplyTokenFallback(promptTokens, completionTokens int64, accumulatedContent string, ...) (promptResult, completionResult, totalResult int64)
- func ExtractJSON(jsonContent string, model any) error
- func FormatToolUseArgumentsError(toolName, raw string) string
- func IsRetriableError(err error) bool
- func IsRetriableStatus(statusCode int) bool
- func NormalizeToolUseArguments(raw, toolName string) (string, string, bool)
- func ParseToolUseArguments(raw string) (map[string]any, bool)
- func ReadAllContent(ctx context.Context, resp providers.Response) (string, error)
- func RepairToolHistory(history []types.Message) []types.Message
- func RetryBackoffDelay(attempt int) time.Duration
- func StructuredPredictWithFallback(ctx context.Context, req providers.Request, model any, ...) error
- func Truncate(s string, max int) string
- func WaitBackoff(ctx context.Context, delay time.Duration) error
Constants ¶
const MaxRetriableAttempts = 3
MaxRetriableAttempts is the number of times a provider client retries a retriable LLM error before giving up.
const TokenEstimateFactor = 0.6
TokenEstimateFactor is the empirical factor for estimating tokens from rune count
Variables ¶
This section is empty.
Functions ¶
func ApplyTokenFallback ¶
func ApplyTokenFallback(promptTokens, completionTokens int64, accumulatedContent string, requestMessages []types.Message, promptOverhead int64) (promptResult, completionResult, totalResult int64)
ApplyTokenFallback fills in token counts using FuzzyTokens if API didn't return them. API returned values take precedence, only applies fallback if missing. promptTokens: tokens from API response (0 if not returned) completionTokens: tokens from API response (0 if not returned) accumulatedContent: the accumulated content for completion token estimation requestMessages: the request messages for prompt token estimation promptOverhead: estimated tokens for system prompt and tool definitions
func ExtractJSON ¶
func FormatToolUseArgumentsError ¶
FormatToolUseArgumentsError builds a human-readable error for invalid tool arguments.
func IsRetriableError ¶
IsRetriableError reports whether err is worth retrying: rate limiting and transient server-side failures. It prefers typed SDK errors (exchanging the HTTP status code) and only falls back to tightened message matching for untyped errors, so digits that merely appear in request IDs or model names do not trigger a retry.
func IsRetriableStatus ¶
IsRetriableStatus reports whether an HTTP status code is retriable: 429 (rate limit) and 500-529 (server errors, incl. 529 overloaded).
func NormalizeToolUseArguments ¶
NormalizeToolUseArguments replaces non-object args with "{}" and returns an error string. Returns (normalized, errorMessage, ok). When ok is true, the input was a valid object.
func ParseToolUseArguments ¶
ParseToolUseArguments strictly parses raw as a JSON object. Returns nil, false if raw is empty, invalid JSON, or not an object.
func ReadAllContent ¶
func RepairToolHistory ¶
RepairToolHistory performs only unambiguous, provider-agnostic cleanup. Provider-specific tool-call ordering rules must be enforced by each client.
func RetryBackoffDelay ¶
RetryBackoffDelay returns the backoff delay to wait before retry attempt (1-based), growing linearly: 10s, 20s, 30s...
Types ¶
This section is empty.