Documentation
¶
Overview ¶
Package provider defines the complete model-provider boundary consumed by Floret's runtime. Gateways own transport; the runtime owns the Agent loop.
Index ¶
- Constants
- Variables
- func OllamaReasoningEffort(capability config.ReasoningCapability, selection config.ReasoningSelection) (string, error)
- func ParseOllamaReasoningCapability(raw json.RawMessage, thinkingCapable bool) (config.ReasoningCapability, error)
- func WithRetryAdvice(cause error, advice RetryAdvice) error
- type AnthropicOptions
- type Attachment
- type AttachmentPayloadMode
- type AttachmentTextStats
- type Capabilities
- type ContentAttributionPart
- type DeepSeekOptions
- type Event
- type EventType
- type Gateway
- type HostedToolDefinition
- type HostedToolResult
- type HostedToolResultError
- type HostedToolResultItem
- type Identity
- type Labels
- type Message
- type MessageAttribution
- type MessageRole
- type OpenAICompatibleOptions
- type OutputControl
- type PreparedRequest
- type PreparedRequestOutputLimiter
- type PreparedRequestReplay
- type ProviderHTTPError
- type ReasoningHistoryPolicy
- type ReasoningSupport
- type RenderedContentAttribution
- type RenderedRequest
- type Request
- type RequestFormat
- type RequestPreparer
- type RequestReusePolicy
- type RequestTimeoutDetails
- type RequestTimeoutError
- type RetryAdvice
- type RetryAdviser
- type RetryCategory
- type Source
- type State
- type StateReusePolicy
- type TokenEstimate
- type ToolCall
- type ToolCallStream
- type ToolResult
- type Usage
Constants ¶
const ( RetryTransient = RetryCategory(providerretry.Transient) RetryRateLimit = RetryCategory(providerretry.RateLimit) RetryTimeout = RetryCategory(providerretry.Timeout) RetryStreamInterrupted = RetryCategory(providerretry.Interrupted) RetryPermanent = RetryCategory(providerretry.Permanent) )
Variables ¶
var ( // ErrContextOverflow reports that a provider rejected a request because its // rendered context exceeded the model limit. ErrContextOverflow = errors.New("provider context overflow") )
var ErrRequestTimeout = internalprovider.ErrRequestTimeout
ErrRequestTimeout identifies a runtime-enforced physical request deadline.
Functions ¶
func OllamaReasoningEffort ¶ added in v7.22.0
func OllamaReasoningEffort(capability config.ReasoningCapability, selection config.ReasoningSelection) (string, error)
OllamaReasoningEffort maps verified model intent to the OpenAI-compatible reasoning_effort field. An empty result must be omitted. Boolean On uses Ollama's documented medium compatibility alias; named levels stay exact.
func ParseOllamaReasoningCapability ¶ added in v7.22.0
func ParseOllamaReasoningCapability(raw json.RawMessage, thinkingCapable bool) (config.ReasoningCapability, error)
ParseOllamaReasoningCapability resolves the thinking object from /api/show. Metadata is authoritative, independent of model names. Missing metadata and unknown named levels retain provider-managed behavior without invented controls. Default remains an omitted request parameter, not a frozen server default.
func WithRetryAdvice ¶ added in v7.38.0
func WithRetryAdvice(cause error, advice RetryAdvice) error
WithRetryAdvice preserves cause and exposes immutable protocol facts.
Types ¶
type AnthropicOptions ¶
type AnthropicOptions struct {
Provider string
Model string
BaseURL string
APIKey string
StateCompatibilityKey string
HTTPClient *http.Client
Capabilities Capabilities
}
AnthropicOptions configures an explicit Anthropic messages transport. BaseURL is the API root; the gateway sends requests to BaseURL/messages.
type Attachment ¶
type Attachment struct {
ResourceRef string `json:"resource_ref"`
Name string `json:"name"`
MIMEType string `json:"mime_type"`
SizeBytes int64 `json:"size_bytes,omitempty"`
TextStats *AttachmentTextStats `json:"text_stats,omitempty"`
}
Attachment is an opaque host resource descriptor visible to a gateway.
type AttachmentPayloadMode ¶
type AttachmentPayloadMode string
AttachmentPayloadMode declares whether Request attachments stay as opaque descriptors or are expanded by a prepared request.
const ( // AttachmentDescriptors keeps attachment resource references opaque. AttachmentDescriptors AttachmentPayloadMode = "descriptors" // AttachmentExpanded requires Gateway to implement RequestPreparer. AttachmentExpanded AttachmentPayloadMode = "expanded" )
type AttachmentTextStats ¶
type AttachmentTextStats struct {
UnicodeCodePointCount int64 `json:"unicode_code_points"`
LogicalLineCount int64 `json:"logical_lines"`
}
AttachmentTextStats is a stable display snapshot for textual attachments.
type Capabilities ¶
type Capabilities struct {
// OutputControl declares whether a client output ceiling is enforced.
OutputControl OutputControl `json:"output_control,omitempty"`
Reasoning ReasoningSupport `json:"reasoning"`
ReasoningCapability config.ReasoningCapability `json:"reasoning_capability,omitempty"`
AttachmentPayload AttachmentPayloadMode `json:"attachment_payload"`
ReasoningHistory ReasoningHistoryPolicy `json:"reasoning_history,omitempty"`
}
Capabilities describes provider behavior that affects request validation.
func (Capabilities) Validate ¶
func (capabilities Capabilities) Validate() error
Validate verifies an explicit capability declaration.
type ContentAttributionPart ¶ added in v7.47.0
type ContentAttributionPart struct {
// Category optionally identifies a span within merged protocol instructions.
Category string `json:"category,omitempty"`
Start int `json:"start"`
End int `json:"end"`
Key string `json:"key,omitempty"`
}
ContentAttributionPart identifies one contiguous decoded-text span.
type DeepSeekOptions ¶ added in v7.2.0
type DeepSeekOptions struct {
Model string
BaseURL string
APIKey string
StateCompatibilityKey string
HTTPClient *http.Client
Temperature *float64
TopP *float64
ResponseFormat string
// ResolveAttachment resolves an authorized opaque attachment into image bytes.
// It runs during Prepare (or Stream for direct callers), never during replay
// of a prepared request. Nil preserves descriptor-only behavior. The gateway
// accepts images only when the selected model advertises image input.
ResolveAttachment func(context.Context, Attachment) ([]byte, error)
}
DeepSeekOptions configures DeepSeek's stateless Responses transport. BaseURL is the API root. Sampling and output format apply to every request made by this gateway; ResponseFormat accepts empty, text, or json_object. Opaque response state belongs to Floret and must be passed back unchanged.
type Event ¶
type Event struct {
Type EventType `json:"type"`
Text string `json:"text,omitempty"`
ToolCallStream *ToolCallStream `json:"tool_call_stream,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
HostedToolCall *ToolCall `json:"hosted_tool_call,omitempty"`
HostedResult *HostedToolResult `json:"hosted_result,omitempty"`
Sources []Source `json:"sources,omitempty"`
Reason string `json:"reason,omitempty"`
Usage Usage `json:"usage,omitempty"`
ResponseID string `json:"response_id,omitempty"`
ResponseState *State `json:"response_state,omitempty"`
Err error `json:"-"`
}
Event carries one streamed provider output.
type EventType ¶
type EventType string
EventType is one streamed provider event kind.
const ( // EventDelta appends assistant text. EventDelta EventType = "delta" // EventReasoning appends assistant reasoning. EventReasoning EventType = "reasoning" // EventToolCallStart begins one streamed tool call. EventToolCallStart EventType = "tool_call_start" // EventToolCallDelta appends streamed tool-call arguments. EventToolCallDelta EventType = "tool_call_delta" // EventToolCallEnd ends one streamed tool call. EventToolCallEnd EventType = "tool_call_end" // EventToolCalls delivers executable local tool calls. EventToolCalls EventType = "tool_calls" // EventUsage reports normalized provider usage. EventUsage EventType = "usage" // EventSources reports provider citations. EventSources EventType = "sources" // EventHostedToolCall reports a provider-native tool invocation. EventHostedToolCall EventType = "hosted_tool_call" // EventHostedToolResult reports the structured result of a provider-native // tool invocation. EventHostedToolResult EventType = "hosted_tool_result" // EventDone terminates a successful provider step. EventDone EventType = "done" // EventEmpty terminates an empty provider step. EventEmpty EventType = "empty" // EventTruncated terminates a length-limited provider step. EventTruncated EventType = "truncated" // EventError terminates a failed provider step. EventError EventType = "error" )
type Gateway ¶
type Gateway interface {
Identity() Identity
Capabilities() Capabilities
Stream(context.Context, Request) (<-chan Event, error)
}
Gateway is the single model-execution path used by every Agent.
func NewAnthropic ¶
func NewAnthropic(options AnthropicOptions) (Gateway, error)
NewAnthropic constructs an explicit Anthropic messages Gateway.
func NewDeepSeek ¶ added in v7.2.0
func NewDeepSeek(options DeepSeekOptions) (Gateway, error)
NewDeepSeek constructs the single DeepSeek Responses execution path, including streaming reasoning and validated stateless history replay. Hosted web_search wire input remains accepted for v7 compatibility; the official API ignores it. Image input is an optional per-model capability resolved by the host.
func NewOpenAICompatible ¶
func NewOpenAICompatible(options OpenAICompatibleOptions) (Gateway, error)
NewOpenAICompatible constructs an explicit OpenAI-compatible Gateway.
type HostedToolDefinition ¶
type HostedToolDefinition struct {
// ReplaySafe permits repeating the entire model request after uncertain dispatch.
ReplaySafe bool `json:"replay_safe,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Parameters map[string]any `json:"parameters,omitempty"`
Options map[string]any `json:"options,omitempty"`
}
HostedToolDefinition is one provider-native capability that the local tool runtime must not dispatch.
type HostedToolResult ¶
type HostedToolResult struct {
// ResultsProvided is true when the provider returned a structured result list, including an empty list.
ResultsProvided bool `json:"results_provided,omitempty"`
Text string `json:"text,omitempty"`
Results []HostedToolResultItem `json:"results,omitempty"`
Error *HostedToolResultError `json:"error,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
HostedToolResult is a provider-neutral projection of provider-native tool output.
type HostedToolResultError ¶
type HostedToolResultError struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
HostedToolResultError describes a provider-native tool failure.
type HostedToolResultItem ¶
type HostedToolResultItem struct {
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Snippet string `json:"snippet,omitempty"`
Source string `json:"source,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
HostedToolResultItem is one structured provider-native result item.
type Identity ¶
type Identity struct {
Provider string `json:"provider"`
Model string `json:"model"`
StateCompatibilityKey string `json:"state_compatibility_key"`
}
Identity describes one provider/model transport and its opaque-state compatibility boundary.
type Labels ¶
type Labels struct {
Correlation map[string]string `json:"correlation,omitempty"`
Host map[string]string `json:"host,omitempty"`
}
Labels carries opaque correlation and host labels.
type Message ¶
type Message struct {
// Attribution is observation-only provenance, never model input.
Attribution *MessageAttribution `json:"attribution,omitempty"`
Role MessageRole `json:"role"`
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolResult *ToolResult `json:"tool_result,omitempty"`
}
Message is one typed provider-visible context item.
type MessageAttribution ¶ added in v7.47.0
type MessageAttribution struct {
Category string `json:"category"`
Parts []ContentAttributionPart `json:"parts,omitempty"`
}
MessageAttribution identifies canonical model-context or compaction text. Parts partition Text by UTF-8 byte offsets and contain no prompt content.
type MessageRole ¶
type MessageRole string
MessageRole is a provider-visible message role.
const ( // RoleSystem identifies a system instruction. RoleSystem MessageRole = "system" // RoleUser identifies admitted user input. RoleUser MessageRole = "user" // RoleAssistant identifies assistant output or tool calls. RoleAssistant MessageRole = "assistant" // RoleTool identifies one local tool result. RoleTool MessageRole = "tool" )
type OpenAICompatibleOptions ¶
type OpenAICompatibleOptions struct {
Provider string
Model string
BaseURL string
APIKey string
StateCompatibilityKey string
HTTPClient *http.Client
Capabilities Capabilities
}
OpenAICompatibleOptions configures an explicit OpenAI chat-completions transport. BaseURL is the API root; the gateway sends requests to BaseURL/chat/completions.
type OutputControl ¶ added in v7.48.0
type OutputControl string
OutputControl describes who enforces a provider request output ceiling.
const ( OutputControlClient OutputControl = "client" OutputControlServer OutputControl = "server" )
type PreparedRequest ¶
type PreparedRequest interface {
Stream(context.Context) (<-chan Event, error)
TokenEstimate() TokenEstimate
RenderedPayloadFingerprint() string
Close() error
}
PreparedRequest is one immutable, single-use rendered provider request.
type PreparedRequestOutputLimiter ¶ added in v7.48.0
type PreparedRequestOutputLimiter interface {
WithMaxOutputTokens(context.Context, int64) (PreparedRequest, error)
}
PreparedRequestOutputLimiter creates a new single-use request from frozen input. It must change only the output ceiling, retain its input estimate, and never read attachments, collect context, authorize effects, or mutate the original.
type PreparedRequestReplay ¶ added in v7.38.0
type PreparedRequestReplay interface {
PrepareRetry(context.Context, Request) (PreparedRequest, error)
}
PreparedRequestReplay optionally creates a fresh single-use attempt from the original immutable rendering, even after Close. It must not reopen resources or resolve attachments. Only execution identity may differ in request.
type ProviderHTTPError ¶ added in v7.10.3
ProviderHTTPError reports a non-successful HTTP response from a provider. Message and Code are provider-supplied values after transport-safe sanitization; they never contain authorization headers or request bodies.
func (*ProviderHTTPError) Error ¶ added in v7.10.3
func (e *ProviderHTTPError) Error() string
func (*ProviderHTTPError) ProviderRetryAdvice ¶ added in v7.38.0
func (e *ProviderHTTPError) ProviderRetryAdvice() RetryAdvice
ProviderRetryAdvice classifies an HTTP error without parsing its human message.
type ReasoningHistoryPolicy ¶ added in v7.25.0
type ReasoningHistoryPolicy string
ReasoningHistoryPolicy selects transient reasoning replay without changing canonical conversation storage, visible answers, or tool call/result pairs.
const ( // ReasoningHistoryAll preserves reasoning from all messages (the default). ReasoningHistoryAll ReasoningHistoryPolicy = "all" // ReasoningHistoryCurrentUser replays reasoning only after the latest // canonical user message. Ephemeral supplemental input is not a boundary. ReasoningHistoryCurrentUser ReasoningHistoryPolicy = "current_user" )
type ReasoningSupport ¶
type ReasoningSupport string
ReasoningSupport declares whether a gateway accepts reasoning policy.
const ( // ReasoningUnsupported declares that the model has no reasoning controls. ReasoningUnsupported ReasoningSupport = "unsupported" // ReasoningSupported declares that ReasoningCapability is authoritative. ReasoningSupported ReasoningSupport = "supported" )
type RenderedContentAttribution ¶ added in v7.47.0
type RenderedContentAttribution struct {
Path string
Category string
Key string
Source string
Namespace string
Parts []ContentAttributionPart
}
RenderedContentAttribution assigns a frozen payload value to its actual origin. Parts apply to strings and cover their complete UTF-8 text. Tool identifiers are observation metadata and must not be added to the model-visible payload.
type RenderedRequest ¶ added in v7.16.0
type RenderedRequest struct {
// Attribution refers only to decoded values in Payload using JSON Pointer paths.
Attribution []RenderedContentAttribution
Provider string
Model string
Format RequestFormat
Payload []byte
}
RenderedRequest is the immutable JSON input of one provider request. The caller sends the same prepared input after estimation. Payload is not retained.
type Request ¶
type Request struct {
RunID identity.RunID `json:"run_id"`
ThreadID identity.ThreadID `json:"thread_id,omitempty"`
TurnID identity.TurnID `json:"turn_id,omitempty"`
TraceID identity.TraceID `json:"trace_id,omitempty"`
PromptScopeID identity.PromptScopeID `json:"prompt_scope_id"`
LogicalRequestID identity.LogicalRequestID `json:"logical_request_id,omitempty"`
AttemptID string `json:"attempt_id,omitempty"`
AttemptEpoch int `json:"attempt_epoch,omitempty"`
Step int `json:"step"`
Messages []Message `json:"messages"`
Tools []tools.ToolDefinition `json:"tools,omitempty"`
HostedTools []HostedToolDefinition `json:"hosted_tools,omitempty"`
MaxOutputTokens int64 `json:"max_output_tokens,omitempty"`
Reasoning config.ReasoningSelection `json:"reasoning,omitempty"`
PreviousState *State `json:"previous_state,omitempty"`
// ReusePolicy is always set by the runtime. Nil preserves gateway defaults
// for callers constructing requests outside the Engine.
ReusePolicy *RequestReusePolicy `json:"reuse_policy,omitempty"`
Labels Labels `json:"labels,omitempty"`
}
Request is one complete provider-visible model request.
func (Request) MarshalJSON ¶
MarshalJSON omits the optional logical request identity when a low-level provider request is constructed before runtime admission has assigned one. Non-empty identities still use identity.LogicalRequestID's validation.
type RequestFormat ¶ added in v7.16.0
type RequestFormat string
RequestFormat identifies the rendered input protocol, independently of model identity. An OpenAI-compatible transport does not imply an OpenAI tokenizer.
const ( RequestFormatOpenAIChat RequestFormat = "openai_chat" RequestFormatOpenAIResponses RequestFormat = "openai_responses" RequestFormatAnthropic RequestFormat = "anthropic_messages" // RequestFormatJSON is for opaque host transports. Payload must contain only // complete model input, excluding routing, credentials and runtime metadata. // It uses the generic estimate method, without claiming server wire fidelity. RequestFormatJSON RequestFormat = "input_json" )
type RequestPreparer ¶
type RequestPreparer interface {
Prepare(context.Context, Request) (PreparedRequest, error)
}
RequestPreparer renders a complete provider request before context limits are applied.
type RequestReusePolicy ¶ added in v7.37.0
type RequestReusePolicy struct {
PromptCacheEnabled bool `json:"prompt_cache_enabled"`
PromptCacheNamespace string `json:"prompt_cache_namespace,omitempty"`
ProviderStateAllowed bool `json:"provider_state_allowed"`
PreferContinuation bool `json:"prefer_continuation"`
}
RequestReusePolicy is the Engine's effective application reuse decision. Gateways must not broaden it. Prompt caching and native provider state are independent: disabling cache hints alone does not discard native history.
func (RequestReusePolicy) Validate ¶ added in v7.37.0
func (policy RequestReusePolicy) Validate() error
Validate rejects inconsistent effective reuse decisions.
type RequestTimeoutDetails ¶ added in v7.42.0
type RequestTimeoutDetails = internalprovider.RequestTimeoutDetails
RequestTimeoutDetails records runtime-authored timing and attempt identity. Stage is first_output, output_idle, hosted_tool, or max_duration.
type RequestTimeoutError ¶ added in v7.42.0
type RequestTimeoutError = internalprovider.RequestTimeoutError
RequestTimeoutError reports a retryable request timeout. It matches ErrRequestTimeout and context.DeadlineExceeded, never user cancellation.
type RetryAdvice ¶ added in v7.38.0
type RetryAdvice struct {
Category RetryCategory `json:"category,omitempty"`
NotBefore time.Time `json:"not_before,omitempty"`
Forbidden bool `json:"forbidden,omitempty"`
}
RetryAdvice carries response-time facts, including an absolute server deadline.
func HTTPRetryAdvice ¶ added in v7.38.0
func HTTPRetryAdvice(status int, code string, headers http.Header, receivedAt time.Time) RetryAdvice
HTTPRetryAdvice classifies exact protocol codes and parses Retry-After headers. receivedAt must be the time the response was received, not a later inspection.
type RetryAdviser ¶ added in v7.38.0
type RetryAdviser interface{ ProviderRetryAdvice() RetryAdvice }
RetryAdviser is an optional provider-error contract. Unknown errors are not retried.
type RetryCategory ¶ added in v7.38.0
type RetryCategory string
RetryCategory is a structured protocol or transport failure classification.
type Source ¶
type Source struct {
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
StartIndex *int `json:"start_index,omitempty"`
EndIndex *int `json:"end_index,omitempty"`
}
Source is one provider citation. Positions, when both are present, are end-exclusive Unicode code-point indices in the complete response text. Hosts must use exact ranges rather than infer links from provider marker IDs.
type State ¶
type State struct {
ReusePolicy StateReusePolicy `json:"reuse_policy,omitempty"`
Kind string `json:"kind,omitempty"`
ID string `json:"id,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}
State is opaque provider continuation state persisted by Floret. ReusePolicy never bypasses model/account identity, canonical lineage, or secret fences.
type StateReusePolicy ¶ added in v7.34.0
type StateReusePolicy string
StateReusePolicy describes which request changes preserve opaque state.
const ( // StateReuseExactSurface requires an unchanged provider surface. // The zero value preserves the default continuation behavior. StateReuseExactSurface StateReusePolicy = "" // StateReuseCanonicalHistory allows a provider to replay native history // across surface changes after validating its canonical message prefix. StateReuseCanonicalHistory StateReusePolicy = "canonical_history" )
type TokenEstimate ¶
type TokenEstimate struct {
Breakdown config.ContextBreakdown `json:"breakdown,omitzero"`
// AttachmentTokens is the estimated media/file subset already included in MessageTokens.
AttachmentTokens int64 `json:"attachment_tokens,omitempty"`
PrefixTokens int64 `json:"prefix_tokens,omitempty"`
MessageTokens int64 `json:"message_tokens,omitempty"`
ToolDefinitionTokens int64 `json:"tool_definition_tokens,omitempty"`
EstimatedInputTokens int64 `json:"estimated_input_tokens,omitempty"`
Source string `json:"source,omitempty"`
Method string `json:"method,omitempty"`
Confidence string `json:"confidence,omitempty"`
Coverage string `json:"coverage,omitempty"`
}
TokenEstimate describes the size of a complete rendered request.
func EstimateRenderedRequest ¶ added in v7.16.0
func EstimateRenderedRequest(request RenderedRequest) (TokenEstimate, error)
EstimateRenderedRequest counts model input with a supported official vocabulary or an explicitly identified proxy estimate. Native usage remains authoritative. No network, resource resolution, or provider call occurs. Image transport data is budgeted separately; opaque files retain a conservative transport-byte budget.
type ToolCallStream ¶
ToolCallStream identifies one tool call while its arguments stream.
type ToolResult ¶
type ToolResult struct {
CallID string `json:"call_id"`
ToolName string `json:"tool_name"`
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
}
ToolResult is one provider-visible local tool outcome.
type Usage ¶
type Usage struct {
// OutputIncludesReasoning means ReasoningTokens is a subset of OutputTokens.
OutputIncludesReasoning bool `json:"output_includes_reasoning,omitempty"`
// TotalTokensReported distinguishes an explicit native zero from an absent total.
TotalTokensReported bool `json:"total_tokens_reported,omitempty"`
InputTokens int64 `json:"input_tokens,omitempty"`
OutputTokens int64 `json:"output_tokens,omitempty"`
ReasoningTokens int64 `json:"reasoning_tokens,omitempty"`
CacheReadTokens int64 `json:"cache_read_tokens,omitempty"`
CacheWriteTokens int64 `json:"cache_write_tokens,omitempty"`
TotalTokens int64 `json:"total_tokens,omitempty"`
CostUSD float64 `json:"cost_usd,omitempty"`
Source string `json:"source,omitempty"`
Available bool `json:"available,omitempty"`
WindowInputTokens int64 `json:"window_input_tokens,omitempty"`
}
Usage is normalized provider token and cost usage.
func (Usage) Normalized ¶ added in v7.55.0
Normalized derives missing totals using the declared protocol relationship.