execution

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 15 Imported by: ? 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 execution defines portable run identity, tool-attempt, approval, and versioned dispatch contracts. Persistence is supplied by the host.

Index

Constants

View Source
const (
	RunPending   RunExecutionState = "pending"
	RunExecuting RunExecutionState = "executing"
	RunPaused    RunExecutionState = "paused"
	RunSucceeded RunExecutionState = "succeeded"
	RunFailed    RunExecutionState = "failed"
	RunCancelled RunExecutionState = "cancelled"

	DeliveryPending   RunDeliveryState = "pending"
	DeliveryStreaming RunDeliveryState = "streaming"
	DeliveryDelivered RunDeliveryState = "delivered"
	DeliveryFailed    RunDeliveryState = "failed"
)
View Source
const (
	PlanStepPending   = "pending"
	PlanStepRunning   = "running"
	PlanStepCompleted = "completed"
	PlanStepBlocked   = "blocked"

	TaskPending   = "pending"
	TaskClaimed   = "claimed"
	TaskRunning   = "running"
	TaskCompleted = "completed"
	TaskFailed    = "failed"
	TaskCancelled = "cancelled"
)
View Source
const OperationEnvelopeVersion = 1

Variables

View Source
var (
	ErrApprovalRevisionConflict = errors.New("approval revision conflict")
	ErrApprovalOwnerMismatch    = errors.New("approval owner mismatch")
)
View Source
var (
	ErrAttemptConflict         = errors.New("attempt identity reused with different input")
	ErrAttemptRevisionConflict = errors.New("attempt revision conflict")
	ErrAttemptOwnerMismatch    = errors.New("attempt owner mismatch")
	ErrAttemptTerminal         = errors.New("attempt already settled")
)
View Source
var (
	ErrInputConflict = errors.New("input ID reused with different request")
	ErrInputRevision = errors.New("input revision conflict")
	ErrSessionBusy   = errors.New("session has an active input")
	ErrGlobalBusy    = errors.New("global run limit reached")
)
View Source
var (
	ErrToolRoundConflict = errors.New("tool round ID reused with different intent")
	ErrToolRoundRevision = errors.New("tool round revision conflict")
)
View Source
var (
	ErrPlanRevision = errors.New("plan revision conflict")
	ErrTaskRevision = errors.New("task revision conflict")
	ErrTaskClaimed  = errors.New("task is already claimed")
)

Functions

func IsTaskPlanStale

func IsTaskPlanStale(task Task, plan Plan) bool

IsTaskPlanStale reports whether a task was admitted against an older plan revision. Hosts can surface this without mutating either durable record.

func WithIdentity

func WithIdentity(ctx context.Context, identity Identity) (context.Context, error)

WithIdentity pins identity once. Rebinding an existing context fails.

Types

type AdmissionDecision

type AdmissionDecision struct {
	Input    AdmittedInput
	Join     bool
	Wake     bool
	ActiveID string
	// InterruptID is populated only for an explicit now-priority input. The
	// host remains responsible for cancelling the active provider/tool work.
	InterruptID string
}

type AdmissionEnvelopeBuilder

type AdmissionEnvelopeBuilder struct {
	Attempts          AttemptLedger
	MaxReconciliation int
}

func (AdmissionEnvelopeBuilder) Build

func (b AdmissionEnvelopeBuilder) Build(ctx context.Context, identity Identity, inputID, policyVersion, catalogVersion, contextDigest, harnessDigest string) (CanonicalAdmission, error)

type AdmittedInput

type AdmittedInput struct {
	ID            string        `json:"id"`
	Identity      Identity      `json:"identity"`
	PayloadHash   string        `json:"payload_hash"`
	Mode          InputMode     `json:"mode"`
	Priority      InputPriority `json:"priority"`
	State         InputState    `json:"state"`
	FailureCode   string        `json:"failure_code,omitempty"`
	AdmittedAt    time.Time     `json:"admitted_at"`
	UpdatedAt     time.Time     `json:"updated_at"`
	Revision      uint64        `json:"revision"`
	SteersInputID string        `json:"steers_input_id,omitempty"`
}

