agentproduct

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 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 agentproduct defines the provider-neutral runtime product returned by capability-aware agent factories.

A Product owns its Agent and any resources reachable through that Agent. Callers must close the Product, not Product.Agent. Closing the Agent directly bypasses control admission and violates the ownership contract.

Index

Constants

View Source
const (
	// MaxModels is the largest model list accepted from a control adapter.
	MaxModels = 128
	// MaxModelIDBytes bounds public model identifiers.
	MaxModelIDBytes = 256
	// MaxModelLabelBytes bounds public model labels.
	MaxModelLabelBytes = 512
	// MaxControlRevisionBytes bounds opaque provider control revisions.
	MaxControlRevisionBytes = 512
	// MaxContextMessages bounds one portable context package.
	MaxContextMessages = 256
	// MaxContextMessageBytes bounds one portable context message.
	MaxContextMessageBytes = 32 << 10
	// MaxContextBytes bounds all text in one portable context package.
	MaxContextBytes = 256 << 10
)

Variables

View Source
var ErrCloseFailed = errors.New("agent product close failed")

ErrCloseFailed reports that an owned resource failed to close. Product does not expose the underlying provider error because it may contain protected configuration or remote details.

View Source
var ErrInvalidContextPackage = errors.New("invalid portable context package")

ErrInvalidContextPackage reports non-portable or excessive context input.

Functions

This section is empty.

Types

type ContextChange

type ContextChange struct {
	Status ContextChangeStatus
	Reason Reason
}

ContextChange reports a provider-native import without an assistant turn.

func UnsupportedFastForward

func UnsupportedFastForward() ContextChange

UnsupportedFastForward returns the default safe result for providers that have no non-turn context import operation.

type ContextChangeStatus

type ContextChangeStatus string

ContextChangeStatus is the result of a portable context import.

const (
	// ContextReady means an import is prepared but is not yet committed.
	ContextReady ContextChangeStatus = "ready"
	// ContextSucceeded means the provider conclusively imported the package.
	ContextSucceeded ContextChangeStatus = "succeeded"
	// ContextUnsupported means no non-turn context import exists.
	ContextUnsupported ContextChangeStatus = "unsupported"
	// ContextIncompatible means the package cannot be imported safely.
	ContextIncompatible ContextChangeStatus = "incompatible"
	// ContextBusy means active provider work prevents safe import.
	ContextBusy ContextChangeStatus = "busy"
	// ContextFailed means failure was proven before provider dispatch.
	ContextFailed ContextChangeStatus = "failed"
	// ContextAmbiguous means import may have occurred and needs reconciliation.
	ContextAmbiguous ContextChangeStatus = "ambiguous"
	// ContextClosed means the owning Product is closed.
	ContextClosed ContextChangeStatus = "closed"
)

type ContextMessage

type ContextMessage struct {
	Role ContextRole
	Text string
}

ContextMessage is one visible user or assistant message.

type ContextPackage

type ContextPackage struct {
	// contains filtered or unexported fields
}

ContextPackage contains only validated visible text. It cannot represent system prompts, tool traffic, attachments, or provider-private state.

func NewContextPackage

func NewContextPackage(messages []ContextMessage) (ContextPackage, error)

NewContextPackage validates and copies portable visible context.

func (ContextPackage) ByteLen

func (p ContextPackage) ByteLen() int

ByteLen returns the total UTF-8 byte length of message text.

func (ContextPackage) Messages

func (p ContextPackage) Messages() []ContextMessage

Messages returns a copy of the portable messages.

func (ContextPackage) Valid

func (p ContextPackage) Valid() bool

Valid reports whether the package was constructed with NewContextPackage.

type ContextRole

type ContextRole string

ContextRole is an allowlisted portable visible-message role.

const (
	// ContextRoleUser identifies visible user-authored text.
	ContextRoleUser ContextRole = "user"
	// ContextRoleAssistant identifies visible assistant-authored text.
	ContextRoleAssistant ContextRole = "assistant"
)

type ControlStatus

type ControlStatus string

ControlStatus describes whether exact-session control is available.

const (
	// ControlReady means authoritative exact-session control is available.
	ControlReady ControlStatus = "ready"
	// ControlUnsupported means the exact session has no control support.
	ControlUnsupported ControlStatus = "unsupported"
	// ControlBusy means active provider work prevents safe inspection.
	ControlBusy ControlStatus = "busy"
	// ControlFailed means inspection failed without external mutation.
	ControlFailed ControlStatus = "failed"
	// ControlClosed means the owning Product is closed.
	ControlClosed ControlStatus = "closed"
)

type ModelChange

type ModelChange struct {
	Status         ModelChangeStatus
	EffectiveModel string
	Replacement    *Product
	Reason         Reason
}

ModelChange reports a model mutation. Replacement is populated only when Status is ModelReplacement; its caller becomes the candidate owner.

type ModelChangeStatus

type ModelChangeStatus string

ModelChangeStatus is the terminal or uncertain result of a model change.

