Documentation
¶
Overview ¶
Package goagent adapts llmkit routing to goagent's LLMClient port.
Index ¶
- func DefaultErrorClassifier(err error) llmkit.ErrorClass
- func OpenAICompatibleProvidersFromConfig(config llmkit.Config, getenv func(string) string, httpClient *http.Client, ...) (map[string]ProviderClient, error)
- type Client
- type Config
- type ErrorClassifier
- type ErrorStage
- type FallbackPolicy
- type ModelStatsProvider
- type PreDispatchConfig
- type PreDispatchHook
- type PreDispatchMetadata
- type PreDispatchMetadataProvider
- type PreDispatchRequest
- type ProfileProvider
- type ProviderClient
- type ProviderDispatchStatus
- type ProviderRequestDigester
- type ProviderStreamRequestDigester
- type RouteMetadata
- type RouteMetadataProvider
- type RuntimeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorClassifier ¶
func DefaultErrorClassifier(err error) llmkit.ErrorClass
DefaultErrorClassifier maps typed provider and network errors to stable audit classes without depending on provider-specific error messages.
func OpenAICompatibleProvidersFromConfig ¶
func OpenAICompatibleProvidersFromConfig(config llmkit.Config, getenv func(string) string, httpClient *http.Client, limits openaiapi.Limits) (map[string]ProviderClient, error)
OpenAICompatibleProvidersFromConfig builds provider clients for configured OpenAI-compatible models. It reads API key values from getenv at construction time and never stores keys in llmkit audit records.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements goagent's LLMClient by routing to a provider client.
func (*Client) Chat ¶
func (c *Client) Chat(ctx context.Context, req ports.ChatRequest) (*ports.ChatResponse, error)
Chat selects a route, records the route trace, and delegates to the selected provider client.
func (*Client) ChatStream ¶
func (c *Client) ChatStream(ctx context.Context, req ports.ChatRequest, onDelta func(ports.ChatDelta) error) (*ports.ChatResponse, error)
ChatStream routes like Chat and delivers the selected provider's output to onDelta: streamed when the provider implements ports.StreamingLLMClient, otherwise as one delta of the complete response. An attempt that already delivered output never falls back, so the caller never sees two answers.
type Config ¶
type Config struct {
Policy llmkit.RoutePolicy
Candidates []llmkit.Candidate
Providers map[string]ProviderClient
ProfileProvider ProfileProvider
RouteMetadataProvider RouteMetadataProvider
Recorder llmkit.Recorder
RecordOutcomes bool
ModelStats *llmkit.ModelStats
ModelStatsProvider ModelStatsProvider
HealthStore llmkit.HealthStore
FallbackPolicy FallbackPolicy
ErrorClassifier ErrorClassifier
// PreDispatch installs a host claim boundary before each provider call.
// It implies FallbackPolicy.FailClosed.
PreDispatch PreDispatchConfig
}
Config configures the goagent adapter.
type ErrorClassifier ¶
type ErrorClassifier func(error) llmkit.ErrorClass
ErrorClassifier maps provider errors to llmkit's stable fallback/audit classes.
type ErrorStage ¶
type ErrorStage string
ErrorStage 无需解析错误文本即可标识 runtime 调用的失败阶段。
const ( ErrorStageRoute ErrorStage = "route" ErrorStageConfig ErrorStage = "config" ErrorStagePreCall ErrorStage = "pre_call" ErrorStageProvider ErrorStage = "provider" ErrorStagePostCall ErrorStage = "post_call" )
type FallbackPolicy ¶
type FallbackPolicy struct {
// MaxAttempts caps provider attempts per request; <= 0 tries every
// remaining eligible candidate.
MaxAttempts int
// FailClosed restricts fallback to failures the provider proved happened
// before dispatch and whose class is in RetryableErrorClasses, so a request
// that may have reached a provider is never sent to a second one. Without
// it, any provider failure falls back.
FailClosed bool
RetryableErrorClasses []llmkit.ErrorClass
}
FallbackPolicy controls which provider failures move on to the next candidate.
type ModelStatsProvider ¶
type ModelStatsProvider func(context.Context) (*llmkit.ModelStats, error)
ModelStatsProvider supplies fresh model statistics before each route decision.
type PreDispatchConfig ¶
type PreDispatchConfig struct {
MetadataProvider PreDispatchMetadataProvider
Hook PreDispatchHook
}
PreDispatchConfig 启用可选的 Provider claim 边界。
type PreDispatchHook ¶
type PreDispatchHook func(context.Context, PreDispatchRequest) error
PreDispatchHook 在路由和请求摘要构造后、health 计数或 Provider 调用前执行。
type PreDispatchMetadata ¶
PreDispatchMetadata 标识一次由 Host 所有的 Provider claim。
type PreDispatchMetadataProvider ¶
type PreDispatchMetadataProvider func(context.Context, ports.ChatRequest) PreDispatchMetadata
PreDispatchMetadataProvider 为每次 Provider 尝试提供 Host 所有的 dispatch 标识, 同时不改变 v0.1.0 RouteMetadata 合同。
type PreDispatchRequest ¶
type PreDispatchRequest struct {
Route llmkit.RouteTrace
ProviderCallIndex int
Attempt int
ProviderClass string
RunRequestSHA256 [sha256.Size]byte
ProviderRequestSHA256 [sha256.Size]byte
}
PreDispatchRequest 只包含白名单路由数据和请求摘要, 有意不暴露 ChatRequest 或凭据字段。
type ProfileProvider ¶
type ProfileProvider func(context.Context, ports.ChatRequest) llmkit.TaskProfile
ProfileProvider supplies task routing metadata for a goagent request.
type ProviderClient ¶
type ProviderClient interface {
Chat(context.Context, ports.ChatRequest) (*ports.ChatResponse, error)
}
ProviderClient is the provider-side chat client selected by route alias.
type ProviderDispatchStatus ¶
type ProviderDispatchStatus interface {
ProviderDispatched() bool
}
ProviderDispatchStatus 让 Provider 证明错误发生在出站前; 无法证明的错误按已经 dispatch 处理。
type ProviderRequestDigester ¶
type ProviderRequestDigester interface {
ProviderRequestSHA256(ports.ChatRequest) ([sha256.Size]byte, error)
}
ProviderRequestDigester 暴露 Provider 实际发送的请求 body 摘要; Provider 不支持时,pre-dispatch hook 必须 fail closed。
type ProviderStreamRequestDigester ¶
type ProviderStreamRequestDigester interface {
ProviderStreamRequestSHA256(ports.ChatRequest) ([sha256.Size]byte, error)
}
ProviderStreamRequestDigester is ProviderRequestDigester for the body a streaming provider's ChatStream sends.
type RouteMetadata ¶
RouteMetadata contains host-provided trace identifiers.
type RouteMetadataProvider ¶
type RouteMetadataProvider func(context.Context, ports.ChatRequest) RouteMetadata
RouteMetadataProvider supplies allowlisted trace identifiers.
type RuntimeError ¶
type RuntimeError struct {
Stage ErrorStage
Class llmkit.ErrorClass
ProviderDispatched bool
// contains filtered or unexported fields
}
RuntimeError 暴露稳定的失败元数据,并保留供 errors.Is/errors.As 使用的类型化原因; Error 有意不输出底层消息。
func (*RuntimeError) Error ¶
func (e *RuntimeError) Error() string
func (*RuntimeError) Unwrap ¶
func (e *RuntimeError) Unwrap() error