Versions in this module Expand all Collapse all v0 v0.1.1 Aug 6, 2026 Changes in this version + const DefaultLoopDetectThreshold + const DefaultLoopDetectWindow + const LegacyExecutableVersion + const RunSnapshotSchemaVersion + var ErrAgentConfigInvalid = errors.New("agent: invalid configuration") + var ErrCheckpointConflict = errors.New("agent: checkpoint conflict") + var ErrInvalidRunTransition = errors.New("agent: invalid run transition") + var ErrLoopDetected = errors.New("agent: tool call loop detected") + var ErrSessionNotFound = errors.New("agent: session not found") + var ErrToolExecutionUnknown = errors.New("agent: tool execution status unknown") + var ErrToolInputInvalid = errors.New("agent: invalid tool input") + var ErrToolNotAllowed = errors.New("agent: tool not allowed") + var ErrToolNotFound = errors.New("agent: tool not registered") + var ErrUnsupportedRunSnapshotSchema = errors.New("agent: unsupported run snapshot schema") + func CanonicalDigest(value any) (string, error) + func ContextBudgetExceeded(contextWindow, promptTokens int) bool + func DigestRunConfig(config ImmutableRunConfig) (string, error) + func DigestRunInput(input ImmutableRunInput) (string, error) + func DigestToolInput(input string) (string, error) + func MarshalRunSnapshot(snapshot RunSnapshot) ([]byte, error) + func NewModelError(kind ModelErrorKind, retryable bool, httpStatus int, retryAfter time.Duration, ...) error + func ToolExecutionKey(identity RunIdentity, stepNumber, ordinal int, call ToolCall) string + func ToolExecutionKeyFromContext(ctx context.Context) (string, bool) + func ValidateGenerateRequest(req *GenerateRequest) error + func ValidateGenerateRequestCapabilities(req *GenerateRequest, caps Capabilities) error + func ValidateMessage(m Message) error + func ValidateResponse(r *Response) error + func ValidateRunRequest(req RunRequest) error + func ValidateRunRequestCapabilities(req RunRequest, caps Capabilities) error + func ValidateRunTransition(from, to RunSnapshot) error + func WithToolExecutionKey(ctx context.Context, key string) context.Context + type Agent struct + func New(cfg Config, model Model, registry *Registry) (*Agent, error) + func (a *Agent) ContextWindow() int + func (a *Agent) Key() string + func (a *Agent) PrepareDurableRun(request RunRequest) (string, string, Checkpoint, error) + func (a *Agent) Run(ctx context.Context, request RunRequest) (result *RunResult, runErr error) + type ArtifactVersions struct + Definition string + Model string + Policy string + Prompt string + Tools string + type Capabilities struct + ImageInput bool + Media bool + Reasoning bool + StructuredOutput bool + ToolChoiceNamed bool + ToolChoiceNone bool + ToolChoiceRequired bool + Tools bool + UsageDetails bool + func (c Capabilities) Validate() error + type Checkpoint struct + CompletedSteps []StepResult + History []Message + NewMessages []Message + NextStep int + Outcome RunResult + PendingToolCalls []ToolCall + RepairCount int + Usage Usage + func (checkpoint Checkpoint) Clone() Checkpoint + type CheckpointStore interface + Acquire func(ctx context.Context, runKey, leaseOwner string, leaseUntil time.Time) (RunSnapshot, error) + Begin func(ctx context.Context, identity RunIdentity, inputDigest, configDigest string, ...) (RunSnapshot, error) + BeginTool func(ctx context.Context, guard MutationGuard, idempotencyKey string, ...) (RunSnapshot, ToolExecution, error) + CommitModelResponse func(ctx context.Context, guard MutationGuard, response Response, ...) (RunSnapshot, error) + CommitTool func(ctx context.Context, guard MutationGuard, execution ToolExecution, ...) (RunSnapshot, error) + Complete func(ctx context.Context, guard MutationGuard, checkpoint Checkpoint) (RunSnapshot, error) + Fail func(ctx context.Context, guard MutationGuard, checkpoint Checkpoint, ...) (RunSnapshot, error) + Load func(ctx context.Context, runKey string) (RunSnapshot, error) + ModelInflight func(ctx context.Context, guard MutationGuard, checkpoint Checkpoint) (RunSnapshot, error) + PrepareTools func(ctx context.Context, guard MutationGuard, tools []ToolExecution, ...) (RunSnapshot, error) + Suspend func(ctx context.Context, guard MutationGuard, checkpoint Checkpoint) (RunSnapshot, error) + type ChunkType string + const ChunkError + const ChunkFinish + const ChunkText + const ChunkToolCall + type Config struct + AllowedTools []string + ContextWindow int + Key string + LoopDetectThreshold int + LoopDetectWindow int + MaxSteps int + MaxTokens *int + ModelName string + StopConditions []StopCondition + Temperature *float64 + ToolChoice *ToolChoice + ToolRepairLimit int + TopP *float64 + type ContentPart struct + Image *ImageContent + Text string + ToolCall *ToolCall + ToolResult *ToolResult + Type PartType + type DurableCompletion struct + Checkpoint Checkpoint + Guard MutationGuard + type DurableFailure struct + Checkpoint Checkpoint + Failure RunFailure + Guard MutationGuard + type DurableRunConfig struct + AttemptAcquired func(RunIdentity, uint64) error + AutoComplete bool + CheckpointStore CheckpointStore + ConfigDigest string + DeferFailureFinalization bool + Identity RunIdentity + InputDigest string + LeaseDuration time.Duration + LeaseOwner string + ObservationEmitterFactory func(RunIdentity, uint64) *ObservationEmitter + PolicyVersion string + PromptVersion string + type DurableSuspension struct + Checkpoint Checkpoint + Guard MutationGuard + type ExecutableVersioner interface + ExecutableVersion func() string + type ExecutionSettings struct + LoopDetectThreshold int + LoopDetectWindow int + MaxSteps int + MaxTokens *int + StopConditions []StopCondition + Temperature *float64 + ToolChoice *ToolChoice + ToolRepairLimit int + TopP *float64 + type FinishReason string + const FinishError + const FinishLength + const FinishStop + const FinishToolCalls + type FuncTool struct + func MustNewTool[T any](name, description string, ...) *FuncTool[T] + func NewTool[T any](name, description string, ...) (*FuncTool[T], error) + func (t *FuncTool[T]) Definition() ToolDefinition + func (t *FuncTool[T]) ExecutableVersion() string + func (t *FuncTool[T]) Execute(ctx context.Context, invocation ToolInvocation) (ToolResult, error) + func (t *FuncTool[T]) ReplayPolicy() ReplayPolicy + type GenerateRequest struct + MaxTokens *int + Messages []Message + Model string + Temperature *float64 + ToolChoice *ToolChoice + Tools []ToolDefinition + TopP *float64 + type GenerationOptions struct + MaxTokens *int + Temperature *float64 + TopP *float64 + type Generator interface + Generate func(ctx context.Context, req *GenerateRequest) (*Response, error) + type ImageContent struct + Data []byte + Digest string + MediaType string + Ref string + SizeBytes int64 + type ImmutableRunConfig struct + AgentKey string + ContextWindow int + Generation GenerationOptions + LoopDetectThreshold int + LoopDetectWindow int + MaxSteps int + ModelName string + PolicyVersion string + PromptVersion string + ToolChoice *ToolChoice + ToolRepairLimit int + Tools []ToolDefinition + type ImmutableRunInput struct + Messages []Message + ToolChoice *ToolChoice + type LoopDetector struct + func NewLoopDetector(window, threshold int) *LoopDetector + func (d *LoopDetector) Detect(steps []StepResult) (sig string, count int, detected bool) + func (d *LoopDetector) Threshold() int + func (d *LoopDetector) Validate(maxSteps int) error + func (d *LoopDetector) Window() int + type MemoryStore struct + func NewMemoryStore() *MemoryStore + func (s *MemoryStore) AddUsage(_ context.Context, sessionID uint, usage Usage) error + func (s *MemoryStore) AppendMessages(_ context.Context, sessionID uint, messages ...Message) error + func (s *MemoryStore) CreateSession(_ context.Context, session Session) error + func (s *MemoryStore) GetSession(_ context.Context, sessionID uint) (Session, error) + func (s *MemoryStore) ListMessages(_ context.Context, sessionID uint) ([]Message, error) + func (s *MemoryStore) UpdateSessionStatus(_ context.Context, sessionID uint, status SessionStatus) error + type Message struct + FinishReason FinishReason + Parts []ContentPart + Role Role + func NewAssistantMessage(text string) Message + func NewSystemMessage(text string) Message + func NewToolMessage(results ...ToolResult) Message + func NewUserMessage(text string) Message + func (m Message) Text() string + func (m Message) ToolCalls() []ToolCall + func (m Message) ToolResults() []ToolResult + type MessageStore interface + AppendMessages func(ctx context.Context, sessionID uint, messages ...Message) error + ListMessages func(ctx context.Context, sessionID uint) ([]Message, error) + type Model interface + Capabilities func() Capabilities + Name func() string + Stream func(ctx context.Context, req *GenerateRequest) (<-chan StreamChunk, error) + type ModelError struct + Cause error + HTTPStatus int + Kind ModelErrorKind + RetryAfter time.Duration + Retryable bool + SafeDetail string + func (e *ModelError) Error() string + func (e *ModelError) Unwrap() error + type ModelErrorKind string + const ModelErrorKindAuth + const ModelErrorKindProtocol + const ModelErrorKindRateLimit + const ModelErrorKindRejected + const ModelErrorKindTransport + const ModelErrorKindUnsupported + type ModelMetadata struct + Capabilities Capabilities + ContextWindow int + Name string + Version string + type MutationGuard struct + FenceToken uint64 + LeaseOwner string + Revision uint64 + RunKey string + type Observation struct + Step *StepResult + Text string + ToolCall *ToolCall + ToolResult *ToolResult + Type ObservationType + type ObservationEmitter struct + func NewObservationEmitter(queueSize int, consume func(Observation)) *ObservationEmitter + func (e *ObservationEmitter) Close() + type ObservationType string + const ObservationStepFinished + const ObservationTextDelta + const ObservationToolCall + const ObservationToolResult + type Outcome string + const OutcomeCompleted + const OutcomeFailed + const OutcomeSuspended + type PartType string + const PartImage + const PartText + const PartToolCall + const PartToolResult + type Registry struct + func NewRegistry() *Registry + func (r *Registry) Get(name string) (Tool, bool) + func (r *Registry) Names() []string + func (r *Registry) Register(t Tool) error + func (r *Registry) Replace(t Tool) error + type ReplayPolicy string + const ReplayPolicyIdempotent + const ReplayPolicyNever + const ReplayPolicyResolve + type Response struct + FinishReason FinishReason + Message Message + ModelName string + Usage Usage + func (r *Response) ToolCalls() []ToolCall + type Role string + const RoleAssistant + const RoleSystem + const RoleTool + const RoleUser + type RunFailure struct + Code string + Message string + type RunIdentity struct + AgentKey string + RequestID string + RunKey string + SessionID string + type RunPhase string + const RunPhaseFinalizing + const RunPhaseModelInflight + const RunPhaseModelReady + const RunPhaseTerminal + const RunPhaseToolInflight + const RunPhaseToolsReady + type RunRequest struct + DurableRun *DurableRunConfig + Messages []Message + ObservationEmitter *ObservationEmitter + StepPolicy StepPolicy + ToolChoice *ToolChoice + type RunResult struct + DurableCompletion *DurableCompletion + DurableFailure *DurableFailure + DurableFence uint64 + DurableSuspension *DurableSuspension + Messages []Message + ModelName string + Outcome Outcome + Steps []StepResult + StopReason StopReason + Text string + Usage Usage + type RunSnapshot struct + Checkpoint Checkpoint + ConfigDigest string + Failure *RunFailure + FenceToken uint64 + Identity RunIdentity + InputDigest string + LeaseOwner string + LeaseUntil time.Time + Phase RunPhase + Revision uint64 + SchemaVersion int + Status RunStatus + func UnmarshalRunSnapshot(data []byte) (RunSnapshot, error) + func (snapshot RunSnapshot) Clone() RunSnapshot + func (snapshot RunSnapshot) Guard() MutationGuard + type RunStatus string + const RunStatusAbandoned + const RunStatusClaimed + const RunStatusCompleted + const RunStatusFailed + const RunStatusRunning + const RunStatusSuspended + type RuntimeDefinition struct + func NewRuntimeDefinition(spec RuntimeDefinitionSpec, model Model, tools *ToolSet) (*RuntimeDefinition, error) + func (d *RuntimeDefinition) ArtifactVersions() ArtifactVersions + func (d *RuntimeDefinition) ExecutionSettings() ExecutionSettings + func (d *RuntimeDefinition) Key() string + func (d *RuntimeDefinition) ModelMetadata() ModelMetadata + func (d *RuntimeDefinition) NewAgent() (*Agent, error) + func (d *RuntimeDefinition) ToolDefinitions() []ToolDefinition + type RuntimeDefinitionSpec struct + Execution ExecutionSettings + Key string + Model ModelMetadata + PolicyVersion string + PromptVersion string + type Session struct + AgentKey string + ID uint + Identity string + Metadata string + ModelName string + Status SessionStatus + Usage Usage + UserID uint + type SessionStatus string + const SessionAbandoned + const SessionActive + const SessionFailed + const SessionFinished + type SessionStore interface + AddUsage func(ctx context.Context, sessionID uint, usage Usage) error + CreateSession func(ctx context.Context, session Session) error + GetSession func(ctx context.Context, sessionID uint) (Session, error) + UpdateSessionStatus func(ctx context.Context, sessionID uint, status SessionStatus) error + type StepPolicy func(StepPolicyInput) (StepPolicyDecision, error) + type StepPolicyDecision struct + ActiveTools []string + Generation GenerationOptions + Model string + ToolChoice *ToolChoice + type StepPolicyInput struct + AvailableTools []ToolDefinition + CompletedSteps []StepResult + type StepResult struct + FinishReason FinishReason + Message Message + StepNumber int + ToolCalls []ToolCall + ToolResults []ToolResult + Usage Usage + type StopCondition = func(steps []StepResult) bool + func AnyStopCondition(conds ...StopCondition) StopCondition + func HasToolCall(name string) StopCondition + func MaxTokensUsed(max int) StopCondition + func StepCountIs(n int) StopCondition + type StopReason string + const StopReasonComplete + const StopReasonContextBudget + const StopReasonLoopDetected + const StopReasonMaxSteps + const StopReasonOutputLimit + const StopReasonStopCondition + const StopReasonToolStopTurn + type Store interface + type StreamChunk struct + Err error + Response *Response + TextDelta string + ToolCall *ToolCall + Type ChunkType + type TenantKey string + func (k TenantKey) Valid() bool + type Tool interface + Definition func() ToolDefinition + Execute func(ctx context.Context, invocation ToolInvocation) (ToolResult, error) + ReplayPolicy func() ReplayPolicy + type ToolCall struct + ID string + Input string + Name string + type ToolChoice struct + Mode ToolChoiceMode + Name string + func (c ToolChoice) Validate(tools []ToolDefinition, caps Capabilities) error + type ToolChoiceMode string + const ToolChoiceAuto + const ToolChoiceNamed + const ToolChoiceNone + const ToolChoiceRequired + type ToolDefinition struct + Description string + Name string + Parameters map[string]any + Strict bool + type ToolExecution struct + IdempotencyKey string + InputHash string + Ordinal int + Result *ToolResult + RunKey string + Status ToolExecutionStatus + StepNumber int + ToolCall ToolCall + func NewToolExecution(identity RunIdentity, stepNumber, ordinal int, call ToolCall) (ToolExecution, error) + type ToolExecutionStatus string + const ToolExecutionCompleted + const ToolExecutionExecuting + const ToolExecutionPrepared + const ToolExecutionUnknown + type ToolInvocation struct + CallID string + ExecutionKey string + Name string + RawInput string + type ToolOption func(*toolOptions) + func WithToolExecutableVersion(version string) ToolOption + func WithToolReplayPolicy(policy ReplayPolicy) ToolOption + func WithoutStrictSchema() ToolOption + type ToolResult struct + Content string + IsError bool + Name string + StopTurn bool + ToolCallID string + type ToolSet struct + func NewToolSet(registry *Registry, allowed []string) (*ToolSet, error) + func (s *ToolSet) Allowed(name string) bool + func (s *ToolSet) Definitions() []ToolDefinition + func (s *ToolSet) Get(name string) (Tool, error) + func (s *ToolSet) Subset(names []string) (*ToolSet, error) + func (s *ToolSet) ValidateExecutableVersions() error + func (s *ToolSet) Version() string + type Usage struct + CacheCreationTokens int + CacheReadTokens int + CompletionTokens int + PromptTokens int + ReasoningTokens int + TotalTokens int + func (u *Usage) Add(other Usage) + func (u Usage) InputTokens() int + func (u Usage) Validate() error v0.1.0 Aug 6, 2026