agentharness

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package agentharness exposes the host/UI durable conversation API.

AgentHarness owns durable threads backed by sessiontree.Repo. Thread.Run, Thread.Retry, Thread.MoveTo, and Thread.Compact are safe to call concurrently across different ThreadIDs, including source and forked threads. A single durable ThreadID admits at most one active turn or mutation at a time; callers that race the same thread receive ErrActiveTurn before new turn entries are appended. This serialization is enforced through the repository turn lease contract when the repo implements sessiontree.TurnLeaseRepo, so two harnesses sharing one durable repo observe the same active-turn invariant.

The lower-level engine remains a turn executor. Harness callers configure engine behavior through TurnPolicy and LoopLimits rather than raw engine.Options so run identity, provider/model identity, and control tool definitions are generated by the harness for the active durable thread.

Thread.Read returns the host-facing snapshot: lifecycle status, appendability, retry availability, and display messages. Thread.Journal is the explicit raw session-tree inspection API for tests, debug consoles, and admin tooling.

Index

Constants

View Source
const (
	DefaultSubAgentWaitTimeout = 5 * time.Minute
	MaxSubAgentWaitTimeout     = 20 * time.Minute
	DefaultSubAgentRunTimeout  = 20 * time.Minute
	MaxSubAgentRunTimeout      = 20 * time.Minute
	DefaultSubAgentDetailLimit = 200
	MaxSubAgentDetailLimit     = 500

	DefaultThreadDetailEventLimit = DefaultSubAgentDetailLimit
	MaxThreadDetailEventLimit     = MaxSubAgentDetailLimit
)
View Source
const ThreadTitleLogicalRequestID = "thread_title"

Variables

View Source
var (
	ErrEffectUnauthorized        = errors.New("effect is unauthorized")
	ErrAuthorizationUnavailable  = errors.New("effect authorization is unavailable")
	ErrInvalidAuthorizationProof = errors.New("effect authorization proof is invalid")
	ErrEffectDispatchConsumed    = errors.New("authorized effect dispatch was already consumed")
	ErrAuthorizationContract     = errors.New("effect authorization gate contract failed")
)
View Source
var (
	ErrActiveTurn                              = errors.New("thread already has an active turn")
	ErrNoRetryTarget                           = errors.New("thread has no retryable turn")
	ErrPendingToolSettlementTargetTurnNotFound = errors.New("pending tool settlement target turn was not found")
	ErrPendingToolSettlementTargetRunNotFound  = errors.New("pending tool settlement target run was not found")
	ErrPendingToolSettlementTargetToolNotFound = errors.New("pending tool settlement target tool call was not found")
	ErrPendingToolSettlementTargetNotActive    = errors.New("pending tool settlement target is not an active pending tool result")
	ErrPendingToolSettlementConflict           = errors.New("pending tool settlement conflicts with existing settlement")
	ErrForkOperationConflict                   = errors.New("fork operation conflicts with existing request")
	ErrJournalInvariant                        = errors.New("thread journal invariant violated")
)
View Source
var (
	ErrSubAgentNotFound = errors.New("subagent not found")
	ErrSubAgentClosed   = errors.New("subagent is closed")
)

Functions

This section is empty.

Types

type AgentHarness

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

func New

func New(options Options) *AgentHarness

func (*AgentHarness) BindCreatedRoot

func (h *AgentHarness) BindCreatedRoot(meta sessiontree.ThreadMeta, replayed bool) (*Thread, error)

BindCreatedRoot attaches the harness cache to a root already committed by the storage authority kernel. It never creates or repairs canonical state.

func (*AgentHarness) CloseSubAgent

func (h *AgentHarness) CloseSubAgent(ctx context.Context, opts CloseSubAgentOptions) (SubAgentSnapshot, error)

func (*AgentHarness) ForkThread

func (h *AgentHarness) ForkThread(ctx context.Context, opts ForkOptions) (*Thread, error)

func (*AgentHarness) ForkThreadWithResult

func (h *AgentHarness) ForkThreadWithResult(ctx context.Context, opts ForkOptions) (ForkResult, error)

func (*AgentHarness) ListCanonicalTurnDetailEvents

func (h *AgentHarness) ListCanonicalTurnDetailEvents(ctx context.Context, opts sessiontree.ListCanonicalTurnsOptions, includeRaw bool) (CanonicalTurnDetailsPage, error)

func (*AgentHarness) ListPendingToolSettlementTargets

func (h *AgentHarness) ListPendingToolSettlementTargets(ctx context.Context, threadID string) ([]sessiontree.PendingToolSettlementTarget, error)

ListPendingToolSettlementTargets returns every active pending tool target on the thread's canonical path. It intentionally does not use detail-event projections, whose pagination and sanitization are presentation concerns.

func (*AgentHarness) ListRootThreadSummaries

func (h *AgentHarness) ListRootThreadSummaries(ctx context.Context, opts ListRootThreadSummariesOptions) ([]ThreadSummary, error)

func (*AgentHarness) ListSubAgentPendingToolSettlementTargets

func (h *AgentHarness) ListSubAgentPendingToolSettlementTargets(ctx context.Context, parentThreadID, childThreadID string) ([]sessiontree.PendingToolSettlementTarget, error)

ListSubAgentPendingToolSettlementTargets returns canonical pending targets for one direct child of the supplied parent.

func (*AgentHarness) ListSubAgents