AdmittedInput stores a digest, not prompt text. Hosts retain sensitive request bodies in their own encrypted store.

type ApprovalDecision

type ApprovalDecision struct {
	RequestID    string    `json:"request_id"`
	EnvelopeHash string    `json:"envelope_hash"`
	Allowed      bool      `json:"allowed"`
	Reason       string    `json:"reason,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
}

ApprovalDecision settles one approval request.

type ApprovalPendingError

type ApprovalPendingError struct{ Request ApprovalRequest }

func (*ApprovalPendingError) Error

func (e *ApprovalPendingError) Error() string

type ApprovalRecord

type ApprovalRecord struct {
	Request  ApprovalRequest  `json:"request"`
	Decision ApprovalDecision `json:"decision,omitempty"`
	State    ApprovalState    `json:"state"`
	Revision uint64           `json:"revision"`
}

type ApprovalRequest

type ApprovalRequest struct {
	Version      int               `json:"version"`
	ID           string            `json:"id"`
	Envelope     OperationEnvelope `json:"envelope"`
	EnvelopeHash string            `json:"envelope_hash"`
	ReasonCode   string            `json:"reason_code"`
	CreatedAt    time.Time         `json:"created_at"`
}

ApprovalRequest is a reconnect-safe authorization question.

func NewApprovalRequest

func NewApprovalRequest(id string, envelope OperationEnvelope, reason string, at time.Time) (ApprovalRequest, error)

NewApprovalRequest seals an approval question to the exact operation envelope. It is also useful to durable-store conformance suites and out-of-process approval presenters.

type ApprovalState

type ApprovalState string
const (
	ApprovalPending  ApprovalState = "pending"
	ApprovalApproved ApprovalState = "approved"
	ApprovalDenied   ApprovalState = "denied"
)

type ApprovalStore

ApprovalStore is the durable, owner-scoped reconnect boundary.

type Approver

type Approver interface {
	Approve(context.Context, ApprovalRequest) (ApprovalDecision, error)
}

Approver may block while a durable host mediates a request. It must return when ctx is cancelled.

type Attempt

type Attempt struct {
	ID              string       `json:"id"`
	Identity        Identity     `json:"identity"`
	RequestID       string       `json:"request_id,omitempty"`
	Tool            ToolRef      `json:"tool"`
	PolicyVersion   string       `json:"policy_version"`
	CatalogVersion  string       `json:"catalog_version"`
	SchemaDigest    string       `json:"schema_digest"`
	ArgsHash        string       `json:"args_hash"`
	TargetHash      string       `json:"target_hash"`
	IdempotencyKey  string       `json:"idempotency_key"`
	SourceEventIDs  []string     `json:"source_event_ids,omitempty"`
	State           AttemptState `json:"state"`
	ReasonCode      string       `json:"reason_code,omitempty"`
	ResultHash      string       `json:"result_hash,omitempty"`
	ReconcileAction string       `json:"reconcile_action,omitempty"`
	AdmittedAt      time.Time    `json:"admitted_at"`
	StartedAt       time.Time    `json:"started_at,omitempty"`
	SettledAt       time.Time    `json:"settled_at,omitempty"`
	Revision        uint64       `json:"revision"`
}

Attempt records immutable intent plus CAS-guarded lifecycle settlement.

type AttemptLedger

AttemptLedger is the durable, owner-scoped CAS boundary used by Dispatcher.

type AttemptSettlement

type AttemptSettlement struct {
	State           AttemptState
	ReasonCode      string
	ResultHash      string
	ReconcileAction string
	At              time.Time
}

type AttemptState

type AttemptState string

AttemptState is the durable lifecycle of one invocation.

const (
	AttemptAdmitted        AttemptState = "admitted"
	AttemptExecuting       AttemptState = "executing"
	AttemptSucceeded       AttemptState = "succeeded"
	AttemptFailed          AttemptState = "failed"
	AttemptDenied          AttemptState = "denied"
	AttemptIndeterminate   AttemptState = "indeterminate"
	AttemptCancelledBefore AttemptState = "cancelled_before_effect"
)

type AuthorizationResolver

type AuthorizationResolver func(canonicalArguments string) ([]AuthorizationTarget, error)

type AuthorizationTarget

type AuthorizationTarget struct {
	Action   string `json:"action"`
	Resource string `json:"resource,omitempty"`
}

type CanonicalAdmission

type CanonicalAdmission struct {
	Identity        Identity  `json:"identity"`
	InputID         string    `json:"input_id"`
	PolicyVersion   string    `json:"policy_version"`
	CatalogVersion  string    `json:"catalog_version"`
	ContextDigest   string    `json:"context_digest"`
	HarnessDigest   string    `json:"harness_digest,omitempty"`
	Reconciliation  []Attempt `json:"reconciliation,omitempty"`
	AdmissionDigest string    `json:"admission_digest"`
}

CanonicalAdmission is the pre-provider boundary. It pins the projections that must not be rediscovered or silently changed mid-run.

func (CanonicalAdmission) ReadyForProvider

func (a CanonicalAdmission) ReadyForProvider() bool

type Canonicalizer

type Canonicalizer func(arguments string) (string, error)

type Capability

type Capability struct {
	Ref          ToolRef         `json:"ref"`
	Description  string          `json:"description"`
	Schema       json.RawMessage `json:"schema"`
	SchemaDigest string          `json:"schema_digest"`
	Class        ToolClass       `json:"class"`
}

type CapabilityPage

type CapabilityPage struct {
	CatalogVersion string              `json:"catalog_version"`
	Items          []CapabilitySummary `json:"items"`
	NextCursor     string              `json:"next_cursor,omitempty"`
}

type CapabilityQuery

type CapabilityQuery struct {
	ToolSet        string `json:"tool_set,omitempty"`
	Search         string `json:"search,omitempty"`
	Cursor         string `json:"cursor,omitempty"`
	Limit          int    `json:"limit,omitempty"`
	IncludeSchemas bool   `json:"include_schemas,omitempty"`
	MaxSchemaBytes int    `json:"max_schema_bytes,omitempty"`
}

CapabilityQuery pages through the policy-filtered catalog. Schemas are opt-in so a large tool registry does not consume every provider request.

type CapabilitySummary

type CapabilitySummary struct {
	Ref           ToolRef         `json:"ref"`
	Description   string          `json:"description"`
	SchemaDigest  string          `json:"schema_digest"`
	Class         ToolClass       `json:"class"`
	Schema        json.RawMessage `json:"schema,omitempty"`
	SchemaOmitted bool            `json:"schema_omitted,omitempty"`
}

type Catalog

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

Catalog registers tools and produces immutable per-run snapshots.

func NewCatalog

func NewCatalog() *Catalog

func (*Catalog) Register

func (c *Catalog) Register(spec ToolSpec) error

func (*Catalog) Snapshot

func (c *Catalog) Snapshot(version string) (CatalogSnapshot, error)

type CatalogSnapshot

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

CatalogSnapshot is an immutable admitted tool catalog.

func (CatalogSnapshot) CanonicalOperation

func (s CatalogSnapshot) CanonicalOperation(ref ToolRef, assertedResource, arguments string) (Operation, error)

CanonicalOperation validates a tool call and derives its immutable policy target. assertedResource is only a caller-side consistency check.

func (CatalogSnapshot) Capabilities

func (s CatalogSnapshot) Capabilities(toolSet string, snapshot policy.Snapshot) []Capability

Capabilities is the versioned source for model discovery. Consumers should generate provider-specific tool schemas from this same snapshot.

func (CatalogSnapshot) Discover

func (s CatalogSnapshot) Discover(query CapabilityQuery, snapshot policy.Snapshot) (CapabilityPage, error)

Discover returns a deterministic page tied to this admitted catalog generation. A cursor from another generation fails instead of drifting.

func (CatalogSnapshot) Refs

func (s CatalogSnapshot) Refs(policySnapshot policy.Snapshot) []ToolRef

func (CatalogSnapshot) Resolve

func (s CatalogSnapshot) Resolve(ref ToolRef) (ToolSpec, bool)

func (CatalogSnapshot) Version

func (s CatalogSnapshot) Version() string

Version returns the catalog generation pinned at admission.

type ChildRun

type ChildRun struct {
	ID                string      `json:"id"`
	ParentRunID       string      `json:"parent_run_id"`
	ParentNodeID      string      `json:"parent_node_id,omitempty"`
	ExpertID          string      `json:"expert_id"`
	Identity          Identity    `json:"identity"`
	Model             string      `json:"model"`
	CapabilityVersion string      `json:"capability_version"`
	ContextDigest     string      `json:"context_digest,omitempty"`
	Status            ChildStatus `json:"status"`
	ArtifactRef       string      `json:"artifact_ref,omitempty"`
	FailureCode       string      `json:"failure_code,omitempty"`
	CreatedAt         time.Time   `json:"created_at"`
	UpdatedAt         time.Time   `json:"updated_at"`
	Revision          uint64      `json:"revision"`
}

ChildRun is the optional durable projection for inspectable or detached delegated work. It intentionally stores manifests and artifacts, not a full child transcript.

type ChildRunStore

type ChildRunStore interface {
	Create(context.Context, ChildRun) error
	Transition(context.Context, string, uint64, ChildStatus, string, string) (ChildRun, error)
	Get(context.Context, string) (ChildRun, bool)
}

type ChildStatus

type ChildStatus string
const (
	ChildPending   ChildStatus = "pending"
	ChildRunning   ChildStatus = "running"
	ChildCompleted ChildStatus = "completed"
	ChildFailed    ChildStatus = "failed"
	ChildCancelled ChildStatus = "cancelled"
	ChildPressure  ChildStatus = "pressure"
)

type Dispatcher

type Dispatcher struct {
	Catalog   CatalogSnapshot
	Policy    policy.Snapshot
	Ledger    AttemptLedger
	Approver  Approver
	Approvals ApprovalStore
	Now       func() time.Time
}

Dispatcher validates and canonicalizes before it authorizes, records, or exposes an approval. Every later phase consumes the same sealed envelope.

func (Dispatcher) Execute

func (d Dispatcher) Execute(ctx context.Context, attemptID string, ref ToolRef, resource, arguments string) (string, error)

Execute is the compact compatibility entry point. resource is an assertion, never the policy target; registered tools derive that target from arguments.

func (Dispatcher) ExecuteOperation

func (d Dispatcher) ExecuteOperation(ctx context.Context, request OperationRequest) (string, error)

ExecuteOperation runs one request from its canonical operation envelope.

type ExistingAttemptError

type ExistingAttemptError struct{ Attempt Attempt }

func (*ExistingAttemptError) Error

func (e *ExistingAttemptError) Error() string

type Flow

type Flow struct {
	ID       string     `json:"id"`
	Revision uint64     `json:"revision"`
	Nodes    []FlowNode `json:"nodes"`
}

Flow describes dependencies between tasks. It is a contract only; the framework intentionally does not provide a workflow scheduler.

type FlowNode

type FlowNode struct {
	TaskID    string   `json:"task_id"`
	DependsOn []string `json:"depends_on,omitempty"`
}

type Goal

type Goal struct {
	ID        string `json:"id"`
	Objective string `json:"objective"`
	Status    string `json:"status"`
	Revision  uint64 `json:"revision"`
}

Goal is a durable user objective independent of any one run.

type Identity

type Identity struct {
	PrincipalID string `json:"principal_id"`
	TenantID    string `json:"tenant_id,omitempty"`
	SessionID   string `json:"session_id"`
	RunID       string `json:"run_id"`
}

Identity is the immutable server-admitted execution identity inherited by child work. It must never be populated from model tool arguments.

func IdentityFromContext

func IdentityFromContext(ctx context.Context) (Identity, bool)

IdentityFromContext returns the admitted identity.

func (Identity) Validate

func (i Identity) Validate() error

type IndeterminateError

type IndeterminateError struct{ Err error }

IndeterminateError means execution may have produced an external effect; callers must reconcile rather than automatically retry.

func (*IndeterminateError) Error

func (e *IndeterminateError) Error() string

func (*IndeterminateError) Unwrap

func (e *IndeterminateError) Unwrap() error

type InputMode

type InputMode string
const (
	InputQueue InputMode = "queue"
	InputSteer InputMode = "steer"
)

type InputPriority

type InputPriority string

InputPriority declares the safe boundary at which a newly admitted input may affect an active session. It is persisted with the input so reconnects do not silently change interrupt semantics.

const (
	InputPriorityNow   InputPriority = "now"
	InputPriorityNext  InputPriority = "next"
	InputPriorityLater InputPriority = "later"
)

type InputState

type InputState string
const (
	InputAdmitted  InputState = "admitted"
	InputQueued    InputState = "queued"
	InputSteering  InputState = "steering"
	InputRunning   InputState = "running"
	InputCompleted InputState = "completed"
	InputFailed    InputState = "failed"
	InputCancelled InputState = "cancelled"
)

type MemoryAdmissionStore

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

func NewMemoryAdmissionStore

func NewMemoryAdmissionStore() *MemoryAdmissionStore

func (*MemoryAdmissionStore) Create

func (*MemoryAdmissionStore) Get

func (*MemoryAdmissionStore) Pending

func (s *MemoryAdmissionStore) Pending(ctx context.Context, owner Identity, limit int) ([]AdmittedInput, error)

func (*MemoryAdmissionStore) Transition

func (s *MemoryAdmissionStore) Transition(ctx context.Context, owner Identity, id string, expected uint64, next InputState, failure, steers string) (AdmittedInput, error)

type MemoryApprovalStore

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

func NewMemoryApprovalStore

func NewMemoryApprovalStore() *MemoryApprovalStore

func (*MemoryApprovalStore) Create

func (*MemoryApprovalStore) Get

func (s *MemoryApprovalStore) Get(ctx context.Context, owner Identity, requestID string) (ApprovalRecord, bool, error)

func (*MemoryApprovalStore) Resolve

func (s *MemoryApprovalStore) Resolve(ctx context.Context, owner Identity, requestID string, expected uint64, decision ApprovalDecision) (ApprovalRecord, error)

type MemoryAttemptLedger

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

MemoryAttemptLedger is a concurrency-safe reference implementation.

func NewMemoryAttemptLedger

func NewMemoryAttemptLedger() *MemoryAttemptLedger

func (*MemoryAttemptLedger) Admit

func (*MemoryAttemptLedger) Get

func (l *MemoryAttemptLedger) Get(ctx context.Context, owner Identity, id string) (Attempt, bool, error)

func (*MemoryAttemptLedger) ListForReconciliation

func (l *MemoryAttemptLedger) ListForReconciliation(ctx context.Context, owner Identity, limit int) ([]Attempt, error)

func (*MemoryAttemptLedger) Settle

func (l *MemoryAttemptLedger) Settle(ctx context.Context, owner Identity, id string, expected uint64, settlement AttemptSettlement) (Attempt, error)

func (*MemoryAttemptLedger) Start

func (l *MemoryAttemptLedger) Start(ctx context.Context, owner Identity, id string, expected uint64, at time.Time) (Attempt, error)

type MemoryChildRunStore

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

func NewMemoryChildRunStore

func NewMemoryChildRunStore() *MemoryChildRunStore

func (*MemoryChildRunStore) Create

func (s *MemoryChildRunStore) Create(ctx context.Context, run ChildRun) error

func (*MemoryChildRunStore) Get

func (*MemoryChildRunStore) Transition

func (s *MemoryChildRunStore) Transition(ctx context.Context, id string, expected uint64, next ChildStatus, artifactRef, failureCode string) (ChildRun, error)

type MemoryRunStore

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

func NewMemoryRunStore

func NewMemoryRunStore() *MemoryRunStore

func (*MemoryRunStore) Create

func (s *MemoryRunStore) Create(ctx context.Context, run Run) (Run, error)

func (*MemoryRunStore) Get

func (s *MemoryRunStore) Get(ctx context.Context, owner Identity, id string) (Run, bool, error)

func (*MemoryRunStore) Update

func (s *MemoryRunStore) Update(ctx context.Context, owner Identity, id string, expected uint64, execution RunExecutionState, delivery RunDeliveryState, failure string, cursor uint64) (Run, error)

type MemoryTaskMailbox

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

func NewMemoryTaskMailbox

func NewMemoryTaskMailbox() *MemoryTaskMailbox

func (*MemoryTaskMailbox) Ack

func (m *MemoryTaskMailbox) Ack(ctx context.Context, owner Identity, recipient string, sequence uint64) (TaskMailboxState, error)

func (*MemoryTaskMailbox) Append

func (m *MemoryTaskMailbox) Append(ctx context.Context, message TaskMessage) (TaskMessage, bool, error)

func (*MemoryTaskMailbox) Replay

func (m *MemoryTaskMailbox) Replay(ctx context.Context, owner Identity, recipient string, after uint64, limit int) ([]TaskMessage, error)

type MemoryToolRoundStore

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

func NewMemoryToolRoundStore

func NewMemoryToolRoundStore() *MemoryToolRoundStore

func (*MemoryToolRoundStore) Create

func (s *MemoryToolRoundStore) Create(ctx context.Context, round ToolRound) (ToolRound, bool, error)

func (*MemoryToolRoundStore) Get

func (*MemoryToolRoundStore) Open

func (s *MemoryToolRoundStore) Open(ctx context.Context, owner Identity, limit int) ([]ToolRound, error)

func (*MemoryToolRoundStore) Transition

func (s *MemoryToolRoundStore) Transition(ctx context.Context, owner Identity, roundID string, expected uint64, callID string, next ToolCallState, attemptID string, omission *ToolOmission) (ToolRound, error)

type MemoryWorkStore

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

func NewMemoryWorkStore

func NewMemoryWorkStore() *MemoryWorkStore

func (*MemoryWorkStore) CreatePlan

func (s *MemoryWorkStore) CreatePlan(ctx context.Context, record PlanRecord) (PlanRecord, error)

func (*MemoryWorkStore) CreateTask

func (s *MemoryWorkStore) CreateTask(ctx context.Context, task Task) (Task, error)

func (*MemoryWorkStore) GetPlan

func (s *MemoryWorkStore) GetPlan(ctx context.Context, owner Identity, id string) (PlanRecord, bool, error)

func (*MemoryWorkStore) GetTask

func (s *MemoryWorkStore) GetTask(ctx context.Context, owner Identity, id string) (Task, bool, error)

func (*MemoryWorkStore) ListTasks

func (s *MemoryWorkStore) ListTasks(ctx context.Context, owner Identity, goalID string) ([]Task, error)

func (*MemoryWorkStore) TransitionTask

func (s *MemoryWorkStore) TransitionTask(ctx context.Context, owner Identity, id string, expected uint64, status, runID, assignee string) (Task, error)

func (*MemoryWorkStore) UpdatePlan

func (s *MemoryWorkStore) UpdatePlan(ctx context.Context, owner Identity, id string, expected uint64, steps []PlanStep) (PlanRecord, error)

type Operation

type Operation struct {
	Tool               ToolRef               `json:"tool"`
	CatalogVersion     string                `json:"catalog_version"`
	SchemaDigest       string                `json:"schema_digest"`
	CanonicalArguments string                `json:"canonical_arguments"`
	ArgsHash           string                `json:"args_hash"`
	Resource           string                `json:"resource,omitempty"`
	TargetHash         string                `json:"target_hash"`
	Authorizations     []AuthorizationTarget `json:"authorizations,omitempty"`
}

Operation is the canonical, schema-pinned value authorized by policy and approvals. It contains no caller-authored description of the target.

type OperationEnvelope

type OperationEnvelope struct {
	Version        int      `json:"version"`
	Identity       Identity `json:"identity"`
	AttemptID      string   `json:"attempt_id"`
	RequestID      string   `json:"request_id,omitempty"`
	PolicyVersion  string   `json:"policy_version"`
	IdempotencyKey string   `json:"idempotency_key"`
	SourceEventIDs []string `json:"source_event_ids,omitempty"`
	Operation
}

OperationEnvelope is the closed record used for intent, approval, dispatch, reconciliation, and audit.

type OperationRequest

type OperationRequest struct {
	AttemptID      string   `json:"attempt_id"`
	RequestID      string   `json:"request_id,omitempty"`
	IdempotencyKey string   `json:"idempotency_key,omitempty"`
	SourceEventIDs []string `json:"source_event_ids,omitempty"`
	Tool           ToolRef  `json:"tool"`
	Resource       string   `json:"resource,omitempty"`
	Arguments      string   `json:"arguments"`
}

OperationRequest binds an operation to its admitted execution provenance.

type Plan

type Plan struct {
	ID        string     `json:"id"`
	Revision  uint64     `json:"revision"`
	Steps     []PlanStep `json:"steps"`
	UpdatedAt time.Time  `json:"updated_at"`
}

Plan describes intended steps and may be revised without becoming a task.

type PlanRecord

type PlanRecord struct {
	Owner Identity `json:"owner"`
	Plan  Plan     `json:"plan"`
}

type PlanStep

type PlanStep struct {
	ID          string `json:"id"`
	Description string `json:"description"`
	Status      string `json:"status"`
}

type PlanStore

type PlanStore interface {
	CreatePlan(context.Context, PlanRecord) (PlanRecord, error)
	UpdatePlan(context.Context, Identity, string, uint64, []PlanStep) (PlanRecord, error)
	GetPlan(context.Context, Identity, string) (PlanRecord, bool, error)
}

type ResourceResolver

type ResourceResolver func(canonicalArguments string) (string, error)

type Run

type Run struct {
	ID             string            `json:"id"`
	InputID        string            `json:"input_id"`
	Identity       Identity          `json:"identity"`
	Execution      RunExecutionState `json:"execution"`
	Delivery       RunDeliveryState  `json:"delivery"`
	FailureCode    string            `json:"failure_code,omitempty"`
	DeliveryCursor uint64            `json:"delivery_cursor,omitempty"`
	CreatedAt      time.Time         `json:"created_at"`
	UpdatedAt      time.Time         `json:"updated_at"`
	Revision       uint64            `json:"revision"`
}

type RunDeliveryState

type RunDeliveryState string

type RunExecutionState

type RunExecutionState string

type SessionCoordinator

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

SessionCoordinator serializes each session and bounds global running work. Its wake bit coalesces repeated scheduler notifications.

func NewSessionCoordinator

func NewSessionCoordinator(store AdmissionStore, maxActive int) (*SessionCoordinator, error)

func (*SessionCoordinator) Admit

func (*SessionCoordinator) ConsumeWake

func (c *SessionCoordinator) ConsumeWake(sessionID string) bool

func (*SessionCoordinator) Finish

func (c *SessionCoordinator) Finish(ctx context.Context, owner Identity, id string, expected uint64, state InputState, failure string) (AdmittedInput, *AdmittedInput, error)

func (*SessionCoordinator) Interrupt

func (c *SessionCoordinator) Interrupt(ctx context.Context, owner Identity, id string, expected uint64) (AdmittedInput, *AdmittedInput, error)

func (*SessionCoordinator) Recover

func (c *SessionCoordinator) Recover(inputs []AdmittedInput) error

Recover rebuilds process-local scheduling state from durable nonterminal inputs. Hosts call it once after loading owner-scoped pending records.

type Task

type Task struct {
	ID           string    `json:"id"`
	GoalID       string    `json:"goal_id,omitempty"`
	ParentTaskID string    `json:"parent_task_id,omitempty"`
	PlanID       string    `json:"plan_id,omitempty"`
	PlanRevision uint64    `json:"plan_revision,omitempty"`
	RunID        string    `json:"run_id,omitempty"`
	Status       string    `json:"status"`
	Assignee     string    `json:"assignee,omitempty"`
	Owner        Identity  `json:"owner"`
	Revision     uint64    `json:"revision"`
	UpdatedAt    time.Time `json:"updated_at"`
}

Task is one executing unit with ownership and terminal state.

type TaskMailboxState

type TaskMailboxState struct {
	HeadSequence  uint64 `json:"head_sequence"`
	AckedSequence uint64 `json:"acked_sequence"`
}

type TaskMessage

type TaskMessage struct {
	ID              string    `json:"id"`
	Owner           Identity  `json:"owner"`
	SenderTaskID    string    `json:"sender_task_id"`
	RecipientTaskID string    `json:"recipient_task_id"`
	PayloadHash     string    `json:"payload_hash"`
	Sequence        uint64    `json:"sequence"`
	CreatedAt       time.Time `json:"created_at"`
}

TaskMessage carries only a payload digest; hosts retain message content in their encrypted task store. Sequence is assigned by the mailbox.

type TaskStore

type TaskStore interface {
	CreateTask(context.Context, Task) (Task, error)
	TransitionTask(context.Context, Identity, string, uint64, string, string, string) (Task, error)
	GetTask(context.Context, Identity, string) (Task, bool, error)
	ListTasks(context.Context, Identity, string) ([]Task, error)
}

type ToolCallRecord

type ToolCallRecord struct {
	ID        string        `json:"id"`
	Tool      ToolRef       `json:"tool"`
	Required  bool          `json:"required"`
	State     ToolCallState `json:"state"`
	AttemptID string        `json:"attempt_id,omitempty"`
	Omission  *ToolOmission `json:"omission,omitempty"`
	UpdatedAt time.Time     `json:"updated_at"`
}

type ToolCallState

type ToolCallState string
const (
	ToolCallPlanned         ToolCallState = "planned"
	ToolCallAdmitted        ToolCallState = "admitted"
	ToolCallApprovalPending ToolCallState = "approval_pending"
	ToolCallExecuting       ToolCallState = "executing"
	ToolCallSucceeded       ToolCallState = "succeeded"
	ToolCallFailed          ToolCallState = "failed"
	ToolCallDenied          ToolCallState = "denied"
	ToolCallIndeterminate   ToolCallState = "indeterminate"
	ToolCallOmitted         ToolCallState = "omitted"
)

type ToolClass

type ToolClass struct {
	Category      string `json:"category"`
	SideEffecting bool   `json:"side_effecting"`
	HostAction    bool   `json:"host_action"`
	TrustedOutput bool   `json:"trusted_output"`
}

ToolClass describes side effects and trust independently of prompts.

type ToolFunc

type ToolFunc func(context.Context, string) (string, error)

type ToolOmission

type ToolOmission struct {
	ReasonCode string `json:"reason_code"`
	Safe       bool   `json:"safe"`
}

type ToolRef

type ToolRef struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ToolRef pins the exact admitted tool registration.

type ToolRound

type ToolRound struct {
	ID             string           `json:"id"`
	Identity       Identity         `json:"identity"`
	PolicyVersion  string           `json:"policy_version"`
	CatalogVersion string           `json:"catalog_version"`
	Calls          []ToolCallRecord `json:"calls"`
	Revision       uint64           `json:"revision"`
	CreatedAt      time.Time        `json:"created_at"`
	UpdatedAt      time.Time        `json:"updated_at"`
}

ToolRound is the durable closure boundary for one model tool-call batch. Calls retain proposal order while settlement uses a round-wide CAS revision.

func (ToolRound) Assess

func (r ToolRound) Assess() ToolRoundAssessment

type ToolRoundAssessment

type ToolRoundAssessment struct {
	Converged bool     `json:"converged"`
	Blockers  []string `json:"blockers,omitempty"`
}

type ToolSpec

type ToolSpec struct {
	Ref          ToolRef
	Description  string
	Schema       json.RawMessage
	SchemaDigest string
	ToolSets     []string
	Class        ToolClass
	Validate     Validator
	// Canonicalize returns the exact JSON passed to execution and hashed into
	// approvals. When nil, the catalog uses deterministic JSON encoding.
	Canonicalize Canonicalizer
	// ResolveResource derives the policy resource from canonical arguments.
	// Resource-sensitive and side-effecting tools must provide it; callers are
	// never trusted to describe their own authorization target.
	ResolveResource ResourceResolver
	// ResolveAuthorizations adds argument-derived capabilities, such as the
	// selected expert or skill, that must also pass the admitted policy.
	ResolveAuthorizations AuthorizationResolver
	Execute               ToolFunc
}

ToolSpec is one immutable, executable catalog registration.

type Validator

type Validator func(arguments string) error

Jump to

Keyboard shortcuts

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