api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package api defines the agentsessions contracts: the Sessions control-plane API, the Harness BYOH SPI, and the Runtime compute SPI.

The .proto files in this directory are the wire format; these Go types are the hand-written SPI used by hosts and backends (to be reconciled with generated code).

Design rule: the core is vendor-neutral. Producers (GitHub, Foundry, custom apps) plug in on top as adapters; compute backends (pod, Kata, Cloud Hypervisor, substrate) plug in underneath via Runtime. No producer- or backend-specific fields in the core — specifics ride in Origin, annotations, and ComputeRef.Attributes.

Index

Constants

This section is empty.

Variables

View Source
var ErrApprovalParked = errors.New("approval parked")

ErrApprovalParked distinguishes a host-requested approval park from execution failure. A transport uses ApprovalParkedError.Ref, never error-string matching, for the park exchange.

View Source
var ErrSnapshotSuperseded = errors.New("runtime: fork source snapshot was superseded")

ErrSnapshotSuperseded reports that a fork's source snapshot is no longer the one the parent holds, because the parent was resumed (and possibly checkpointed again) after the snapshot was taken. The fork cannot clone it without pairing the children's journal prefix with different RAM; the caller can retry the fork at the parent's new head.

Functions

func IsParkUnwind

func IsParkUnwind(err error, ref ApprovalRef) bool

IsParkUnwind reports whether err contains only wrapped or joined parks for ref, with no independent failure elsewhere in the error tree. A matching park alone does not prove that the host has checkpointed compute or durably recorded a successful pause.

Types

type ApprovalDecision

type ApprovalDecision struct {
	ExecutionID string
	ToolCallID  string
	RequestSeq  int64
	Approved    bool
	Reason      string
	Identity    IdentityRef
}

ApprovalDecision is a caller's decision for one request. Identity records provenance only; it is not an authorization credential. The wire request uses explicit Approved presence so an omitted decision can be rejected; this domain value represents a supplied decision.

type ApprovalParkedError

type ApprovalParkedError struct {
	Ref ApprovalRef
}

ApprovalParkedError carries the request correlation for a parked Run. It does not commit a request or decision; durable approval state belongs to the host's journal.

func (*ApprovalParkedError) Error

func (e *ApprovalParkedError) Error() string

func (*ApprovalParkedError) Unwrap

func (e *ApprovalParkedError) Unwrap() error

type ApprovalRef

type ApprovalRef struct {
	ExecutionID string
	ToolCallID  string
	RequestSeq  int64
}

ApprovalRef identifies one host-owned approval request within the enclosing session. RequestSeq is the positive journal sequence, not a harness-chosen correlation number.

type ApprovalRequest

type ApprovalRequest struct {
	ToolCallID string
	Reason     string
}

ApprovalRequest asks a human or policy engine to allow a tool call.

type ApprovalResult

type ApprovalResult struct {
	ToolCallID string
	Approved   bool
	Reason     string
	RequestSeq int64 `json:",omitempty"` // sequence of the host-owned APPROVAL_REQUEST; zero for legacy decisions
}

ApprovalResult answers an ApprovalRequest (sent by the host).

type Capabilities

type Capabilities struct {
	Resumability Resumability
	ForkSafe     bool // no un-replayable side effects mid-turn -> fork via replay is safe
	RequiresGPU  bool
	Streaming    bool
	// ReasoningReplay: the harness persists and replays opaque provider reasoning parts
	// verbatim via the provider's stateless path (not previous_response_id / server lineage).
	// This keeps a reasoning harness on STATELESS_REPLAY — it adds NO snapshot edge. Verified
	// across Anthropic/OpenAI/Gemini in the Track A reasoning-continuity spike.
	ReasoningReplay bool
}

Capabilities is what a harness needs from the runtime and how it may be moved.

type ComputeRef

type ComputeRef struct {
	Runtime      string
	Worker       string // pod/worker id when live/warm; empty when cold
	Snapshot     *SnapshotRef
	Capabilities RuntimeCapabilities
	Attributes   map[string]string // backend-specific, e.g. substrate actor/atespace
}

ComputeRef describes the session's current incarnation.

type ComputeState

type ComputeState string

ComputeState is the incarnation (compute/sandbox) axis of a session's lifecycle.

