Documentation
¶
Index ¶
- Constants
- Variables
- func BindingsForTurn(recipes []MountRecipe, auth AuthContext) []vfs.Binding
- func DeleteSessionMessages(ctx context.Context, agent tacklr.AgentOptions, sessionID SessionID)
- func MergeUserState(base, overlay map[string]any) map[string]any
- func UserMessage(text string, msg *tacklr.Message) *tacklr.Message
- type AuthContext
- type Children
- type CommitInput
- type Control
- type CreateSession
- type CredentialBag
- type EventLog
- type InferenceInput
- type InferenceOutput
- type JobHandler
- type Ledger
- type Mailbox
- type MemoryEventLog
- func (l *MemoryEventLog) Append(_ context.Context, sessionID SessionID, topic string, ev tacklr.StreamEvent) error
- func (l *MemoryEventLog) CloseSession(_ context.Context, sessionID SessionID) error
- func (l *MemoryEventLog) Head(_ context.Context, sessionID SessionID) (Seq, error)
- func (l *MemoryEventLog) Subscribe(ctx context.Context, sessionID SessionID, after Seq) (<-chan tacklr.StreamEvent, error)
- type MemorySecretStorage
- type MemorySnapshot
- type MountRecipe
- type Prompt
- type PromptIn
- type Resume
- type ResumeIn
- type Revision
- type Runtime
- type SecretStorage
- type Secrets
- type Seq
- type Session
- type SessionID
- type SessionState
- type SessionStatus
- type Sessions
- type Snapshot
- type SnapshotStore
- type Step
- type Subscription
- type ToolInput
- type ToolOutput
- type Turn
- type Wake
Constants ¶
const ( WakePrompt = "prompt" WakeResume = "resume" WakeCancel = "cancel" WakeClose = "close" WakeChild = "child" )
Wake kinds from Mailbox. A prompt or resume is also the turn-span kind.
const ( // SessionKindSpecialist is Status.Kind for spawn_specialist children. SessionKindSpecialist = "specialist" // SessionKindWorker is Status.Kind for a named job-handler child. SessionKindWorker = "worker" )
const ( TopicEvents = "events" TopicRetry = "retry" )
EventLog topics.
Variables ¶
var ( // ErrSessionNotFound is unknown, closed, or already torn down. ErrSessionNotFound = errors.New("session not found") // ErrSessionExists is CreateSession with an id that is already live. ErrSessionExists = errors.New("session already exists") // ErrStaleCheckpoint is SnapshotStore.Save when expected Revision does not // match the row (another writer already saved). Reload and retry. ErrStaleCheckpoint = errors.New("stale checkpoint") )
Functions ¶
func BindingsForTurn ¶
func BindingsForTurn(recipes []MountRecipe, auth AuthContext) []vfs.Binding
BindingsForTurn builds the secret-bearing mounts for one turn. Each cached recipe is included when a token for its provider is on auth.
func DeleteSessionMessages ¶
func DeleteSessionMessages(ctx context.Context, agent tacklr.AgentOptions, sessionID SessionID)
DeleteSessionMessages removes this session's saved messages from the agent's brain. A nil brain is a no-op.
func MergeUserState ¶
MergeUserState copies overlay onto a clone of base. Overlay wins on conflict.
Types ¶
type AuthContext ¶
type AuthContext struct {
// Bindings are this slice's mounts and/or provider tokens. A binding with
// an alias upserts the recipe. A binding with only provider+token refreshes
// every cached recipe for that provider.
Bindings []vfs.Binding `json:"bindings,omitempty"`
// Drop removes cached recipes by alias or provider. Applied before Bindings.
Drop []string `json:"drop,omitempty"`
}
AuthContext is credentials and mount intent for one work item (Prompt, Resume, or a child session). Protocols map their wire auth into this type. Autonomous hosts set it on the payload that queues the work. Tokens are not stored in the snapshot or the durable history. The runtime writes them to SecretStorage before the work item runs.
func (AuthContext) WithoutSecrets ¶
func (a AuthContext) WithoutSecrets() AuthContext
WithoutSecrets returns a copy with Credential Token and ExpiresAt cleared. Binding metadata (provider, alias, params, writable) is kept. The input is not modified.
type Children ¶
type Children interface {
Children(ctx context.Context, parent SessionID) ([]SessionID, error)
Jobs(ctx context.Context, parent SessionID) ([]SessionStatus, error)
}
Children lists child sessions in start order. The agent starts and cancels them through tools. Hosts only read this list.
type CommitInput ¶
type CommitInput struct {
SessionID SessionID
Rec Snapshot
MCPServers []mcp.MCPConfig
State map[string]any
Call tacklr.ToolCall
Output string
}
CommitInput writes a tool output the runtime already has (a child result) without running the tool again.
type Control ¶
type Control interface {
Prompt(ctx context.Context, sessionID SessionID, msg Prompt) error
Resume(ctx context.Context, sessionID SessionID, resume Resume) error
Cancel(ctx context.Context, sessionID SessionID) error
}
Control is the live agent. Prompt while a turn is running or parked steers; it does not cancel the in-flight model call. Cancel aborts that turn and stops child sessions. The parent session stays open.
type CreateSession ¶
type CreateSession struct {
SessionID SessionID
MCPServers []mcp.MCPConfig
// Mounts seeds the session recipe cache (no secrets). Tokens arrive on Prompt.
Mounts []MountRecipe
// Parent, when set, makes this a child session of that parent. The child
// reuses the same wait loop. Empty MCPServers/Mounts inherit from parent.
Parent SessionID
// Specialist selects an assistant on the agent's Specialists list.
// Required with Parent for spawn_specialist children.
Specialist string
// Worker selects a named job handler. Exclusive with Specialist.
// The child session runs that handler instead of a model.
Worker string
// State seeds checkpoint userState (JSON-serializable values).
// Tools read it via HarnessRuntime.StateGet. The canonical copy is
// Snapshot.Checkpoint. No tokens or clients.
// Child sessions do not inherit this map.
State map[string]any
}
CreateSession is the typed input for Runtime.CreateSession.
type CredentialBag ¶
type CredentialBag struct {
// contains filtered or unexported fields
}
CredentialBag is the VFS credential state for one wire session. A protocol parses its own payload into vfs.Binding values, then calls Bind, Refresh, and Unbind. Take copies that state onto AuthContext for the next Prompt or Resume and clears the drop list.
func (*CredentialBag) Bind ¶
func (b *CredentialBag) Bind(binding vfs.Binding) error
Bind validates b and stores it. A later bind with the same provider and alias replaces the previous one.
func (*CredentialBag) Refresh ¶
func (b *CredentialBag) Refresh(provider string, cred vfs.Credential) bool
Refresh replaces the token on every binding for provider. It reports whether any binding matched.
func (*CredentialBag) Take ¶
func (b *CredentialBag) Take() AuthContext
Take returns the bindings for the next work item and clears drops.
func (*CredentialBag) Unbind ¶
func (b *CredentialBag) Unbind(point, provider string)
Unbind removes bindings whose alias or provider matches and records the alias on the next Take drop list.
type EventLog ¶
type EventLog interface {
Append(ctx context.Context, sessionID SessionID, topic string, ev tacklr.StreamEvent) error
Subscribe(ctx context.Context, sessionID SessionID, after Seq) (<-chan tacklr.StreamEvent, error)
Head(ctx context.Context, sessionID SessionID) (Seq, error)
CloseSession(ctx context.Context, sessionID SessionID) error
}
EventLog is the session progress stream. Topics are TopicEvents and TopicRetry (a repeated attempt).
type InferenceInput ¶
type InferenceInput struct {
SessionID SessionID
Rec Snapshot
MCPServers []mcp.MCPConfig
State map[string]any
User *tacklr.Message
Extra []*tacklr.Message
HadToolRound bool
ModelRequests int
Resume map[string][]byte
}
InferenceInput is one model step. Rec is the snapshot row to persist.
type InferenceOutput ¶
InferenceOutput is the model step result.
type JobHandler ¶
JobHandler runs a named background job. The runtime registers handlers by name. Schedule starts one.
type Ledger ¶
type Ledger interface {
IDs() []SessionID
Start(ToolOutput) error
Await(SessionID) (string, error)
CancelAll()
}
Ledger is the child-session ledger. The session decides when to start, wait, or cancel. The implementation starts and stops the child process.
type Mailbox ¶
Mailbox is the session mailbox. Prompts and Ready return work that is already queued. Recv blocks for the idle mailbox: prompt, resume, cancel, or close. Wait blocks during a turn that is waiting on children: a prompt, a finished child, or cancel.
type MemoryEventLog ¶
type MemoryEventLog struct {
// contains filtered or unexported fields
}
MemoryEventLog is a channel EventLog with topics events/retry/close.
func NewMemoryEventLog ¶
func NewMemoryEventLog() *MemoryEventLog
NewMemoryEventLog returns an empty EventLog.
func (*MemoryEventLog) Append ¶
func (l *MemoryEventLog) Append(_ context.Context, sessionID SessionID, topic string, ev tacklr.StreamEvent) error
Append implements EventLog.
func (*MemoryEventLog) CloseSession ¶
func (l *MemoryEventLog) CloseSession(_ context.Context, sessionID SessionID) error
CloseSession implements EventLog. It drops the log so a later session can reuse the id and so closed history does not stay in process memory.
func (*MemoryEventLog) Head ¶
Head implements EventLog. Unknown sessions report seq 0 without allocating a log.
func (*MemoryEventLog) Subscribe ¶
func (l *MemoryEventLog) Subscribe(ctx context.Context, sessionID SessionID, after Seq) (<-chan tacklr.StreamEvent, error)
Subscribe implements EventLog. It replays seq > after then tails. Replay is sent after unlocking so a large log cannot deadlock Append.
type MemorySecretStorage ¶
type MemorySecretStorage struct {
// contains filtered or unexported fields
}
MemorySecretStorage is an in-memory SecretStorage for tests and single-process workers. Client and worker must share the same instance.
func NewMemorySecretStorage ¶
func NewMemorySecretStorage() *MemorySecretStorage
func (*MemorySecretStorage) Delete ¶
func (s *MemorySecretStorage) Delete(_ context.Context, sessionID SessionID) error
type MemorySnapshot ¶
type MemorySnapshot struct {
// contains filtered or unexported fields
}
MemorySnapshot is an in-memory SnapshotStore.
func NewMemorySnapshot ¶
func NewMemorySnapshot() *MemorySnapshot
NewMemorySnapshot returns an empty SnapshotStore.
func (*MemorySnapshot) Delete ¶
func (s *MemorySnapshot) Delete(_ context.Context, sessionID SessionID) error
Delete implements SnapshotStore.
type MountRecipe ¶
type MountRecipe struct {
Provider string `json:"provider"`
Alias string `json:"alias"`
Params map[string]string `json:"params,omitempty"`
SourceIDs []string `json:"sourceIds,omitempty"`
Writable bool `json:"writable,omitempty"`
}
MountRecipe is secret-free VFS context remembered across turns. It records where a mount came from (provider, alias, backend ids). File contents are never stored; providers lazy-load on open/read.
func ApplyAuth ¶
func ApplyAuth(recipes []MountRecipe, auth AuthContext) []MountRecipe
ApplyAuth updates cached recipes from a work-item AuthContext. Drop is applied first. Bindings with an alias upsert that recipe. Tokens are not stored on the returned recipes.
type Prompt ¶
type Prompt struct {
Text string
UserMessage *tacklr.Message
// MCPServers, when non-nil, replaces session-scoped MCP configs for this turn.
MCPServers []mcp.MCPConfig
Auth AuthContext
// State merges into checkpoint userState for this turn after restore.
// JSON-serializable values only. No tokens or clients.
State map[string]any
}
Prompt is the typed input for Runtime.Prompt.
type PromptIn ¶
type PromptIn struct {
Text string
UserMessage *tacklr.Message
MCPServers []mcp.MCPConfig
Auth AuthContext
State map[string]any
}
PromptIn is one prompt delivered to a waiting session.
type Resume ¶
type Resume struct {
Responses map[string][]byte
Auth AuthContext
// State merges into checkpoint userState when the parked turn continues.
State map[string]any
}
Resume is the typed input for Runtime.Resume (HITL answer plus optional auth).
type ResumeIn ¶
type ResumeIn struct {
Responses map[string][]byte
Auth AuthContext
State map[string]any
}
ResumeIn is one resume delivered to a parked session.
type Revision ¶
type Revision string
Revision is the SnapshotStore compare-and-swap token for one session row. The zero value means no row exists yet; the next Save creates it.
type Runtime ¶
Runtime is the host session API. One backend runs one session per id. That backend implements Step, Mailbox, and Ledger. Package session owns the session loop. Leftover-tool and HITL rules live in tacklr.Next.
Prompt and Resume deliver work to the session. They do not return a harness. Subscribe yields StreamEvent values (message, tool, yield, error, complete). VFS credentials travel on Prompt, Resume, and CreateSession.Mounts. Protocols map wire auth into AuthContext.
type SecretStorage ¶
type SecretStorage interface {
// Put replaces Auth when secrets.Auth.Bindings is non-empty.
// Empty Bindings (including drop-only) is a no-op on the bag.
Put(ctx context.Context, sessionID SessionID, secrets Secrets) error
// Get returns the last Put bag. Missing session: zero Secrets, nil error.
Get(ctx context.Context, sessionID SessionID) (Secrets, error)
Delete(ctx context.Context, sessionID SessionID) error
}
SecretStorage holds Secrets for the workers that run a turn. The runtime client and the worker must share one instance. It is not SnapshotStore.
type Secrets ¶
type Secrets struct {
Auth AuthContext
}
Secrets is the session-scoped secret bag. It is not stored in the snapshot or the durable history. Auth holds VFS credentials. Add fields here when more work-item secrets need the same path.
type Session ¶
Session is one durable session lifetime. Task is set when a child workflow is started with a prompt: that session runs one turn and returns. A parent has an empty Task and waits until Close.
type SessionID ¶
type SessionID string
SessionID is the durable agent session identifier.
func ChildSessionID ¶
ChildSessionID is the stable id for a spawn_specialist child session.
type SessionState ¶
type SessionState string
SessionState is parent-facing session/job state. Child HITL does not change this from running until the interrupt is resolved and the child completes, fails, or is cancelled.
const ( SessionRunning SessionState = "running" SessionComplete SessionState = "complete" SessionFailed SessionState = "failed" SessionUnknown SessionState = "unknown" )
type SessionStatus ¶
type SessionStatus struct {
ID SessionID
Parent SessionID
State SessionState
Specialist string
Kind string
Result string
Err error
// Waiting is true while the session is parked for HITL. Parent-facing
// State stays running until that interrupt is resolved.
Waiting bool
}
SessionStatus is a value type returned by Runtime.Status. Not an interface.
type Sessions ¶
type Sessions interface {
CreateSession(ctx context.Context, req CreateSession) (SessionID, error)
// Close destroys the session and recursively stops children.
Close(ctx context.Context, sessionID SessionID) error
// Status is running, complete, failed, or unknown. A child waiting on HITL
// stays running until that interrupt is resolved.
Status(ctx context.Context, id SessionID) (SessionStatus, error)
// Head is the current EventLog offset. Protocol pumps pass it to Subscribe
// to tail from now (skip events from prior turns).
Head(ctx context.Context, sessionID SessionID) (Seq, error)
Subscribe(ctx context.Context, sessionID SessionID, after Seq) (Subscription, error)
}
Sessions is the session record: create it, destroy it, and read its status and event log.
type Snapshot ¶
type Snapshot struct {
Specialist string
Parent SessionID
// Children are child session ids in start order (no handles, no tokens).
Children []SessionID
Checkpoint tacklr.SessionCheckpoint
Mounts []MountRecipe
// Worker, when set, means this session is a named JobHandler child.
Worker string
}
Snapshot is the session record in SnapshotStore. Wait-loop fields (leftover tool calls, the MCP overlay, and child handles) stay on the session, not here.
type SnapshotStore ¶
type SnapshotStore interface {
Save(ctx context.Context, sessionID SessionID, snap Snapshot, expected Revision) (Revision, error)
Load(ctx context.Context, sessionID SessionID) (Snapshot, Revision, error)
Delete(ctx context.Context, sessionID SessionID) error
}
SnapshotStore is the session record: what the harness needs to think again after HITL or a worker recycle. It is not the wait loop and not credentials.
Frozen contents: SessionCheckpoint (window, plan, parked interrupt, userState), MountRecipe topology, and session identity (agent, parent, specialist, child ids). Tokens, file bytes, leftover unstarted tool calls, MCP env and headers, and child session handles never go here.
Save's expected Revision must match the last Load (zero if no row). Mismatch means another writer already saved — reload and retry.
type Step ¶
type Step interface {
Begin(kind string, promptLen, resumes int)
End()
Infer(InferenceInput) (InferenceOutput, error)
Tool(ToolInput) (ToolOutput, error)
Commit(CommitInput) error
Emit(tacklr.StreamEvent)
Job(name, task string) (string, error)
}
Step is the non-deterministic work inside one turn: model, tool, worker body, and the terminal event. The implementation retries a wrapped network error, a model refusal, and a stale checkpoint. Any other error stops on the first attempt. Begin and End bracket Run so the implementation can pin turn-scoped resources.
type Subscription ¶
type Subscription interface {
Events() <-chan tacklr.StreamEvent
Close() error
}
Subscription is one consumer of a session EventLog.
type ToolInput ¶
type ToolInput struct {
SessionID SessionID
Rec Snapshot
MCPServers []mcp.MCPConfig
State map[string]any
Call tacklr.ToolCall
}
ToolInput is one tool step.
type ToolOutput ¶
type ToolOutput struct {
Interrupted bool
InterruptID string
InterruptData []byte
CancelID SessionID
AwaitID SessionID
JobID SessionID
JobName string
JobTask string
Child bool
}
ToolOutput is one tool step. Job fields are the child the runtime must start or cancel. AwaitID blocks this tool call until that child finishes.
type Turn ¶
type Turn struct {
SessionID SessionID
Specialist string
Worker string
Parent SessionID
Mounts []MountRecipe
MCP []mcp.MCPConfig
Inbox []*tacklr.Message
NextMCP []mcp.MCPConfig
// Seed is CreateSession state until the first Run consumes it.
Seed map[string]any
HadTools bool
Requests int
Leftover []tacklr.ToolCall
Parked bool
// Overlay is the turn's user state while it is parked.
Overlay map[string]any
Result string
Terminal SessionState
Err error
Yielded bool
Closed bool
}
Turn is one session's scheduler state. The snapshot holds the conversation. Run is one prompt or resume, and returns when the turn parks, finishes, or fails.