model

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 65 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package model captures provider requests and owns per-attempt model transport.

Foundry routing follows Goose 14741e9a. Apache-2.0; see LICENSE.goose.

Context discovery policy derived from Goose 14741e9a providers/openai.rs (Apache-2.0). See LICENSE.goose.

Request parameter policy is derived from Goose 14741e9a and rig-core 0.46.0. Apache-2.0; see LICENSE.goose and LICENSE.rig.

Chat schema adaptation derives from Goose 14741e9a through the reviewed Sailry adapter. Apache-2.0; see LICENSE.goose.

Request layouts derive from rig-core 0.46.0 and the reviewed Sailry wire adapter. MIT and Apache-2.0; see LICENSE.rig.

Inline thinking filter derived from Goose 14741e9a. Apache-2.0; see LICENSE.goose.

Index

Constants

View Source
const (
	MaxMediaImageBytes  = 64 << 20
	MaxMediaVideoBytes  = 512 << 20
	MaxMediaSpeechBytes = 8 << 20
	// MaxSpeechCharacters is the input bound of the speech endpoint.
	MaxSpeechCharacters = 4096
	// MediaVideoPoll is the production interval between video job reads.
	MediaVideoPoll = 5 * time.Second
)
View Source
const MainRetries = 9

MainRetries bounds resends of one main or summary request. Both also share the request's cumulative wait budget, regardless of the transient cause.

View Source
const (
	// MaxToolMediaBytes bounds one media item a tool result sends to a model.
	// It is the file-image bound and the per-image limit of the strictest API.
	MaxToolMediaBytes = 5 << 20
)
View Source
const UsageMetadataKey = "sailry.usage"

Variables

This section is empty.

Functions

func Answered

func Answered(records []canonical.Record) []canonical.Record

Answered applies the source request repair to the records a request carries: a tool result is kept only after its unanswered call, and a call that never received a result is removed. A turn that ended before recording a result therefore cannot make every later request invalid.

func ApplyPluginMetadata

func ApplyPluginMetadata(block *canonical.Block, part fantasy.StreamPart) error

func ApplyStreamMetadata

func ApplyStreamMetadata(block *canonical.Block, part fantasy.StreamPart) error

ApplyStreamMetadata is the provider-to-canonical carrier boundary. The engine owns text accumulation and slot identity; transport owns provider signatures.

func BuildCall

func BuildCall(binding Binding, request Request) (fantasy.Call, error)

func BuildPluginCall

func BuildPluginCall(binding Binding, request Request) (fantasy.Call, error)

func BuildProjectedCall added in v0.2.3

func BuildProjectedCall(binding Binding, request Request) (fantasy.Call, error)

BuildProjectedCall consumes request records already filtered by output.Cache.Project. The engine may subsequently materialize attachments and rename tool calls.

func ContextLimit

func ContextLimit(binding Binding) uint32

ContextLimit returns the context window of the bound model: the size its provider lists, else the size its server reported when the model was created, else the bundled catalog's size, else 128000. It performs no I/O.

func DiscoverACP

func DiscoverACP(ctx context.Context, binding Binding, capture ACPCapture) (protocol.ConversationDiscoveryCatalog, error)

DiscoverACP lists the models the agent offers a new session. No prompt is sent. Variants the package declares as effort levels fold into one model; nothing is listed that the agent did not report.

func DiscoverPlugin

func DiscoverPlugin(ctx context.Context, binding Binding, capture PluginCapture) (protocol.ConversationDiscoveryCatalog, error)

func Fault

func Fault(err error) *protocol.Fault

func New

func New(ctx context.Context, binding Binding) (fantasy.LanguageModel, error)

func NewACP

func NewACP(binding Binding, capture ACPCapture) (fantasy.LanguageModel, error)

func NewPlugin

func NewPlugin(_ context.Context, binding Binding, capture PluginCapture) (fantasy.LanguageModel, error)

func OutputLimit

func OutputLimit(binding Binding, summary bool) int64

OutputLimit is the model's listed output limit, 0 when it lists none. A summary request asks for twice its handoff cap (compact.Output), which is 8,000 tokens for windows from 32,000 through 200,000, bounded by the model's limit. A model that lists none uses at most 8,000, still within the window's summary budget.

func PartIndex

func PartIndex(part fantasy.StreamPart) (uint64, bool)

func PartUsage

func PartUsage(part fantasy.StreamPart) canonical.Usage

func PluginBound

func PluginBound(provider protocol.ConversationProvider) bool

func PluginOutput

func PluginOutput(part fantasy.StreamPart) bool

func PrepareNativeSearch

func PrepareNativeSearch(ctx context.Context, binding Binding, body map[string]any) (*http.Request, error)

PrepareNativeSearch shares the captured model's authorization and declared request policies. Native search owns its input and tool fields.

func ReadsImages

func ReadsImages(binding Binding) bool

ReadsImages reports whether the bound model takes image input: its listed capability, or the provider's default for a model the provider does not list, bounded by the adapter's declared input capabilities.

func ReplayPrefix

func ReplayPrefix(call fantasy.Call) string

ReplayPrefix identifies the projected request that produced the next reply.

func Run

func Run(ctx context.Context, languageModel fantasy.LanguageModel, call fantasy.Call, purpose Purpose, timer clock.Clock, observe func(Attempt) error, yield func(fantasy.StreamPart) bool, reset func()) error

Run uses reset to discard provisional output before replaying an interrupted attempt. Without it, main output that escaped to the consumer cannot be retried safely.

func Scope

func Scope(binding Binding) canonical.ModelSource

func SendsToolMedia

func SendsToolMedia(binding Binding, mime string, size uint64) bool

SendsToolMedia reports whether a request to the bound model carries a tool media item of this type and size.

func SetToolSchemas

func SetToolSchemas(call *fantasy.Call, schemas map[string]json.RawMessage)

SetToolSchemas retains declaration order across Fantasy's map-only schema boundary.

func StreamSources

func StreamSources(part fantasy.StreamPart) (canonical.Sources, bool)

StreamSources returns an independent provider source snapshot. Citation offsets remain provider character offsets; Store validates presentation ranges.

func VisibleRecords

func VisibleRecords(records []canonical.Record) []canonical.Record

VisibleRecords selects what a request carries without changing its messages: the latest summary followed by agent-visible records after its boundary. It also accepts an already projected record list.

Types

type ACPCapture

type ACPCapture struct {
	Adapter protocol.PluginModelAdapterDeclaration
	Program protocol.PluginProgramDeclaration
	// Owner is the package; Dir is the program's directory in its data.
	Owner, Dir, Version string
	Host                []string
	Pool                *program.Pool
	// contains filtered or unexported fields
}

ACPCapture is what the Node captured for one request to an agent program.

type Attempt

type Attempt struct {
	RequestID      string
	RequestStarted time.Time
	Index          uint64
	Started        time.Time
	Finished       time.Time
	FirstToken     *time.Time
	Usage          canonical.Usage
	Failure        *Failure
	// RetryDelay is the wait before the next attempt; nil on the last attempt.
	RetryDelay        *time.Duration
	Status            *uint16
	ResponseUs        *uint64
	RequestBytes      *uint64
	DispatchUs        *uint64
	RequestSentUs     *uint64
	Categories        []protocol.ConversationObservationCategory
	CompleteContext   bool
	ReasoningStreamed bool
}

type Binding

type Binding struct {
	Provider protocol.ConversationProvider
	Config   protocol.SessionConfig
	Secret   *protocol.Secret
	Session  protocol.SessionID
}

func Capture

func Capture(provider protocol.ConversationProvider, config protocol.SessionConfig, secret *protocol.Secret, session protocol.SessionID) (Binding, error)

Capture retains independent copies of the immutable admitted configuration.

func Summary

func Summary(binding Binding) Binding

type Failure

type Failure struct {
	Kind    FailureKind
	Message string

	// Exhausted marks only Run's terminal recovery outcome. Kind still names
	// the provider failure, including when a summary records why it failed.
	Exhausted bool
	// WaitExhausted distinguishes the cumulative wait budget from the attempt limit.
	WaitExhausted bool
	// contains filtered or unexported fields
}

func Classify

func Classify(err error, secrets ...protocol.Secret) *Failure

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) Retryable

func (f *Failure) Retryable() bool

type FailureKind

type FailureKind string
const (
	NotConfigured   FailureKind = "not_configured"
	Authentication  FailureKind = "authentication"
	ContextOverflow FailureKind = "context_overflow"
	RateLimited     FailureKind = "rate_limited"
	Quota           FailureKind = "quota"
	Network         FailureKind = "network"
	Unavailable     FailureKind = "unavailable"
	InvalidRequest  FailureKind = "invalid_request"
	InvalidResponse FailureKind = "invalid_response"
	Unsupported     FailureKind = "unsupported"
	Cancelled       FailureKind = "cancelled"
	Other           FailureKind = "other"
)

type MediaChannel

type MediaChannel string