func (h *AgentHarness) ListSubAgents(ctx context.Context, parentThreadID string) ([]SubAgentSnapshot, error)

func (*AgentHarness) ListThreadDetailEvents

func (h *AgentHarness) ListThreadDetailEvents(ctx context.Context, opts ListThreadDetailEventsOptions) (ThreadDetailEvents, error)

func (*AgentHarness) OwnedActiveThread

func (h *AgentHarness) OwnedActiveThread(ctx context.Context, id, turnID string) (*Thread, sessiontree.TurnLease, bool, error)

OwnedActiveThread returns a cached thread only when its in-process owner and the durable turn lease are the same exact authority generation.

func (*AgentHarness) PublishSubAgentPendingToolCompletion

func (h *AgentHarness) PublishSubAgentPendingToolCompletion(ctx context.Context, opts PublishSubAgentPendingToolCompletionOptions) (SubAgentSnapshot, error)

func (*AgentHarness) ReadApprovalQueue

func (*AgentHarness) ReadCanonicalTurnDetailEvents

func (h *AgentHarness) ReadCanonicalTurnDetailEvents(ctx context.Context, threadID, turnID string, includeRaw bool) (CanonicalTurnDetailRead, error)

func (*AgentHarness) ReadLatestThreadDetailEvents

func (h *AgentHarness) ReadLatestThreadDetailEvents(ctx context.Context, threadID string, includeRaw bool) (ThreadDetailEvents, error)

ReadLatestThreadDetailEvents reads only the active-path entries required to project the latest admitted turn. It walks backwards until it has the latest started marker and the canonical user input used by that turn.

func (*AgentHarness) ReadSubAgentDetail

func (h *AgentHarness) ReadSubAgentDetail(ctx context.Context, opts ReadSubAgentDetailOptions) (SubAgentDetail, error)

func (*AgentHarness) ReadThread

func (h *AgentHarness) ReadThread(ctx context.Context, id string) (ThreadSnapshot, error)

func (*AgentHarness) ReadThreadContext

func (h *AgentHarness) ReadThreadContext(ctx context.Context, threadID string) (ThreadContextSnapshot, error)

func (*AgentHarness) ReadThreadOverview

func (h *AgentHarness) ReadThreadOverview(ctx context.Context, id string) (ThreadOverview, error)

func (*AgentHarness) ReadTurnDetailEvents

func (h *AgentHarness) ReadTurnDetailEvents(ctx context.Context, threadID, turnID, runID string, includeRaw bool) (ThreadDetailEvents, bool, error)

func (*AgentHarness) RecoverInterruptedTurn

func (*AgentHarness) RecoverPendingAutomaticThreadTitles

func (h *AgentHarness) RecoverPendingAutomaticThreadTitles(ctx context.Context) error

func (*AgentHarness) ResolveApproval

func (*AgentHarness) ResumeThread

func (h *AgentHarness) ResumeThread(ctx context.Context, id string, _ ResumeOptions) (*Thread, error)

func (*AgentHarness) SendSubAgentInput

func (h *AgentHarness) SendSubAgentInput(ctx context.Context, opts SendSubAgentInputOptions) (SubAgentSnapshot, error)

func (*AgentHarness) SetThreadTitle

func (h *AgentHarness) SetThreadTitle(ctx context.Context, id, rawTitle string) (ThreadSnapshot, error)

func (*AgentHarness) SpawnSubAgent

func (h *AgentHarness) SpawnSubAgent(ctx context.Context, opts SpawnSubAgentOptions) (SubAgentSnapshot, error)

func (*AgentHarness) ValidateSubAgentAuthority

func (h *AgentHarness) ValidateSubAgentAuthority(ctx context.Context, parentThreadID, childThreadID string) error

func (*AgentHarness) ValidateSubAgentDescendantAuthority

func (h *AgentHarness) ValidateSubAgentDescendantAuthority(ctx context.Context, parentThreadID, childThreadID string) error

func (*AgentHarness) WaitSubAgents

type ApprovalQueueSnapshot

type ApprovalQueueSnapshot struct {
	RootThreadID      string           `json:"root_thread_id"`
	Generation        int64            `json:"generation"`
	Revision          int64            `json:"revision"`
	CurrentApprovalID string           `json:"current_approval_id,omitempty"`
	Approvals         []ApprovalRecord `json:"approvals"`
	GeneratedAt       time.Time        `json:"generated_at"`
}

type ApprovalRecord

type ApprovalRecord struct {
	ApprovalID             string             `json:"approval_id,omitempty"`
	RootThreadID           string             `json:"root_thread_id,omitempty"`
	ParentThreadID         string             `json:"parent_thread_id,omitempty"`
	ToolCallID             string             `json:"tool_call_id,omitempty"`
	EffectAttemptID        string             `json:"effect_attempt_id,omitempty"`
	ToolName               string             `json:"tool_name,omitempty"`
	ToolKind               string             `json:"tool_kind,omitempty"`
	RunID                  string             `json:"run_id,omitempty"`
	ThreadID               string             `json:"thread_id,omitempty"`
	TurnID                 string             `json:"turn_id,omitempty"`
	Step                   int                `json:"step,omitempty"`
	BatchIndex             int                `json:"batch_index"`
	BatchSize              int                `json:"batch_size"`
	State                  string             `json:"state,omitempty"`
	Revision               int64              `json:"revision,omitempty"`
	QueueSequence          int64              `json:"queue_sequence,omitempty"`
	DecisionID             string             `json:"decision_id,omitempty"`
	RequestedAt            time.Time          `json:"requested_at,omitempty"`
	UpdatedAt              time.Time          `json:"updated_at,omitempty"`
	ResolvedAt             time.Time          `json:"resolved_at,omitempty"`
	ArgsHash               string             `json:"args_hash,omitempty"`
	RequestFingerprint     string             `json:"request_fingerprint,omitempty"`
	AuthorizationProofHash string             `json:"authorization_proof_hash,omitempty"`
	Resources              []ApprovalResource `json:"resources,omitempty"`
	Effects                []string           `json:"effects,omitempty"`
	Labels                 map[string]string  `json:"labels,omitempty"`
	HostContext            map[string]string  `json:"host_context,omitempty"`
	ReadOnly               bool               `json:"read_only,omitempty"`
	Destructive            bool               `json:"destructive,omitempty"`
	OpenWorld              bool               `json:"open_world,omitempty"`
	Reason                 string             `json:"reason,omitempty"`
}

