retry

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package retry implements the single retry/fallthrough engine shared by the router (credential rotation) and the agents adapter (model rotation).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(err error) bool

Classify reports whether err is retryable via errors.As unwrapping.

func Run

func Run[T any](ctx context.Context, candidates []Candidate[T], logger *slog.Logger) (T, error)

Run tries each candidate in order. The first success wins. A retryable error moves to the next candidate; a terminal error returns immediately. When every candidate fails with a retryable error, a single aggregated "all candidates exhausted" error is returned.

func RunStream

func RunStream(ctx context.Context, candidates []StreamCandidate, w io.Writer, logger *slog.Logger) error

RunStream tries each candidate in order, writing SSE to w. Streaming candidates must only write to w on success paths where the headers are already committed; a retryable failure before any write moves to the next candidate.

Types

type Candidate

type Candidate[T any] struct {
	Label string
	Run   func(ctx context.Context) (T, error)
}

Candidate is a single attempt for a non-streaming call.

type Classifiable

type Classifiable interface {
	Retryable() bool
}

Classifiable is implemented by errors that know whether they are retryable.

type StreamCandidate

type StreamCandidate struct {
	Label string
	Run   func(ctx context.Context, w io.Writer) error
}

StreamCandidate is a single attempt for a streaming call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL