modelstage

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 13 Imported by: 1 module, 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 modelstage is the worker's side of every model stage: the dispatch-once protocol that each stage's handler runs. A stage keeps only the prompt it reads an item under, what that prompt quotes, and how the run's answer becomes the output.

A task's call is started once, under an idempotency key of its subject, the stage and the prompt's version. The subject is the task's item, or the prompt proposal that a prompt-proposal task drafts. The dispatch is stored on the output in the write that ends the worker's lease, and each later claim follows it until the run answers. So a waiting task holds no worker slot, and a lease that lapsed never pays for a second run. A run that failed is started again only once `tasks retry` queues its task, under a key that also names the failed dispatch, because a dispatch service may answer the old key with the failed run.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeepAgain = errors.New("the answer waits to be kept")

ErrKeepAgain marks a Keep error where the answer holds to its schema and a step after it failed, such as the scan of a suggestion. Where the run keeps a dispatch, the task follows that run again after its backoff, so the paid answer is kept without a second call. Where it keeps none, the output fails.

Functions

func Estimate

func Estimate(ctx context.Context, st *store.Store, stage string, items []store.Item,
	due func(r store.ItemRecords, open bool) bool,
) (int, *store.Tokens, error)

Estimate is how many of items a replay of stage would run on, as due says of each item's records and whether it holds an open task at stage. Its tokens are the median by kind of the stage's newest stored runs times that count, and nil where the stage holds no stored run.

func NewHandler

func NewHandler(port modelport.Port, stage Stage, settings Settings, log *slog.Logger) worker.Handler

NewHandler is the worker handler that runs stage's tasks through port under settings.

Types

type Settings

type Settings struct {
	Model  string
	Effort string
}

Settings are what a stage asks its run for.

type Stage

type Stage struct {
	// Name is the store's stage, and the capability of each of its tasks.
	Name string
	// Producer names the stage's outputs, whose version is the prompt's.
	Producer string
	// Prompt is the prompt that task's item is read under, which names the
	// output. An error fails the task with no output, as a lens that this
	// build holds no prompt for does.
	Prompt func(task worker.Task) (prompts.Prompt, error)
	// Data is what the prompt quotes of task's item. It is read only where a
	// call starts. An error marked modelport.ErrRefused fails the task, and
	// any other tries again after a backoff.
	Data func(ctx context.Context, task worker.Task) (any, error)
	// Keep fills out from the answer that a run gave to prompt on task, and
	// returns the answer's fields that the answered line logs, never outsider
	// text. An error fails the output, as an answer that breaks prompt's
	// schema does, and `tasks retry` starts a new run. An error that wraps
	// ErrKeepAgain leaves the output waiting on its dispatch instead.
	Keep func(ctx context.Context, task worker.Task, prompt prompts.Prompt, answer json.RawMessage, out *server.ReportOutput) (logged []any, err error)
}

Stage is one model stage as its handler runs it.

Jump to

Keyboard shortcuts

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