runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSingleModelProvider

func NewSingleModelProvider(cfg *op.ModelConfig) (ai.CanonicalProvider, error)

Types

type APIProvider

type APIProvider = ai.CanonicalProvider

type CanonicalRequest

type CanonicalRequest struct {
	ModelID string
	// ThreadID is the durable thread/chat identity.
	ThreadID string
	// SessionID is an optional transport/provider session hint, not transcript truth.
	SessionID string
	Params    *ai.ProviderRequest
}

type Config

type Config struct {
	Providers    []ProviderEndpoint
	Models       []LogicalModel
	RetryPolicy  RetryPolicy
	StickyPolicy StickyPolicy
	PoolPolicy   PoolPolicy
}

type LogicalModel

type LogicalModel struct {
	ID              string
	Name            string
	Provider        string
	API             string
	Reasoning       bool
	ReasoningLevels []string
	ContextWindow   int64
	MaxOutputTokens int64
	Routes          []RouteCandidate
}

type PoolPolicy

type PoolPolicy struct {
	Isolation           string
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConnsPerHost     int
	IdleConnTimeout     time.Duration
}

type ProviderEndpoint

type ProviderEndpoint struct {
	ID       string
	Provider string
	BaseURL  string
	APIKey   string
	Headers  map[string]string
}

type ProviderFactory

type ProviderFactory func(ctx context.Context, endpoint ProviderEndpoint, model LogicalModel, candidate RouteCandidate, httpClient *http.Client) (APIProvider, error)

type ResolveOptions

type ResolveOptions struct {
	// ThreadID is the durable thread/chat identity.
	ThreadID string
	// SessionID is an optional transport/provider session hint, not transcript truth.
	SessionID string
}

type ResolvedModel

type ResolvedModel struct {
	Model      LogicalModel
	Candidates []ResolvedRouteCandidate
}

type ResolvedRouteCandidate

type ResolvedRouteCandidate struct {
	Candidate RouteCandidate
	Endpoint  ProviderEndpoint
}

type ResponsesRequest

type ResponsesRequest struct {
	ModelID string
	// ThreadID is the durable thread/chat identity.
	ThreadID string
	// SessionID is an optional transport/provider session hint, not transcript truth.
	SessionID string
	Params    *ai.ResponsesRequest
}

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts      int
	InitialBackoff   time.Duration
	MaxBackoff       time.Duration
	JitterRatio      float64
	TotalBudget      time.Duration
	FirstByteTimeout time.Duration
	Cooldown         time.Duration
}

type RouteCandidate

type RouteCandidate struct {
	ProviderRef   string
	UpstreamModel string
	Priority      int
	Weight        int
}

type Runtime

type Runtime interface {
	ResolveModel(modelID string, opts ResolveOptions) (*ResolvedModel, error)
	CompleteCanonical(ctx context.Context, req *CanonicalRequest) (*ai.ProviderResponse, error)
	StreamCanonical(ctx context.Context, req *CanonicalRequest) (*ai.ProviderEventStream, error)
	CompleteResponses(ctx context.Context, req *ResponsesRequest) (*ai.ResponsesResult, error)
	StreamResponses(ctx context.Context, req *ResponsesRequest) (*ai.ResponsesEventStream, error)
	ListModels() []LogicalModel
}

func New

func New(config Config) (Runtime, error)

func NewWithFactory

func NewWithFactory(config Config, factory ProviderFactory) (Runtime, error)

type StickyPolicy

type StickyPolicy struct {
	Scope StickyScope
	TTL   time.Duration
}

type StickyScope

type StickyScope string
const (
	StickyScopeNone StickyScope = ""
	// StickyScopeThread uses the durable thread identity as the routing key.
	// This is the default for thread chat flows in opagent.
	StickyScopeThread StickyScope = "thread"
	// StickyScopeSession uses an optional transport/provider session hint.
	// It is not the persisted thread identity and should only be used when a
	// caller explicitly wants session-scoped stickiness outside normal thread chat.
	StickyScopeSession StickyScope = "session"
)

Jump to

Keyboard shortcuts

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