const (
	ComputeNone       ComputeState = "NONE" // no incarnation
	ComputeLive       ComputeState = "LIVE" // running
	ComputeWarm       ComputeState = "WARM" // paused: resident, worker held
	ComputeCold       ComputeState = "COLD" // suspended: snapshot in storage, worker freed
	ComputeTerminated ComputeState = "TERMINATED"
)

type DeletionState

type DeletionState string

DeletionState is the permanent-deletion axis, independent of execution and compute. Pending acknowledges durable intent only; retained resources have not been reclaimed. Any other value is unrecognized and fails closed: it is treated as deleted, never as ACTIVE.

const (
	DeletionActive  DeletionState = "ACTIVE"
	DeletionPending DeletionState = "PENDING"
)

type Delta

type Delta struct {
	ExecutionID string
	PartIndex   int32
	Chunk       string
	Done        bool
}

Delta is an ephemeral streaming chunk. It is transport only: never appended to the log, never hash-chained, and never produced on replay. Chunks coalesce into the finalized EVENT_OUTPUT the log does record, so the journal is identical whether or not anyone was watching the turn.

type Descriptor

type Descriptor struct {
	ID           string
	Version      string   // stable author-owned replay version; empty is supported as unknown
	Models       []string // model-agnostic: supported/required model ids
	Tools        []ToolSpec
	Capabilities Capabilities
}

Descriptor is a harness's static contract.

type Error

type Error struct {
	Code        int32
	Description string
}

Error mirrors a gRPC status code + description.

type Event

type Event struct {
	// ExecutionID, timestamp, and content live on the Event; ordering (seq) and integrity
	// (prev_hash / content_hash) are host-assigned and live on the log-record envelope
	// (eventlog.Record / proto LogRecord), not on the harness-emitted Event.
	ExecutionID   string
	Timestamp     time.Time
	SchemaVersion int32 // versions the event body; replay survives schema skew

	Kind EventKind

	// typed body (exactly one set)
	Message        *Message
	ModelCall      *ModelCall
	ToolCall       *ToolCall
	Result         *ToolResult
	Approval       *ApprovalRequest
	ApprovalResult *ApprovalResult
	Usage          *Usage
	Lifecycle      *Lifecycle
	End            *HarnessEnd
	Err            *Error
	ExecutionStart *ExecutionStart
	Parked         *ApprovalRef `json:",omitempty"` // transport only, excluded from durable history

	Actor IdentityRef // emitter principal -> provenance on every action
}

Event is the shared unit of the session log and the harness stream. The host assigns the authoritative Seq on append. Ordering + integrity + identity live on the envelope; typed content lives in the body.

type EventKind

type EventKind string

EventKind classifies an Event. Typed events (vs opaque messages) are what make provenance, audit, cost, and tool-approval first-class.

const (
	EventInput           EventKind = "INPUT"
	EventModelCall       EventKind = "MODEL_CALL"
	EventOutput          EventKind = "OUTPUT"
	EventToolCall        EventKind = "TOOL_CALL"
	EventToolResult      EventKind = "TOOL_RESULT"
	EventApprovalRequest EventKind = "APPROVAL_REQUEST"
	EventApprovalResult  EventKind = "APPROVAL_RESULT"
	EventUsage           EventKind = "USAGE"
	EventLifecycle       EventKind = "LIFECYCLE"
	EventEnd             EventKind = "END"
	EventError           EventKind = "ERROR"
	EventExecutionStart  EventKind = "EXECUTION_START"
	EventParked          EventKind = "PARKED" // transport-only approval park acknowledgement; never journaled
)

type EventSink