MediaChannel names the provider endpoint that serves one media kind.

const (
	// MediaChat sends an image part through the model's normal chat request.
	MediaChat MediaChannel = "chat"
	// MediaImages is the OpenAI-compatible POST /images/generations endpoint.
	MediaImages MediaChannel = "images"
	// MediaImageTool is the Responses API hosted image generation tool.
	MediaImageTool MediaChannel = "image_tool"
	// MediaGemini is Gemini's native generateContent image output.
	MediaGemini MediaChannel = "gemini"
	// MediaVideos is the OpenAI-compatible POST /videos job endpoint.
	MediaVideos MediaChannel = "videos"
	// MediaSpeech is the OpenAI-compatible POST /audio/speech endpoint.
	MediaSpeech MediaChannel = "speech"
)

func MediaChannelFor

MediaChannelFor selects the channel driver for one media kind from the model's capability tags and its provider's API and authentication. A model without the tag, or on a channel without a driver, has no route.

type MediaOutput

type MediaOutput struct {
	Data      []byte
	MediaType string
	Usage     canonical.Usage
	// Job identifies an accepted provider job that outlives a local stop.
	Job string
	// Ended reports that the provider ended Job without a video, so nothing
	// remains to fetch.
	Ended bool
}

MediaOutput is one generated asset and the usage its provider reported.

func GenerateImage

func GenerateImage(ctx context.Context, binding Binding, channel MediaChannel, prompt string) (MediaOutput, error)

GenerateImage runs one image generation on the channel selected for the bound model and returns PNG bytes.

func GenerateVideo

func GenerateVideo(ctx context.Context, binding Binding, prompt string, poll time.Duration) (MediaOutput, error)

GenerateVideo submits one OpenAI-compatible video job, waits for it and downloads the MP4. Stopping locally does not cancel an accepted job.

func ResumeVideo

func ResumeVideo(ctx context.Context, binding Binding, job string, poll time.Duration) (MediaOutput, error)

ResumeVideo waits for a job an earlier call submitted and downloads its MP4. It never submits a job, so a prompt is not paid for twice.

func SynthesizeSpeech

func SynthesizeSpeech(ctx context.Context, binding Binding, text, voice string) (MediaOutput, error)

SynthesizeSpeech reads text aloud through the OpenAI-compatible speech endpoint and returns MP3 audio.

type PluginCapture

type PluginCapture struct {
	User        string
	Declaration protocol.PluginModelAdapterDeclaration
	Bundle      plugins.ScriptBundle
	Memory      *plugins.MemoryTracker
	Headers     http.Header
	Access      *protocol.Secret
	Key         *protocol.Secret
	Secrets     []protocol.Secret
	Client      *http.Client
	// Settings are the package's current public setting values, which its
	// prepare and discovery exports receive.
	Settings map[string]json.RawMessage
}

type Purpose

type Purpose string
const (
	Main           Purpose = "main"
	SummaryPurpose Purpose = "summary"
)

type Request

type Request struct {
	System          string
	Records         []canonical.Record
	Tools           []Tool
	ToolSchemas     map[string]json.RawMessage
	MaxOutputTokens *int64
	Temperature     *float64
	Headers         map[string]string
	Assets          map[string][]byte
	// Delegated marks a request of a delegated session, which an account
	// service counts as the agent's own.
	Delegated bool
	// contains filtered or unexported fields
}

type Tool

type Tool = fantasy.FunctionTool

type UsageMetadata

type UsageMetadata struct {
	Reported        bool            `json:"reported"`
	Precise         bool            `json:"precise"`
	Input           *int64          `json:"input"`
	Output          *int64          `json:"output"`
	Total           *int64          `json:"total"`
	Reasoning       *int64          `json:"reasoning"`
	CacheRead       *int64          `json:"cache_read"`
	CacheWrite      *int64          `json:"cache_write"`
	UncachedInput   *int64          `json:"uncached_input,omitempty"`
	CandidateOutput *int64          `json:"candidate_output,omitempty"`
	ToolInput       *int64          `json:"tool_input,omitempty"`
	Raw             json.RawMessage `json:"raw,omitempty"`
}

UsageMetadata preserves reported field presence for one attempt. Scalar Fantasy usage is a convenience projection; these pointers are authoritative.

func (UsageMetadata) MarshalJSON

func (metadata UsageMetadata) MarshalJSON() ([]byte, error)

func (*UsageMetadata) Options

func (*UsageMetadata) Options()

func (*UsageMetadata) UnmarshalJSON

func (metadata *UsageMetadata) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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