const (
	// ModelApplied means the existing provider session changed conclusively.
	ModelApplied ModelChangeStatus = "applied"
	// ModelReplacement returns an independently owned candidate Product.
	ModelReplacement ModelChangeStatus = "replacement"
	// ModelChangeUnsupported means the exact session has no model control.
	ModelChangeUnsupported ModelChangeStatus = "unsupported"
	// ModelChangeIncompatible means the requested value cannot be used safely.
	ModelChangeIncompatible ModelChangeStatus = "incompatible"
	// ModelRejected means the provider authoritatively rejected the request.
	ModelRejected ModelChangeStatus = "rejected"
	// ModelChangeBusy means active provider work prevents safe mutation.
	ModelChangeBusy ModelChangeStatus = "busy"
	// ModelChangeFailed means failure was proven before provider dispatch.
	ModelChangeFailed ModelChangeStatus = "failed"
	// ModelAmbiguous means mutation may have occurred and must be reconciled.
	ModelAmbiguous ModelChangeStatus = "ambiguous"
	// ModelChangeClosed means the owning Product is closed.
	ModelChangeClosed ModelChangeStatus = "closed"
)

type ModelDescriptor

type ModelDescriptor struct {
	ID    string
	Label string
}

ModelDescriptor is bounded public model metadata.

type ModelValidation

type ModelValidation struct {
	Status ModelValidationStatus
	Model  string
	Reason Reason
}

ModelValidation reports whether a model change can be attempted. Validation must not mutate provider state or construct a replacement Product.

type ModelValidationStatus

type ModelValidationStatus string

ModelValidationStatus is a non-mutating validation outcome.

const (
	// ModelSupported means validation proved that the model can be requested.
	ModelSupported ModelValidationStatus = "supported"
	// ModelUnsupported means the exact session has no model control.
	ModelUnsupported ModelValidationStatus = "unsupported"
	// ModelIncompatible means the value cannot be used by this exact session.
	ModelIncompatible ModelValidationStatus = "incompatible"
	// ModelBusy means active provider work prevents safe validation.
	ModelBusy ModelValidationStatus = "busy"
	// ModelFailed means local validation failed without external mutation.
	ModelFailed ModelValidationStatus = "failed"
	// ModelClosed means the owning Product is closed.
	ModelClosed ModelValidationStatus = "closed"
)

type Product

type Product struct {
	Agent   agent.Agent
	Control SessionControl
	// contains filtered or unexported fields
}

Product owns one immutable executable Agent and its optional session control. Agent and Control are fixed at construction time by convention. Close is the sole ownership entrypoint; callers must not close Agent directly.

func New

func New(ag agent.Agent, control SessionControl) (*Product, error)

New constructs a Product and takes ownership of ag. When ag implements io.Closer, Product.Close closes it after control admission is fenced.

func (*Product) Close

func (p *Product) Close() error

Close fences new control calls, waits for admitted calls, and then releases Agent-owned resources exactly once. Cleanup failures return ErrCloseFailed; provider error details are intentionally not exposed.

type Reason

type Reason string

Reason is a bounded, provider-neutral diagnostic classification.

const (
	// ReasonNone means no additional diagnostic classification applies.
	ReasonNone Reason = ""
	// ReasonUnavailable classifies an absent provider operation.
	ReasonUnavailable Reason = "unavailable"
	// ReasonInvalidSession classifies an invalid session reference.
	ReasonInvalidSession Reason = "invalid_session"
	// ReasonBindingMismatch classifies a different product or native binding.
	ReasonBindingMismatch Reason = "binding_mismatch"
	// ReasonInvalidModel classifies an invalid public model value.
	ReasonInvalidModel Reason = "invalid_model"
	// ReasonInvalidContext classifies non-portable context input.
	ReasonInvalidContext Reason = "invalid_context"
	// ReasonActiveWork classifies a conflicting provider operation.
	ReasonActiveWork Reason = "active_work"
	// ReasonPreDispatch classifies a proven failure before provider dispatch.
	ReasonPreDispatch Reason = "pre_dispatch"
	// ReasonProviderReject classifies an authoritative provider rejection.
	ReasonProviderReject Reason = "provider_rejected"
	// ReasonUncertain classifies a result that requires reconciliation.
	ReasonUncertain Reason = "uncertain"
	// ReasonInvalidResult classifies unsafe output from a control adapter.
	ReasonInvalidResult Reason = "invalid_result"
	// ReasonClosed classifies an operation rejected by product lifecycle.
	ReasonClosed Reason = "closed"
)

type SessionControl

type SessionControl interface {
	Inspect(ctx context.Context, sess session.Session) SessionControlSnapshot
	ValidateModel(ctx context.Context, sess session.Session, model string) ModelValidation
	ChangeModel(ctx context.Context, sess session.Session, model string) ModelChange
	FastForward(ctx context.Context, sess session.Session, context ContextPackage) ContextChange
}

SessionControl is the single optional control-plane port for a Product. Presence does not imply support for a particular session or operation; Inspect is authoritative for the exact supplied session.

type SessionControlSnapshot

type SessionControlSnapshot struct {
	Status             ControlStatus
	Models             []ModelDescriptor
	CurrentModel       string
	ControlRevision    string
	FastForwardSupport bool
	Reason             Reason
}

SessionControlSnapshot describes control support for one exact session.

Jump to

Keyboard shortcuts

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