type EventSink interface {
	// Model performs a model call and returns the completion. Live: the host invokes the
	// model and records the result. Replay: the host serves the recorded result from the
	// journal and does not invoke the model. Because the result flows back through this
	// mediated call, the harness never touches a provider SDK directly — the load-bearing
	// replay rule. Reasoning parts ride in the returned ModelResponse.Message and are
	// recorded verbatim for replay/fork continuity (I2). The completion is recorded as the
	// turn's output by the host; do not also emit the same content via Output (double-record).
	//
	// ctx carries the execution's cancellation and deadline through to the provider call, so
	// a cancelled turn stops an in-flight completion instead of orphaning it. Pass the ctx
	// from Run, or one derived from it.
	Model(ctx context.Context, req ModelRequest) (ModelResponse, error)
	// Output streams assistant output (a delta or a full message).
	Output(ctx context.Context, delta string) error
	// ToolCall emits a tool call and returns its result. For CONTROLLER_MEDIATED or
	// REQUIRES_APPROVAL tools it blocks until the host returns a result; for
	// IN_HARNESS_REPORTED tools the author executes the tool and calls Report instead.
	// ctx bounds that wait: a cancelled ctx unblocks it rather than hanging on a host that
	// never replies.
	ToolCall(ctx context.Context, tc ToolCall) (ToolResult, error)
	// Report records the result of a tool the harness executed itself.
	Report(ctx context.Context, tr ToolResult) error
	// Usage records token/cost accounting. To record a model call's usage, pass the
	// ModelResponse.Usage that Model returned: Replay and Resume serve the recorded usage with
	// the recorded completion, so the same call matches the record.
	Usage(ctx context.Context, u Usage) error
}

EventSink is the harness author's handle for emitting events. The SDK hides the gRPC stream, sequence assignment, and the emit -> wait-for-host round-trip.

type ExecState

type ExecState string

ExecState is the execution/turn axis of a session's lifecycle — the event-log axis. It is modeled separately from ComputeState (the incarnation axis) rather than flattened into a single enum, matching the durable-log & replay contract (§6). Both axes are authoritative and are reported independently on the wire.

const (
	ExecPending   ExecState = "PENDING"
	ExecRunning   ExecState = "RUNNING"
	ExecAwaiting  ExecState = "AWAITING" // blocked on approval/input, resolved from the log
	ExecCompleted ExecState = "COMPLETED"
	ExecFailed    ExecState = "FAILED"
	ExecCanceled  ExecState = "CANCELED"
)

type ExecutionStart

type ExecutionStart struct {
	Config         []byte
	ResumeFromSeq  int64
	InputCount     *int64
	Harness        string // resolved registry name; empty legacy values use the session harness
	HarnessVersion string // advertised opaque version; empty is unknown and retains legacy behavior
}

ExecutionStart is host-owned invocation state, recorded before the harness runs. Config is opaque and preserved verbatim; ResumeFromSeq is the harness's cursor, not the log's CAS cursor. InputCount records the expected number of INPUT events; zero explicitly permits inputless turns. A nil count cannot establish completeness and is rejected when reconstructing this invocation. Executions without this event reconstruct with empty config and a zero cursor (legacy defaults).

type FilePart

type FilePart struct {
	MIME   string
	Bytes  []byte
	URI    string
	Digest string // content digest of the URI target, so the hash-chain covers externalized bytes
	Name   string
}

FilePart carries media inline or by URI (A2A file part; MCP resource_link).

type ForkOpts

type ForkOpts struct {
	ChildSessionUID string
}

ForkOpts parameterizes a fork.

type Harness

type Harness interface {
	// Describe returns the static contract, used to match the harness to a Runtime.
	Describe(ctx context.Context) (Descriptor, error)

	// Run drives exactly one execution (turn). It reads the Start, emits events via
	// sink, and returns nil on COMPLETED or an error on FAILED. Cancellation via ctx.
	Run(ctx context.Context, s *Start, sink EventSink) error
}

Harness is the Bring-Your-Own-Harness SPI. A Microsoft Agent Framework (MAF) agent, a GitHub Copilot agent, or a custom agent implements it via a thin adapter. The host drives one execution per Run; the harness runs inside the sandbox provided by a Runtime.

The wire contract is api/harness.proto (Harness.Connect / Harness.Describe); an SDK adapts between them and hides sequence numbers and the tool-mediation round-trip.

type HarnessEnd

type HarnessEnd struct {
	State string // COMPLETED | FAILED | CANCELED
	Error *Error
}

HarnessEnd is the terminal state of one execution.

type IdentityContext

type IdentityContext struct {
	Principal IdentityRef
	MintToken TokenMinter // nil when identity is not configured (dev)
}

IdentityContext carries the session principal and, optionally, a minter so the harness can obtain scoped, delegated tokens (Transaction Tokens) for tool calls rather than passing the raw principal downstream.

