checkpoint

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package checkpoint provides save/load for interrupted run state, enabling resume of partially-completed agent runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(path string) error

Clear deletes the checkpoint file. Returns nil if the file does not exist.

func Save

func Save(path string, cp Checkpoint) error

Save atomically writes a checkpoint to path.

Types

type Checkpoint

type Checkpoint struct {
	Prompt     string             `json:"prompt"`
	Timestamp  time.Time          `json:"timestamp"`
	AdapterIDs []string           `json:"adapter_ids"`
	Responses  []ResponseSnapshot `json:"responses"`
	Verbose    bool               `json:"verbose"`
}

Checkpoint stores the state of an interrupted run.

func Build

func Build(prompt string, adapterIDs []string, responses []models.ModelResponse, verbose bool) *Checkpoint

Build creates a Checkpoint from a completed (possibly interrupted) run. Returns nil if no responses are interrupted (no checkpoint needed).

func Load

func Load(path string) (*Checkpoint, error)

Load reads a checkpoint from path. Returns (nil, nil) if no checkpoint file exists.

type IncrementalSaver

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

IncrementalSaver aggregates per-model snapshots from concurrent adapter goroutines and writes them to disk atomically after each update. This ensures that the checkpoint file reflects the most recent turn boundary even if the process is killed ungracefully (SIGKILL, OOM, power loss).

All methods are safe for concurrent use.

func NewIncrementalSaver

func NewIncrementalSaver(path, prompt string, adapterIDs []string, verbose bool) *IncrementalSaver

NewIncrementalSaver creates a saver that writes checkpoints to path.

func (*IncrementalSaver) MarkCompleted

func (s *IncrementalSaver) MarkCompleted(modelID string, snap ResponseSnapshot)

MarkCompleted stores the final snapshot for a model with Completed=true and flushes.

func (*IncrementalSaver) Update

func (s *IncrementalSaver) Update(modelID string, snap ResponseSnapshot)

Update stores the latest snapshot for a model and flushes to disk.

type ResponseSnapshot

type ResponseSnapshot struct {
	ModelID         string          `json:"model_id"`
	Text            string          `json:"text,omitempty"`
	LatencyMS       int64           `json:"latency_ms"`
	InputTokens     int64           `json:"input_tokens"`
	OutputTokens    int64           `json:"output_tokens"`
	ReasoningTokens int64           `json:"reasoning_tokens,omitempty"`
	CostUSD         float64         `json:"cost_usd"`
	ProposedWrites  []WriteSnapshot `json:"proposed_writes,omitempty"`
	ToolCalls       map[string]int  `json:"tool_calls,omitempty"`
	Error           string          `json:"error,omitempty"`
	Interrupted     bool            `json:"interrupted"`
	Completed       bool            `json:"completed"`
}

ResponseSnapshot is a serializable snapshot of a ModelResponse.

func FromModelResponse

func FromModelResponse(r models.ModelResponse) ResponseSnapshot

FromModelResponse creates a snapshot from a ModelResponse.

func SnapshotFromPartial

func SnapshotFromPartial(modelID string, ps models.PartialSnapshot) ResponseSnapshot

SnapshotFromPartial converts a PartialSnapshot (emitted by adapters via AgentEvent) into a ResponseSnapshot suitable for incremental checkpointing.

func (ResponseSnapshot) ToModelResponse

func (s ResponseSnapshot) ToModelResponse() models.ModelResponse

ToModelResponse converts a snapshot back to a ModelResponse.

type WriteSnapshot

type WriteSnapshot struct {
	Path    string `json:"path"`
	Content string `json:"content"`
	Delete  bool   `json:"delete,omitempty"`
}

WriteSnapshot is a serializable FileWrite.

Jump to

Keyboard shortcuts

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