agents

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 8 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 agents owns saved Agents: reusable configuration a tenant keeps independently of Sessions, with the optional model provider bundle that its x_agents_core.model_provider describes. It validates and merges saved configuration; Session snapshots and execution belong elsewhere.

Index

Constants

View Source
const MaxConfigurationBytes = 512 * 1024

MaxConfigurationBytes bounds a saved configuration and an update's patch.

View Source
const MaxPageSize = 100

MaxPageSize bounds one page of ListAgents.

Variables

View Source
var (
	// ErrNotFound reports an Agent the tenant does not have, including an
	// identifier that cannot name one.
	ErrNotFound = errors.New("agent not found")
	// ErrInvalidInput reports configuration, metadata or a request limit that
	// the saved Agent rules reject.
	ErrInvalidInput = errors.New("invalid agent input")
)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID            string
	TenantID      string
	Metadata      map[string]string
	Configuration json.RawMessage
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

Agent is saved configuration owned by a tenant. It has no Harness binding or live execution state; Session snapshots are separate objects.

type CreateCommand

type CreateCommand struct {
	TenantID      string
	Metadata      map[string]string
	Configuration json.RawMessage
	ModelProvider *v1.ModelProviderInput
}

CreateCommand saves a new Agent. Configuration is the resolved saved configuration; ModelProvider is the bundle its x_agents_core.model_provider describes. Each call creates a new Agent.

type DeleteCommand

type DeleteCommand struct {
	TenantID string
	AgentID  string
}

DeleteCommand removes an Agent. Session snapshots taken from it stay.

type ListQuery

type ListQuery struct {
	TenantID  string
	After     string
	Limit     int
	Ascending bool
}

ListQuery selects one page of a tenant's Agents in creation order. After is the last Agent of the previous page; an After that names no Agent of the tenant is ErrNotFound.

func (ListQuery) Validate

func (q ListQuery) Validate() error

Validate checks the page size.

type ModelProviderChange

type ModelProviderChange struct {
	Provider *v1.ModelProviderInput
}

ModelProviderChange replaces an Agent's saved model provider bundle. A nil Provider removes it.

type NewAgent

type NewAgent struct {
	TenantID string
	// Metadata is the encoded metadata object.
	Metadata      json.RawMessage
	Configuration json.RawMessage
	// ModelProvider is sealed beside the Agent; nil saves none.
	ModelProvider *v1.ModelProviderInput
}

NewAgent is a validated Agent to create.

type Page

type Page struct {
	Agents     []Agent
	NextCursor string
}

Page is one page of Agents. NextCursor is empty on the last page.

type Reader

type Reader interface {
	GetAgent(ctx context.Context, tenantID, agentID string) (Agent, error)
	ListAgents(context.Context, ListQuery) (Page, error)
	// GetAgentWithModelProvider reads the Agent and its opened model provider
	// bundle from one snapshot. The bundle is nil when the Agent has none.
	// Opening one without a credential key is credentialcrypto.ErrUnavailable;
	// a bundle that fails to open is an internal error.
	GetAgentWithModelProvider(ctx context.Context, tenantID, agentID string) (Agent, *v1.ModelProviderInput, error)
}

Reader reads saved Agents of one tenant. An agent ID or list cursor that cannot name an Agent is a missing Agent: ErrNotFound.

type Revision

type Revision struct {
	// Metadata is the encoded metadata object.
	Metadata      json.RawMessage
	Configuration json.RawMessage
	// ModelProvider nil keeps the saved bundle.
	ModelProvider *ModelProviderChange
}

Revision is the complete next state of an Agent.

type Service

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

Service runs the Agent write use cases. Reads go through Reader.

func NewService

func NewService(storage Storage) (*Service, error)

func (*Service) Create

func (s *Service) Create(ctx context.Context, cmd CreateCommand) (Agent, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, cmd DeleteCommand) (string, error)

Delete returns the deleted Agent's ID.

func (*Service) Update

func (s *Service) Update(ctx context.Context, cmd UpdateCommand) (Agent, error)

Update validates the supplied fields before it looks the Agent up, so an invalid request is rejected the same way for a missing Agent. An update that supplies nothing still advances UpdatedAt.

type Storage

type Storage interface {
	// CreateAgent assigns the Agent's ID and saves it with its sealed model
	// provider bundle. Sealing without a credential key is
	// credentialcrypto.ErrUnavailable.
	CreateAgent(context.Context, NewAgent) (Agent, error)
	// WithAgentUpdate locks the tenant's Agent and runs update; the revision
	// it applies commits only when update returns nil.
	WithAgentUpdate(ctx context.Context, tenantID, agentID string, update func(UpdateTx) error) error
	// DeleteAgent removes the Agent and its model provider bundle and returns
	// the deleted ID.
	DeleteAgent(ctx context.Context, tenantID, agentID string) (string, error)
}

Storage persists Agent writes. Each method runs in one transaction that also records the write audit. An agent ID that cannot name an Agent is a missing Agent.

type UpdateCommand

type UpdateCommand struct {
	TenantID      string
	AgentID       string
	Configuration json.RawMessage
	Metadata      *map[string]string
	ModelProvider *ModelProviderChange
}

UpdateCommand changes the supplied fields of an Agent. Configuration holds the supplied top-level fields only (see mergeConfiguration). Metadata nil keeps the saved map; a supplied map replaces it. ModelProvider nil keeps the saved bundle.

type UpdateTx

type UpdateTx interface {
	// LoadAgent returns the locked Agent, or ErrNotFound.
	LoadAgent() (Agent, error)
	// ApplyRevision stores the revision and returns the updated Agent.
	ApplyRevision(Revision) (Agent, error)
}

UpdateTx is one locked Agent inside WithAgentUpdate.

Jump to

Keyboard shortcuts

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