type IdentityRef

type IdentityRef struct {
	Principal string
	Issuer    string
	Subject   string // session-scoped sub
}

IdentityRef is the bound agent principal. It is OIDC-neutral: an Entra Agent ID is one issuer; a SPIFFE ID or a GitHub App identity are others. Carried on every event.

type Incarnation

type Incarnation struct {
	ID         string
	Worker     string // pod/worker id
	Address    string // where the harness server listens, or the ingress that routes to it
	Runtime    string // "pod" | "kata" | "clh" | "substrate"
	FenceToken int64  // monotonic; the log rejects appends from a superseded incarnation
	// CallMetadata is request metadata the host must attach to every call it makes to the harness at
	// Address. A backend whose harness sits behind a shared ingress uses it to name the target
	// sandbox (substrate: ate-target-actor); a backend that hands out a direct address leaves it
	// empty. It is routing, not authentication: nothing here proves the caller's identity.
	CallMetadata map[string]string
}

Incarnation is a live compute instance of a session (a sandbox).

type Lifecycle

type Lifecycle struct {
	Kind     LifecycleKind
	Detail   string
	Snapshot *SnapshotRef // captured state, set on SUSPEND (§5.1)
}

Lifecycle marks a compute/session transition in the log (§7). Baseline is a replay / compaction checkpoint (§1).

type LifecycleKind

type LifecycleKind string

LifecycleKind enumerates the lifecycle transitions recorded in the log.

const (
	LifecycleSuspend  LifecycleKind = "SUSPEND"
	LifecycleResume   LifecycleKind = "RESUME"
	LifecycleFork     LifecycleKind = "FORK"
	LifecycleBaseline LifecycleKind = "BASELINE"
	LifecycleCancel   LifecycleKind = "CANCEL"
	LifecycleDelete   LifecycleKind = "DELETE" // host-owned permanent intent, not compute teardown
)

type Mediation

type Mediation string

Mediation controls how a tool call is executed.

const (
	// MediationInHarnessReported: the harness executes the tool in-sandbox and reports
	// the result as an event for audit. Default; fastest.
	MediationInHarnessReported Mediation = "IN_HARNESS_REPORTED"
	// MediationControllerMediated: the harness emits the call; the host/gateway executes
	// it (authz + policy + audit) and returns the result.
	MediationControllerMediated Mediation = "CONTROLLER_MEDIATED"
	// MediationRequiresApproval: the call pauses for human or policy approval.
	MediationRequiresApproval Mediation = "REQUIRES_APPROVAL"
)

type Message

type Message struct {
	Role  string // system | user | assistant (A2A calls this "agent") | tool
	Parts []Part
}

Message is a role-tagged sequence of content parts (A2A Message = role + Part[]).

func TextMessage

func TextMessage(role, text string) *Message

TextMessage constructs a single-text-part message.

func (*Message) Text

func (m *Message) Text() string

Text concatenates the text parts of a message (ignoring non-text parts).

type ModelCall

type ModelCall struct {
	Model     string
	Params    map[string]string
	InputHash string // required for STATELESS_REPLAY so the §9.1 I0 check can run
	ID        string // correlation id for the served ModelResult (proto ModelCall.id)
}

ModelCall records a call to a model (model-agnostic) for audit and cost.

type ModelRequest

type ModelRequest struct {
	Model    string
	Messages []Message // context (history + new input) sent to the model
	Params   map[string]string
	// Tools are the definitions offered to the model on this call. Order is significant.
	Tools []ToolDefinition `json:",omitempty"`
	// ToolChoice constrains whether and which tool the model calls. Nil means the provider default.
	ToolChoice *ToolChoice `json:",omitempty"`
}

ModelRequest is a model call: the message context + model selection.

The controller hashes the JSON encoding of ModelRequest for the I0 check, so fields added after the first three carry `json:",omitempty"`: a request that does not use them hashes exactly as it did before they existed, and logs recorded earlier keep replaying.

type ModelResponse

type ModelResponse struct {
	Message Message
	Usage   Usage
}

ModelResponse is the model's completion: an assistant message (which may carry text, opaque reasoning, and tool call parts) plus usage.

type Origin