type ApprovalResource

type ApprovalResource struct {
	Kind  string `json:"kind,omitempty"`
	Value string `json:"value,omitempty"`
}

type AuthorizedEffect

AuthorizedEffect crosses the canonical effect boundary under the execution context selected by the host authorization gate.

type CanonicalTurnDetail

type CanonicalTurnDetail struct {
	TurnID         string
	RunID          string
	StartedOrdinal int64
	RetrySource    *sessiontree.CanonicalTurnRetrySource
	Events         []SubAgentDetailEvent
}

type CanonicalTurnDetailRead

type CanonicalTurnDetailRead struct {
	Turn              CanonicalTurnDetail
	ThroughOrdinal    int64
	LatestTurnID      string
	LatestStatus      string
	LatestRecoverable bool
	LatestCanRetry    bool
}

type CanonicalTurnDetailsPage

type CanonicalTurnDetailsPage struct {
	Turns             []CanonicalTurnDetail
	BeforeCursor      *sessiontree.CanonicalTurnBeforeCursor
	SinceCursor       sessiontree.CanonicalTurnSinceCursor
	HasMore           bool
	ThroughOrdinal    int64
	LatestTurnID      string
	LatestStatus      string
	LatestRecoverable bool
	LatestCanRetry    bool
	GeneratedAt       time.Time
}

type CloseSubAgentOptions

type CloseSubAgentOptions struct {
	CloseOperationID string
	ParentThreadID   string
	ChildThreadID    string
	Reason           string
}

type CommittedEffectError

type CommittedEffectError struct {
	EffectAttemptID string
	Err             error
}

func (*CommittedEffectError) Error

func (e *CommittedEffectError) Error() string

func (*CommittedEffectError) Unwrap

func (e *CommittedEffectError) Unwrap() error

type CompactOptions

type CompactOptions struct {
	RequestID              string
	Source                 string
	Labels                 engine.RunLabels
	Reasoning              provider.ReasoningSelection
	MaxInputTokens         int64
	MaxTotalTokens         int64
	MaxCostUSD             float64
	MaxToolCalls           int
	MaxLengthContinuations int
	Sink                   event.Sink
}

type CompactResult

type CompactResult struct {
	RunID       string
	OperationID string
	RequestID   string
	Source      string
	Status      engine.Status
	Err         error
	Diagnostics map[string]string
	Metrics     engine.RunMetrics
	Entry       *sessiontree.Entry
	Replayed    bool
}

type EffectAuthorizationGate

type EffectAuthorizationGate interface {
	Dispatch(context.Context, EffectAuthorizationRequest, AuthorizedEffect) (EffectDispatchResult, error)
}

type EffectAuthorizationProof

type EffectAuthorizationProof struct {
	EffectAttemptID    string
	RequestFingerprint string
	ThreadID           string
	TurnID             string
	RunID              string
	ToolCallID         string
	LeaseOwnerID       string
	LeaseGeneration    int64
	PolicyRevision     string
	ApprovalID         string
	AuditReference     string
	AuditHash          string
	AuthorizedAt       time.Time
}

type EffectAuthorizationRequest

type EffectAuthorizationRequest struct {
	EffectAttemptID    string
	RequestFingerprint string
	ThreadID           string
	TurnID             string
	RunID              string
	ToolCallID         string
	ToolName           string
	ArgumentHash       string
	Step               int
	BatchIndex         int
	BatchSize          int
	Labels             map[string]string
	HostContext        map[string]string
	Resources          []tools.ResourceRef
	Effects            []tools.Effect
	Permission         tools.PermissionSpec
	ReadOnly           bool
	Destructive        bool
	OpenWorld          bool
	LeaseOwnerID       string
	LeaseGeneration    int64
	ObservedHeartbeat  int64
}

type EffectDispatchResult

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

type ForkOptions

type ForkOptions struct {
	SourceThreadID string
	EntryID        string
	Position       sessiontree.ForkPosition
	NewThreadID    string
	OperationID    string
}

type ForkResult

type ForkResult struct {
	OperationID string
	Thread      *Thread
	Summary     ThreadSummary
}

type HarnessEvent

