Help us shape the future of Go! Take the 2026 Go Developer Survey

delegation

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package delegation runs an explicit bounded local-first task policy. It can escalate once after a known complete durable answer fails declared checks; it never retries uncertain calls, intercepts an agent session, or picks models.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQualityFailed = errors.New("delegated task did not satisfy every declared quality check")
	ErrStopped       = errors.New("delegated task stopped without escalating; inspect its recorded outcome")
)

Functions

func NewOutcomeRunID added in v0.9.0

func NewOutcomeRunID() (string, error)

func OutcomeRecord added in v0.9.0

func OutcomeRecord(request Request, result Result, runID string) outcomes.Run

func RecordOutcome added in v0.9.0

func RecordOutcome(ctx context.Context, broker inference.Broker, request Request, result *Result, runID string)

func Validate

func Validate(request Request, allowPaid bool) error

Validate resolves all tier plans and checks before any factory/provider call. A configured hosted tier is rejected unless this caller explicitly opts in, even when the local tier could produce a passing answer.

Types

type Attempt

type Attempt struct {
	TierID        string                   `json:"tier_id"`
	Result        inference.Result         `json:"result"` // Response.Text is always stripped.
	Checks        []evaluation.CheckResult `json:"checks"`
	QualityPassed bool                     `json:"quality_passed"`
	OutputSHA256  string                   `json:"output_sha256,omitempty"`
	ErrorCategory string                   `json:"error_category,omitempty"`
}

type OutcomeTracking added in v0.4.0

type OutcomeTracking struct {
	Status  string            `json:"status"` // recorded or failed
	RunID   string            `json:"run_id"`
	Task    outcomes.Task     `json:"task"`
	Receipt *outcomes.Receipt `json:"receipt,omitempty"`
	Record  *outcomes.Run     `json:"record,omitempty"`
}

OutcomeTracking is separate from answer quality. Registration failure never changes a checked answer or authorizes another model call. Record is returned on failure so the exact metadata can be reconciled without regenerating text.

type Policy

type Policy struct {
	Local      Tier  `json:"local"`
	Escalation *Tier `json:"escalation,omitempty"`
}

type Request

type Request struct {
	TrackOutcome bool               `json:"track_outcome,omitempty"` // Opt-in shared accounting; excluded from generation identity.
	Spec         inference.Spec     `json:"spec"`
	Policy       Policy             `json:"policy"`
	Checks       []evaluation.Check `json:"checks"`
}

Request.Spec supplies approved task, revision, prompt and context only. Every model and resource setting comes from the explicit tier templates.

func Load

func Load(reader io.Reader) (Request, error)

Load reads at most 1MiB of request JSON. Authorization is deliberately not a JSON field: only the caller can enable paid escalation on Router.AllowPaid.

type Result

type Result struct {
	OutcomeTracking *OutcomeTracking    `json:"outcome_tracking,omitempty"`
	RequestSHA256   string              `json:"request_sha256"`
	Attempts        []Attempt           `json:"attempts"`
	SelectedTier    string              `json:"selected_tier,omitempty"`
	Response        *inference.Response `json:"response,omitempty"` // Only a passing answer is exposed.
	Status          string              `json:"status"`             // completed, quality_failed, stopped
}

type Router

type Router struct {
	Factory   RunnerFactory
	AllowPaid bool // Caller permission, never read from request JSON or environment.
}

func (Router) Run

func (router Router) Run(ctx context.Context, request Request) (Result, error)

Run executes at most two explicitly configured tiers. A second tier is reached only after error-free, known complete and durable output fails the declared checks. Every provider/accounting error stops the whole policy. Repeated calls retain the same request/tier identity and the Runner's reuse behavior; the Router never changes a revision to force another generation.

type Runner

type Runner interface {
	Run(context.Context, inference.Spec) (inference.Result, error)
}

type RunnerFactory

type RunnerFactory func(Tier) (Runner, error)

type Tier

type Tier struct {
	ID   string         `json:"id"`
	Spec inference.Spec `json:"spec"`
}

Tier.Spec must omit task, revision, instructions, input and context. Hosted escalation requires explicit prices and positive per-call and daily budgets.

Jump to

Keyboard shortcuts

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