type Origin struct {
	Source     string            // e.g. "github.com/acme/repo", "foundry/project-x"
	Subject    string            // e.g. "issues/42", "threads/abc"
	URI        string            // optional link
	Attributes map[string]string // adapter-specific extras; well-known keys via profiles
}

Origin is the neutral external context a session is tied to: where it came from and what it is about. Producer adapters (GitHub, Foundry, custom apps) fill it; the core defines no producer-specific fields. Modeled on CloudEvents source/subject.

type Part

type Part struct {
	Text      *TextPart
	File      *FilePart
	Data      map[string]any
	Reasoning *ReasoningPart
	// ToolCall is a model's request to call a tool, carried in an assistant message. Mediation
	// and IdempotencyKey are unset on a model output. To execute the call, copy it, set them on
	// the copy, and pass the copy to EventSink.ToolCall: the returned message can share this
	// pointer with the recorded completion, so changing it in place alters a hashed event.
	ToolCall *ToolCall `json:",omitempty"`
	// ToolResult is a tool's result fed back to the model, carried in a message with role
	// "tool". ToolResult.ID is the ID of the ToolCall it answers.
	ToolResult *ToolResult `json:",omitempty"`
}

Part is one unit of content: text, file (inline or URI), structured data, an opaque reasoning block, a model's tool call, or a tool's result. Aligned with A2A Part + MCP content. Exactly one field is set.

Fields added after the first four carry `json:",omitempty"`: the controller's model input hash (I0) is computed over the JSON encoding of ModelRequest, so a new field that encoded as null would change the hash of every request recorded before it existed.

type ReasoningPart

type ReasoningPart struct {
	Provider      string // "anthropic" | "openai" | "google"
	ModelID       string
	Opaque        []byte // set, OR OpaqueURI when externalized
	OpaqueURI     string
	OpaqueDigest  string // content digest of OpaqueURI target (hash-chain covers externalized bytes)
	Summary       []Part // optional, non-authoritative, compaction-droppable
	ItemID        string
	Ordinal       int32
	ValidityScope string // = execution id (turn)
}

ReasoningPart is an opaque, provider-tagged reasoning block replayed verbatim to preserve reasoning continuity within a turn (I2). agentsessions never interprets Opaque; provider specifics live inside it. One part type across all providers (Track A spike: no per-provider sub-shapes, no memory-snapshot edge).

type Resumability

type Resumability string

Resumability declares how a harness survives suspend/resume/fork.

const (
	// ResumabilityStatelessReplay: the harness holds no durable in-memory state beyond
	// the event log. On resume/fork the host replays history via Start.History. Runs on
	// any runtime, including a plain pod. Default.
	ResumabilityStatelessReplay Resumability = "STATELESS_REPLAY"
	// ResumabilityRequiresMemorySnapshot: the harness holds in-process state (a REPL, a
	// browser, a long-running process). The host only schedules it on a runtime whose
	// RuntimeCapabilities.MemorySnapshot is true.
	ResumabilityRequiresMemorySnapshot Resumability = "REQUIRES_MEMORY_SNAPSHOT"
)

type Runtime

type Runtime interface {
	// Create starts a cold incarnation (sandbox) for a session and returns a handle
	// including the address where the harness server listens.
	Create(ctx context.Context, s *SessionSpec) (Incarnation, error)

	// Snapshot captures the incarnation's state. SnapshotLocal (warm/pause) keeps it
	// node-resident. SnapshotExternal owns the cold transition: it captures required state,
	// releases dedicated per-incarnation compute where applicable, and preserves the state
	// and any backend handles Restore needs. A backend without memory snapshots may return
	// a filesystem/journal handle; without dedicated per-session compute, its shared harness
	// server may remain running.
	Snapshot(ctx context.Context, in Incarnation, kind SnapshotKind) (SnapshotRef, error)

	// Restore brings an incarnation back from a snapshot. Sub-second on memory-capable
	// backends; a filesystem-only backend restores the workspace and relies on the host
	// replaying the event log.
	Restore(ctx context.Context, ref SnapshotRef) (Incarnation, error)

	// Fork creates a child incarnation. A backend with MemorySnapshot clones ref's captured state so
	// the child continues from the parent's RAM; a filesystem-only backend returns a fresh incarnation
	// and relies on the host replaying the child's copied log prefix. Implementations must not leak a
	// partially-provisioned child: on any failure after the child exists, tear it down before returning.
	// A backend that finds ref no longer held by the parent returns an error wrapping
	// ErrSnapshotSuperseded.
	Fork(ctx context.Context, ref SnapshotRef, opts ForkOpts) (Incarnation, error)

	// Stop is destructive teardown: it destroys the incarnation and frees its dedicated compute.
	// Callers must not assume a captured SnapshotRef remains restorable after Stop.
	Stop(ctx context.Context, in Incarnation) error

	// Status reports the incarnation's compute-lifecycle state.
	Status(ctx context.Context, in Incarnation) (ComputeState, error)

	// Capabilities reports what this backend supports.
	Capabilities() RuntimeCapabilities
}