type HarnessEvent struct {
	Type      HarnessEventType  `json:"type"`
	RunID     string            `json:"run_id,omitempty"`
	ThreadID  string            `json:"thread_id,omitempty"`
	TurnID    string            `json:"turn_id,omitempty"`
	EntryID   string            `json:"entry_id,omitempty"`
	ParentID  string            `json:"parent_id,omitempty"`
	Message   string            `json:"message,omitempty"`
	Status    string            `json:"status,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
	Timestamp time.Time         `json:"timestamp"`
}

type HarnessEventType

type HarnessEventType string
const (
	EventThreadStarted     HarnessEventType = "thread_started"
	EventThreadForked      HarnessEventType = "thread_forked"
	EventTurnStarted       HarnessEventType = "turn_started"
	EventTurnCompleted     HarnessEventType = "turn_completed"
	EventTurnFailed        HarnessEventType = "turn_failed"
	EventTurnAborted       HarnessEventType = "turn_aborted"
	EventEntryAppended     HarnessEventType = "entry_appended"
	EventRetryStarted      HarnessEventType = "retry_started"
	EventTitlePending      HarnessEventType = "thread_title_pending"
	EventTitleUpdated      HarnessEventType = "thread_title_updated"
	EventTitleFailed       HarnessEventType = "thread_title_failed"
	EventSubAgentSpawned   HarnessEventType = "subagent_spawned"
	EventSubAgentInput     HarnessEventType = "subagent_input"
	EventSubAgentClosed    HarnessEventType = "subagent_closed"
	EventSubAgentCompleted HarnessEventType = "subagent_completed"
)

type HarnessRecorder

type HarnessRecorder struct {
	Events []HarnessEvent
	// contains filtered or unexported fields
}

func (*HarnessRecorder) EmitHarness

func (r *HarnessRecorder) EmitHarness(ev HarnessEvent)

func (*HarnessRecorder) Snapshot

func (r *HarnessRecorder) Snapshot() []HarnessEvent

type HarnessSink

type HarnessSink interface {
	EmitHarness(HarnessEvent)
}

type ListRootThreadSummariesOptions

type ListRootThreadSummariesOptions struct {
	Limit          int
	AfterCreatedAt time.Time
	AfterID        string
}

type ListThreadDetailEventsOptions

type ListThreadDetailEventsOptions struct {
	ThreadID     string
	AfterOrdinal int64
	Limit        int
	IncludeRaw   bool
}

type LoopLimits

type LoopLimits struct {
	MaxEmptyProviderRetries  int
	NoProgressLimit          int
	DuplicateToolLimit       int
	WallTime                 time.Duration
	MaxInputTokens           int64
	MaxTotalTokens           int64
	MaxCostUSD               float64
	MaxToolCalls             int
	MaxLengthContinuations   int
	MaxStopHookContinuations int
}

type Options

type Options struct {
	Provider                 provider.Provider
	ProviderName             string
	Model                    string
	SystemPrompt             string
	Tools                    *tools.Registry
	PromptStore              cache.Store
	Repo                     sessiontree.JournalRepo
	ForkOperations           storage.ForkOperationStore
	StateCompatibilityKey    string
	Sink                     event.Sink
	SinkPolicy               event.SinkPolicy
	HarnessSink              HarnessSink
	EffectAuthorizationGate  EffectAuthorizationGate
	ToolSurfaceProvider      engine.ToolSurfaceProvider
	StopHook                 engine.StopHook
	CompactionGenerator      compaction.SummaryGenerator
	CompactionPrompt         compaction.PromptOptions
	CompactionPromptIdentity string
	TitleGenerator           TitleGenerator
	Reasoning                provider.ReasoningCapability
	TurnPolicy               TurnPolicy
	LoopLimits               LoopLimits
	SubAgentRunTimeout       time.Duration
	AutomaticTitleTimeout    time.Duration
	BeginBackgroundExecution func() (context.Context, func(), error)
	ReportBackgroundError    func(error)
	TurnExecutions           *TurnExecutionRegistry
	NewID                    func(string) string
	Now                      func() time.Time
}

type PendingToolCompletion

type PendingToolCompletion struct {
	CompletionRequestID string
	Target              sessiontree.PendingToolSettlementTarget
	ContinuationTurnID  string
	ContinuationRunID   string
	Status              PendingToolCompletionStatus
	Summary             string
	Output              string
	Input               session.Message
	Labels              engine.RunLabels
}

type PendingToolCompletionStatus

type PendingToolCompletionStatus string
const (
	PendingToolCompleted PendingToolCompletionStatus = "completed"
	PendingToolFailed    PendingToolCompletionStatus = "failed"
	PendingToolCanceled  PendingToolCompletionStatus = "canceled"
)

type PendingToolSettlement

type PendingToolSettlement struct {
	TurnID          string
	RunID           string
	ToolCallID      string
	ToolName        string
	Handle          string
	EffectAttemptID string
	Status          PendingToolSettlementStatus
	Summary         string
	Output          string
	Activity        *observation.ActivityPresentation
}

type PendingToolSettlementStatus

type PendingToolSettlementStatus string
const (
	PendingToolSettledCompleted PendingToolSettlementStatus = "completed"
	PendingToolSettledFailed    PendingToolSettlementStatus = "failed"
	PendingToolSettledCanceled  PendingToolSettlementStatus = "canceled"
)

type ProviderTitleGenerator

type ProviderTitleGenerator struct {
	Provider        provider.Provider
	ProviderName    string
	Model           string
	Reasoning       provider.ReasoningCapability
	MaxRunes        int
	MaxOutputTokens int64
}

func (ProviderTitleGenerator) GenerateTitle

func (g ProviderTitleGenerator) GenerateTitle(ctx context.Context, req TitleRequest) (TitleResult, error)

type PublishSubAgentPendingToolCompletionOptions

type PublishSubAgentPendingToolCompletionOptions struct {
	InputRequestID string
	ParentThreadID string
	ChildThreadID  string
	Target         sessiontree.PendingToolSettlementTarget
	Status         PendingToolCompletionStatus
	Summary        string
	Output         string
	Message        string
	Attachments    []session.MessageAttachment
	References     []session.MessageReference
	Labels         engine.RunLabels
}

type ReadApprovalQueueOptions

type ReadApprovalQueueOptions struct {
	ThreadID string
}

type ReadSubAgentDetailOptions

type ReadSubAgentDetailOptions struct {
	ParentThreadID string
	ChildThreadID  string
	AfterOrdinal   int64
	Limit          int
	IncludeRaw     bool
}

type RecoverInterruptedTurnOptions

type RecoverInterruptedTurnOptions struct {
	ThreadID       string
	ParentThreadID string
	ExpectedLease  sessiontree.TurnLease
}

type RecoverInterruptedTurnResult

type RecoverInterruptedTurnResult struct {
	ThreadID string
	TurnID   string
	RunID    string
	Status   sessiontree.TurnMarkerStatus
	Replayed bool
	Terminal sessiontree.Entry
}

type ResolveApprovalOptions

type ResolveApprovalOptions struct {
	DecisionID               string
	ExpectedRootThreadID     string
	ExpectedGeneration       int64
	ExpectedRevision         int64
	ExpectedCurrent          sessiontree.ApprovalIdentity
	ExpectedApprovalRevision int64
	Decision                 sessiontree.ApprovalDecision
}

type ResolveApprovalResult

type ResolveApprovalResult struct {
	Receipt  sessiontree.ApprovalDecisionReceipt
	Queue    ApprovalQueueSnapshot
	Approval ApprovalRecord
	Replayed bool
}

type ResumeOptions

type ResumeOptions struct{}

type RetryOptions

type RetryOptions struct {
	Reason string
	Labels engine.RunLabels
}

type RunOptions

type RunOptions struct {
	RunID                    string
	TurnID                   string
	AdmittedInputID          string
	AdmissionCommitted       bool
	AdmissionBaseLeafID      string
	Labels                   engine.RunLabels
	TerminalMetadata         map[string]string
	DeadlineMetadata         map[string]string
	CompletionPolicy         engine.CompletionPolicy
	ControlSpec              engine.ControlSpec
	Reasoning                provider.ReasoningSelection
	MaxInputTokens           int64
	MaxTotalTokens           int64
	MaxCostUSD               float64
	MaxToolCalls             int
	MaxLengthContinuations   int
	MaxStopHookContinuations int
	ManualCompactions        engine.ManualCompactionSource
	ToolSurfaceProvider      engine.ToolSurfaceProvider
	SupplementalContext      []engine.TurnSupplementalContextItem
	Attachments              []session.MessageAttachment
	References               []session.MessageReference
	Sink                     event.Sink
}

type SendSubAgentInputOptions

type SendSubAgentInputOptions struct {
	InputRequestID string
	ParentThreadID string
	ChildThreadID  string
	Message        string
	Attachments    []session.MessageAttachment
	References     []session.MessageReference
	Interrupt      bool
	Labels         engine.RunLabels
}

type SpawnSubAgentOptions

type SpawnSubAgentOptions struct {
	PublicationID   string
	ParentThreadID  string
	ParentTurnID    string
	ThreadID        string
	TaskName        string
	TaskDescription string
	Message         string
	Attachments     []session.MessageAttachment
	References      []session.MessageReference
	HostProfileRef  string
	ForkMode        SubAgentForkMode
	Labels          engine.RunLabels
}

type SubAgentDetail

type SubAgentDetail struct {
	Snapshot         SubAgentSnapshot             `json:"snapshot"`
	Events           []SubAgentDetailEvent        `json:"events"`
	ActivityTimeline observation.ActivityTimeline `json:"activity_timeline"`
	Context          ThreadContextSnapshot        `json:"context,omitempty"`
	NextOrdinal      int64                        `json:"next_ordinal,omitempty"`
	HasMore          bool                         `json:"has_more,omitempty"`
	RetainedFrom     int64                        `json:"retained_from,omitempty"`
	GeneratedAt      time.Time                    `json:"generated_at"`
}

type SubAgentDetailApproval

type SubAgentDetailApproval struct {
	State    string            `json:"state,omitempty"`
	ToolID   string            `json:"tool_id,omitempty"`
	ToolName string            `json:"tool_name,omitempty"`
	ToolKind string            `json:"tool_kind,omitempty"`
	ArgsHash string            `json:"args_hash,omitempty"`
	Reason   string            `json:"reason,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type SubAgentDetailCompaction

type SubAgentDetailCompaction struct {
	OperationID             string            `json:"operation_id,omitempty"`
	RequestID               string            `json:"request_id,omitempty"`
	Source                  string            `json:"source,omitempty"`
	CompactionID            string            `json:"compaction_id,omitempty"`
	PreviousCompactionID    string            `json:"previous_compaction_id,omitempty"`
	CompactedThroughEntryID string            `json:"compacted_through_entry_id,omitempty"`
	SummarySchemaVersion    string            `json:"summary_schema_version,omitempty"`
	CompactionGeneration    int               `json:"compaction_generation,omitempty"`
	CompactionWindowID      string            `json:"compaction_window_id,omitempty"`
	FirstKeptEntryID        string            `json:"first_kept_entry_id,omitempty"`
	KeptUserEntryIDs        []string          `json:"kept_user_entry_ids,omitempty"`
	Summary                 string            `json:"summary,omitempty"`
	Trigger                 string            `json:"trigger,omitempty"`
	Reason                  string            `json:"reason,omitempty"`
	Phase                   string            `json:"phase,omitempty"`
	TokensBefore            int64             `json:"tokens_before,omitempty"`
	TokensAfterEstimate     int64             `json:"tokens_after_estimate,omitempty"`
	Metadata                map[string]string `json:"metadata,omitempty"`
}

type SubAgentDetailControlSignal

type SubAgentDetailControlSignal struct {
	Name        string         `json:"name,omitempty"`
	CallID      string         `json:"call_id,omitempty"`
	Disposition string         `json:"disposition,omitempty"`
	Text        string         `json:"text,omitempty"`
	ArgsHash    string         `json:"args_hash,omitempty"`
	Payload     map[string]any `json:"payload,omitempty"`
}

type SubAgentDetailEvent

type SubAgentDetailEvent struct {
	ID        string                  `json:"id"`
	Ordinal   int64                   `json:"ordinal"`
	ParentID  string                  `json:"parent_id,omitempty"`
	ThreadID  string                  `json:"thread_id"`
	TurnID    string                  `json:"turn_id,omitempty"`
	Kind      SubAgentDetailEventKind `json:"kind"`
	Type      string                  `json:"type,omitempty"`
	CreatedAt time.Time               `json:"created_at"`

	Message    *SubAgentDetailMessage    `json:"message,omitempty"`
	ToolCall   *SubAgentDetailToolCall   `json:"tool_call,omitempty"`
	ToolResult *SubAgentDetailToolResult `json:"tool_result,omitempty"`
	Approval   *SubAgentDetailApproval   `json:"approval,omitempty"`
	TurnMarker *SubAgentDetailTurnMarker `json:"turn_marker,omitempty"`
	Compaction *SubAgentDetailCompaction `json:"compaction,omitempty"`
	Error      string                    `json:"error,omitempty"`
	Metadata   map[string]string         `json:"metadata,omitempty"`

	ActivityTimeline *observation.ActivityTimeline `json:"activity_timeline,omitempty"`
}

type SubAgentDetailEventKind

type SubAgentDetailEventKind string
const (
	SubAgentDetailEventUserMessage      SubAgentDetailEventKind = "user_message"
	SubAgentDetailEventAssistantMessage SubAgentDetailEventKind = "assistant_message"
	SubAgentDetailEventToolCall         SubAgentDetailEventKind = "tool_call"
	SubAgentDetailEventToolDispatch     SubAgentDetailEventKind = "tool_dispatch"
	SubAgentDetailEventToolActivity     SubAgentDetailEventKind = "tool_activity"
	SubAgentDetailEventToolResult       SubAgentDetailEventKind = "tool_result"
	SubAgentDetailEventTurnMarker       SubAgentDetailEventKind = "turn_marker"
	SubAgentDetailEventCompaction       SubAgentDetailEventKind = "compaction"
	SubAgentDetailEventError            SubAgentDetailEventKind = "error"
	SubAgentDetailEventApproval         SubAgentDetailEventKind = "approval"
	SubAgentDetailEventCustom           SubAgentDetailEventKind = "custom"
)

type SubAgentDetailMessage

type SubAgentDetailMessage struct {
	Role        string                            `json:"role,omitempty"`
	Kind        string                            `json:"kind,omitempty"`
	Preview     string                            `json:"preview,omitempty"`
	Content     string                            `json:"content,omitempty"`
	Attachments []session.MessageAttachment       `json:"attachments,omitempty"`
	References  []session.MessageReference        `json:"references,omitempty"`
	Reasoning   string                            `json:"reasoning,omitempty"`
	Activity    *observation.ActivityPresentation `json:"activity,omitempty"`
}

type SubAgentDetailToolCall

type SubAgentDetailToolCall struct {
	ID            string                       `json:"id,omitempty"`
	Name          string                       `json:"name,omitempty"`
	ArgsPreview   string                       `json:"args_preview,omitempty"`
	ArgsJSON      string                       `json:"args_json,omitempty"`
	ArgsHash      string                       `json:"args_hash,omitempty"`
	ControlSignal *SubAgentDetailControlSignal `json:"control_signal,omitempty"`
}

type SubAgentDetailToolResult

type SubAgentDetailToolResult struct {
	CallID          string        `json:"call_id,omitempty"`
	ToolName        string        `json:"tool_name,omitempty"`
	EffectAttemptID string        `json:"effect_attempt_id,omitempty"`
	Status          string        `json:"status,omitempty"`
	Preview         string        `json:"preview,omitempty"`
	Content         string        `json:"content,omitempty"`
	Truncated       bool          `json:"truncated,omitempty"`
	OriginalBytes   int           `json:"original_bytes,omitempty"`
	VisibleBytes    int           `json:"visible_bytes,omitempty"`
	OriginalLines   int           `json:"original_lines,omitempty"`
	VisibleLines    int           `json:"visible_lines,omitempty"`
	Strategy        string        `json:"strategy,omitempty"`
	ContentSHA256   string        `json:"content_sha256,omitempty"`
	FullOutput      *artifact.Ref `json:"full_output,omitempty"`
}

type SubAgentDetailTurnMarker

type SubAgentDetailTurnMarker struct {
	Status   string            `json:"status,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type SubAgentForkMode

type SubAgentForkMode string
const (
	SubAgentForkNone     SubAgentForkMode = "none"
	SubAgentForkFullPath SubAgentForkMode = "full_path"
)

type SubAgentSnapshot

type SubAgentSnapshot struct {
	ThreadID        string           `json:"thread_id"`
	Path            string           `json:"path"`
	TaskName        string           `json:"task_name"`
	TaskDescription string           `json:"task_description,omitempty"`
	ParentThreadID  string           `json:"parent_thread_id"`
	ParentTurnID    string           `json:"parent_turn_id,omitempty"`
	HostProfileRef  string           `json:"host_profile_ref,omitempty"`
	ForkMode        SubAgentForkMode `json:"fork_mode,omitempty"`
	Status          SubAgentStatus   `json:"status"`
	LatestTurnID    string           `json:"latest_turn_id,omitempty"`
	LastMessage     string           `json:"last_message,omitempty"`
	WaitingPrompt   string           `json:"waiting_prompt,omitempty"`
	QueuedInputs    int              `json:"queued_inputs,omitempty"`
	CreatedAt       time.Time        `json:"created_at"`
	UpdatedAt       time.Time        `json:"updated_at"`
	Closed          bool             `json:"closed,omitempty"`
	CanSendInput    bool             `json:"can_send_input"`
	CanInterrupt    bool             `json:"can_interrupt"`
	CanClose        bool             `json:"can_close"`
}

type SubAgentStatus

type SubAgentStatus string
const (
	SubAgentStatusIdle        SubAgentStatus = "idle"
	SubAgentStatusRunning     SubAgentStatus = "running"
	SubAgentStatusWaiting     SubAgentStatus = "waiting"
	SubAgentStatusCompleted   SubAgentStatus = "completed"
	SubAgentStatusFailed      SubAgentStatus = "failed"
	SubAgentStatusCancelled   SubAgentStatus = "cancelled"
	SubAgentStatusInterrupted SubAgentStatus = "interrupted"
	SubAgentStatusClosing     SubAgentStatus = "closing"
	SubAgentStatusClosed      SubAgentStatus = "closed"
)

type Thread

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

func (*Thread) Compact

func (t *Thread) Compact(ctx context.Context, opts CompactOptions) (CompactResult, error)

func (*Thread) CompletePendingTool

func (t *Thread) CompletePendingTool(ctx context.Context, completion PendingToolCompletion) (TurnResult, error)

func (*Thread) ID

func (t *Thread) ID() string

func (*Thread) Journal

func (t *Thread) Journal(ctx context.Context) (ThreadJournalSnapshot, error)

func (*Thread) Read

func (t *Thread) Read(ctx context.Context) (ThreadSnapshot, error)

func (*Thread) Retry

func (t *Thread) Retry(ctx context.Context, opts RetryOptions) (TurnResult, error)

func (*Thread) Run

func (t *Thread) Run(ctx context.Context, input string, opts RunOptions) (TurnResult, error)

func (*Thread) SettlePendingTool

func (t *Thread) SettlePendingTool(ctx context.Context, settlement PendingToolSettlement) (SubAgentDetailEvent, error)

func (*Thread) SettlePendingToolActive

func (t *Thread) SettlePendingToolActive(ctx context.Context, settlement PendingToolSettlement, lease sessiontree.TurnLease) (SubAgentDetailEvent, error)

func (*Thread) Summary

func (t *Thread) Summary(ctx context.Context) (ThreadSummary, error)

type ThreadContextCompaction

type ThreadContextCompaction struct {
	RunID               string    `json:"run_id,omitempty"`
	ThreadID            string    `json:"thread_id,omitempty"`
	TurnID              string    `json:"turn_id,omitempty"`
	Step                int       `json:"step,omitempty"`
	OperationID         string    `json:"operation_id,omitempty"`
	RequestID           string    `json:"request_id,omitempty"`
	Phase               string    `json:"phase,omitempty"`
	Status              string    `json:"status,omitempty"`
	Trigger             string    `json:"trigger,omitempty"`
	Reason              string    `json:"reason,omitempty"`
	Source              string    `json:"source,omitempty"`
	TokensBefore        int64     `json:"tokens_before,omitempty"`
	TokensAfterEstimate int64     `json:"tokens_after_estimate,omitempty"`
	Error               string    `json:"error,omitempty"`
	ObservedAt          time.Time `json:"observed_at,omitempty"`
}

type ThreadContextModel

type ThreadContextModel struct {
	Provider string `json:"provider,omitempty"`
	Model    string `json:"model,omitempty"`
}

type ThreadContextPolicy

type ThreadContextPolicy struct {
	ContextWindowTokens  int64 `json:"context_window_tokens,omitempty"`
	MaxOutputTokens      int64 `json:"max_output_tokens,omitempty"`
	ReservedOutputTokens int64 `json:"reserved_output_tokens,omitempty"`
}

type ThreadContextSnapshot

type ThreadContextSnapshot struct {
	Model       ThreadContextModel         `json:"model,omitempty"`
	Policy      ThreadContextPolicy        `json:"policy,omitempty"`
	Usage       *observation.ContextStatus `json:"usage,omitempty"`
	Compactions []ThreadContextCompaction  `json:"compactions,omitempty"`
	UpdatedAt   time.Time                  `json:"updated_at,omitempty"`
}

type ThreadDetailEvents

type ThreadDetailEvents struct {
	Events       []SubAgentDetailEvent `json:"events"`
	NextOrdinal  int64                 `json:"next_ordinal,omitempty"`
	HasMore      bool                  `json:"has_more,omitempty"`
	RetainedFrom int64                 `json:"retained_from,omitempty"`
	GeneratedAt  time.Time             `json:"generated_at"`
}

type ThreadJournalSnapshot

type ThreadJournalSnapshot struct {
	Meta    sessiontree.ThreadMeta `json:"meta"`
	Path    []sessiontree.Entry    `json:"path"`
	Entries []sessiontree.Entry    `json:"entries"`
	Context []session.Message      `json:"context"`
	Phase   string                 `json:"phase"`
}

type ThreadMessage

type ThreadMessage struct {
	Role        session.Role                `json:"role"`
	Content     string                      `json:"content"`
	Attachments []session.MessageAttachment `json:"attachments,omitempty"`
	References  []session.MessageReference  `json:"references,omitempty"`
	TurnID      string                      `json:"turn_id,omitempty"`
	CreatedAt   time.Time                   `json:"created_at"`
}

type ThreadOverview

type ThreadOverview struct {
	Thread     ThreadSnapshot
	LatestTurn ThreadDetailEvents
}

type ThreadSnapshot

type ThreadSnapshot struct {
	ID               string          `json:"id"`
	Title            string          `json:"title,omitempty"`
	TitleStatus      string          `json:"title_status,omitempty"`
	TitleSource      string          `json:"title_source,omitempty"`
	TitleUpdatedAt   time.Time       `json:"title_updated_at,omitempty"`
	TitleError       string          `json:"title_error,omitempty"`
	TitleGeneration  int64           `json:"title_generation,omitempty"`
	CreatedAt        time.Time       `json:"created_at"`
	UpdatedAt        time.Time       `json:"updated_at"`
	Phase            string          `json:"phase"`
	Status           string          `json:"status"`
	LatestTurnID     string          `json:"latest_turn_id,omitempty"`
	LatestRunID      string          `json:"latest_run_id,omitempty"`
	ThroughOrdinal   int64           `json:"through_ordinal"`
	WaitingPrompt    string          `json:"waiting_prompt,omitempty"`
	Recoverable      bool            `json:"recoverable"`
	CanAppendMessage bool            `json:"can_append_message"`
	CanRetry         bool            `json:"can_retry"`
	Messages         []ThreadMessage `json:"messages"`
}

type ThreadSummary

type ThreadSummary struct {
	ID               string    `json:"id"`
	Title            string    `json:"title,omitempty"`
	TitleStatus      string    `json:"title_status,omitempty"`
	TitleSource      string    `json:"title_source,omitempty"`
	TitleUpdatedAt   time.Time `json:"title_updated_at,omitempty"`
	TitleError       string    `json:"title_error,omitempty"`
	TitleGeneration  int64     `json:"title_generation,omitempty"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
	Phase            string    `json:"phase"`
	Status           string    `json:"status"`
	LatestTurnID     string    `json:"latest_turn_id,omitempty"`
	WaitingPrompt    string    `json:"waiting_prompt,omitempty"`
	Recoverable      bool      `json:"recoverable"`
	CanAppendMessage bool      `json:"can_append_message"`
	CanRetry         bool      `json:"can_retry"`
}

type TitleGenerator

type TitleGenerator interface {
	GenerateTitle(context.Context, TitleRequest) (TitleResult, error)
}

type TitleRequest

type TitleRequest struct {
	ThreadID string
	TurnID   string
	Messages []session.Message
}

type TitleResult

type TitleResult struct {
	Title  string
	Source sessiontree.ThreadTitleSource
}

type TurnExecutionRegistry

type TurnExecutionRegistry struct {
	Register   func(sessiontree.TurnLease) error
	Renew      func(sessiontree.TurnLease, sessiontree.TurnLease) error
	Unregister func(sessiontree.TurnLease)
	Active     func(string) (sessiontree.TurnLease, bool)
}

type TurnPolicy

type TurnPolicy struct {
	ContextPolicy         contextpolicy.Policy
	Reasoning             provider.ReasoningSelection
	CacheRetention        cache.Retention
	HostedToolDefinitions []provider.HostedToolDefinition
	CompletionPolicy      engine.CompletionPolicy
}

type TurnResult

type TurnResult struct {
	ID                 string
	RunID              string
	Status             engine.Status
	Output             string
	Err                error
	FailureCode        string
	Diagnostics        map[string]string
	Metrics            engine.RunMetrics
	CompletionReason   engine.CompletionReason
	ContinuationReason engine.ContinuationReason
	FinishReason       provider.FinishReason
	RawFinishReason    string
	FinishInferred     bool
	ControlSignal      *engine.ControlSignal
	CanonicalEvents    []SubAgentDetailEvent
	Replayed           bool
	AdmissionRunning   bool
}

type WaitSubAgentsOptions

type WaitSubAgentsOptions struct {
	ParentThreadID string
	ChildThreadIDs []string
	Timeout        time.Duration
}

type WaitSubAgentsResult

type WaitSubAgentsResult struct {
	Snapshots []SubAgentSnapshot `json:"snapshots"`
	TimedOut  bool               `json:"timed_out,omitempty"`
}

Jump to

Keyboard shortcuts

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