Runtime is the compute/sandbox SPI. Pod, Kata Pod Sandboxing, Cloud Hypervisor, Dragonball, Hyperlight, and agent-substrate all implement it. There is no gVisor requirement — backends are interchangeable, and the host reads Capabilities to place harnesses and degrade honestly.

This is the seam that lets "different folks on top" (via producer adapters + the Sessions API) run on "substrate underneath" (or pod, Kata, ...) with no API change.

type RuntimeCapabilities

type RuntimeCapabilities struct {
	MemorySnapshot bool // can capture/restore RAM+process (pod: false, kata/clh: true)
	CoWFork        bool // copy-on-write fork
	Attest         bool // attestation on restore (confidential)
	GPUState       bool // accelerator state capture
}

RuntimeCapabilities is what a backend can do. The host matches these against a harness's Capabilities before scheduling.

type Session

type Session struct {
	UID     string
	Project string // tenant / namespace
	Name    string

	Harness string
	Model   string // model-agnostic id, e.g. "azure-openai/gpt-x", "anthropic/..."

	Exec         ExecState    // execution/turn axis (the event-log axis)
	ComputeState ComputeState // incarnation axis
	LastSeq      int64        // event-log cursor = the resume/replay point

	ParentUID string // set iff this session was forked
	ForkSeq   int64  // parent event seq forked at

	Identity IdentityRef
	Compute  *ComputeRef // current incarnation; nil when SUSPENDED/TERMINATED
	Origin   *Origin     // neutral external context; filled by a producer adapter

	Labels      map[string]string
	Annotations map[string]string // free-form adapter metadata (K8s-style)
}

Session is the durable unit: a conversation (event log) plus zero-or-one live compute incarnation. Unifying the two into one resource is what makes fork, provenance, and identity first-class.

type SessionSpec

type SessionSpec struct {
	SessionUID string
	Image      string
	Harness    string
	Identity   IdentityRef
}

SessionSpec is what a Runtime needs to create an incarnation.

type SnapshotKind

type SnapshotKind string

SnapshotKind selects local (warm/pause) vs external (cold/suspend) storage.

const (
	// SnapshotLocal keeps the captured state warm and node-resident.
	SnapshotLocal SnapshotKind = "LOCAL"
	// SnapshotExternal transitions to cold, releasing dedicated compute while retaining restore state.
	SnapshotExternal SnapshotKind = "EXTERNAL"
)

type SnapshotRef

type SnapshotRef struct {
	Local       string // node/handle-local ref, or (filesystem-only) the session handle to replay
	ExternalURI string // external blob (cold/suspend)
	Memory      bool   // RAM/process captured? kata/clh: true, pod: false
	Sealed      bool   // encrypted + attested (confidential)
}

SnapshotRef points at a captured incarnation state. This Go SPI type is the canonical, WIRED representation: Runtime backends produce/consume it, and the durable log carries it inline on the SUSPEND Lifecycle event (api.Lifecycle.Snapshot -> proto Lifecycle.snapshot_* fields). The proto message agentsessions.v1.SnapshotRef (session.proto, used by ComputeRef) is a SEPARATE, not-yet- wired session-status shape — see its TODO. Unlike that oneof, this holds both Local and ExternalURI (a substrate ref sets both).

type Start

type Start struct {
	// ExecutionID identifies this Run on the wire. Modern runs share it with journal events;
	// legacy runs use a session-scoped legacy- compatibility token that is never journaled.
	ExecutionID string
	// SessionUID carries the ControllerFrame session envelope for tool/approval correlation.
	// Model-only callers that do not use that envelope may leave it empty.
	SessionUID    string    `json:",omitempty"`
	Config        []byte    // opaque per-execution config; journaled verbatim and restored on replay/resume
	History       []Event   // every event before this execution's start, also after a memory restore
	Inputs        []Message // invocation inputs; originals are restored on controller replay/resume
	Identity      IdentityContext
	ResumeFromSeq int64 // opaque harness cursor, journaled with Config; distinct from the append CAS cursor
}

Start is the per-execution invocation the host sends to the harness.

type TextPart

type TextPart struct{ Text string }

TextPart is a text content block.

type TokenMinter

type TokenMinter func(ctx context.Context, audience []string) (string, error)

TokenMinter returns a scoped token for a downstream audience.

type ToolCall

type ToolCall struct {
	ID             string
	Tool           string // tool name / MCP method
	Args           map[string]any
	Mediation      Mediation
	IdempotencyKey string // dedups a retried side-effecting call tool-side (§3/I3)
}

ToolCall is a tool invocation. Its shape aligns with an MCP tool call (name + structured arguments) so MCP tools map onto it directly.

type ToolChoice

type ToolChoice struct {
	Mode ToolChoiceMode
	Name string
}

ToolChoice constrains whether and which tool the model calls. An empty Mode is the provider default. Name forces one specific tool and is meaningful only with ToolChoiceRequired.

type ToolChoiceMode

type ToolChoiceMode string

ToolChoiceMode constrains whether the model calls a tool.

const (
	// ToolChoiceAuto: the model decides whether to call a tool.
	ToolChoiceAuto ToolChoiceMode = "AUTO"
	// ToolChoiceNone: the model must not call a tool.
	ToolChoiceNone ToolChoiceMode = "NONE"
	// ToolChoiceRequired: the model must call at least one tool.
	ToolChoiceRequired ToolChoiceMode = "REQUIRED"
)

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	InputSchema map[string]any // JSON Schema object; JSON-shaped values only (see package wire)
}

ToolDefinition is a tool offered to a model on one call, aligned with an MCP Tool. ToolSpec declares a tool and its default mediation to the host; ToolDefinition is what the model sees.

type ToolResult

type ToolResult struct {
	ID           string
	Output       map[string]any
	OutputURI    string // externalized large output (MCP resource_link); else inline Output
	OutputDigest string // content digest of OutputURI target (hash-chain covers externalized bytes)
	IsError      bool
	Error        string
	// Content is the model-facing result (MCP CallToolResult.content). A harness records on the
	// TOOL_RESULT event the same ToolResult it feeds back as a tool_result part, so history rebuilt
	// from the log can give the model what it saw live.
	Content []Part `json:",omitempty"`
	// Additive durable receipt fields are omitted at zero to preserve old model-input hashes.
	Code                ToolResultCode `json:",omitempty"`
	ApprovalRequestSeq  int64          `json:",omitempty"`
	ApprovalDecisionSeq int64          `json:",omitempty"`
	// Approval carries a host decision to a direct sink caller. It is transient: neither Go JSON
	// nor wire conversion includes it in a receipt or model history. The durable decision is a
	// separate APPROVAL_RESULT event; the receipt binds it by sequence above.
	Approval *ApprovalResult `json:"-"`
}

ToolResult is the outcome of a ToolCall.

type ToolResultCode

type ToolResultCode int32

ToolResultCode is the machine-readable receipt status, matching common.proto ToolResult.Code. Zero preserves legacy receipts and also denotes a successful result when IsError is false.

const (
	ToolResultCodeUnspecified    ToolResultCode = 0
	ToolResultCodeApprovalDenied ToolResultCode = 1
	ToolResultCodeExecutorError  ToolResultCode = 2
)

type ToolSpec

type ToolSpec struct {
	Name        string
	Description string
	Mediation   Mediation
}

ToolSpec declares a tool the harness can call and its default mediation.

type Usage

type Usage struct {
	Model           string
	InputTokens     int64
	OutputTokens    int64
	ReasoningTokens int64
}

Usage is per-model-call token/cost accounting.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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