Documentation
¶
Index ¶
- Variables
- type CheckpointPolicy
- type Edge
- type Graph
- func (g *Graph) AddStep(name string, step Step, after Router)
- func (g *Graph) Resume(ctx context.Context, runID string, input State, store Store) (*RunResult, error)
- func (g *Graph) Run(ctx context.Context, input State, store Store) (*RunResult, error)
- func (g *Graph) SetHooks(h HookPoints)
- func (g *Graph) SetTopology(topo []StepInfo)
- func (g *Graph) Topology() []StepInfo
- type GraphOption
- type HookPoints
- type MemStore
- func (s *MemStore) Delete(_ context.Context, ns, key string) error
- func (s *MemStore) Get(_ context.Context, ns, key string) ([]byte, error)
- func (s *MemStore) List(_ context.Context, ns, prefix string) ([]string, error)
- func (s *MemStore) Put(_ context.Context, ns, key string, value []byte) error
- func (s *MemStore) Tx(_ context.Context, fn func(Store) error) error
- type MergeConfig
- type MergePolicy
- type Router
- type RunResult
- type State
- type Step
- type StepHook
- type StepInfo
- type StopReason
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( ErrMaxIterations = errors.New("loom: max iterations exceeded") ErrBudgetExhausted = errors.New("loom: global step budget exhausted") ErrStepNotFound = errors.New("loom: step not found") ErrCheckpointNotFound = errors.New("loom: checkpoint not found") ErrCorruptCheckpoint = errors.New("loom: corrupt checkpoint") ErrNestedTx = errors.New("loom: nested transactions not supported") )
Functions ¶
This section is empty.
Types ¶
type CheckpointPolicy ¶
type CheckpointPolicy int
CheckpointPolicy controls how checkpoint failures are handled.
const ( // CheckpointBestEffort logs checkpoint failures but does not abort. CheckpointBestEffort CheckpointPolicy = iota // CheckpointRequired aborts the graph if checkpoint fails. CheckpointRequired )
type Edge ¶
type Edge struct {
To string `json:"to"` // target step name ("" = end)
Label string `json:"label,omitempty"` // condition label
}
Edge describes a possible transition from one step to another (for topology export).
type Graph ¶
type Graph struct {
Name string
// contains filtered or unexported fields
}
Graph is an executable composition of Steps and Routers.
func NewGraph ¶
func NewGraph(name string, entry string, opts ...GraphOption) *Graph
NewGraph creates a new graph with the given entry step.
func (*Graph) AddStep ¶
AddStep registers a step with an optional router for the "after" transition.
func (*Graph) Resume ¶
func (g *Graph) Resume(ctx context.Context, runID string, input State, store Store) (*RunResult, error)
Resume restarts a yielded graph from its checkpoint.
func (*Graph) SetHooks ¶
func (g *Graph) SetHooks(h HookPoints)
SetHooks attaches before/after hooks.
func (*Graph) SetTopology ¶
SetTopology declares the graph's topology for visualization. Called by graph builders (CompileAgent, newMirrorGraph, etc.) after constructing the graph.
type GraphOption ¶
type GraphOption func(*Graph)
GraphOption configures a Graph at construction time.
func WithCheckpointPolicy ¶
func WithCheckpointPolicy(p CheckpointPolicy) GraphOption
func WithMaxIterations ¶
func WithMaxIterations(n int) GraphOption
func WithMergeConfig ¶
func WithMergeConfig(cfg *MergeConfig) GraphOption
func WithStepBudget ¶
func WithStepBudget(n int64) GraphOption
WithStepBudget sets a global step limit shared across parent and all sub-graphs.
type HookPoints ¶
HookPoints holds before/after hooks for graph execution.
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore is an in-memory Store implementation for testing.
type MergeConfig ¶
type MergeConfig struct {
// contains filtered or unexported fields
}
MergeConfig holds per-key merge policies. It is mutable during construction and frozen once passed to a Graph.
func DefaultMergeConfig ¶
func DefaultMergeConfig() *MergeConfig
DefaultMergeConfig returns stdlib's recommended defaults.
func NewMergeConfig ¶
func NewMergeConfig() *MergeConfig
func (*MergeConfig) Register ¶
func (mc *MergeConfig) Register(key string, policy MergePolicy)
type MergePolicy ¶
MergePolicy defines how a specific key is merged.
var ( Overwrite MergePolicy = func(_, incoming any) any { return incoming } AppendSlice MergePolicy = func(existing, incoming any) any { e, _ := existing.([]any) i, _ := incoming.([]any) return append(e, i...) } SumInt MergePolicy = func(existing, incoming any) any { e, _ := existing.(int) i, _ := incoming.(int) return e + i } SumFloat MergePolicy = func(existing, incoming any) any { e, _ := existing.(float64) i, _ := incoming.(float64) return e + i } )
Built-in policies.
type Router ¶
Router determines the next step based on current state. Returns the name of the next step, or "" to halt.
func BranchFunc ¶
BranchFunc routes based on a user-supplied key extractor.
type RunResult ¶
type RunResult struct {
State State
LastStep string
Yielded bool
Steps int
RunID string
StopReason StopReason
}
RunResult contains the final state and metadata of a graph execution.
type State ¶
State is the execution context shared across all steps. Keys are strings. Values are any JSON-serializable type.
func UnmarshalState ¶
type Step ¶
Step is the atomic unit of execution. It receives the current state and returns the delta to merge. Returning a non-nil error aborts the graph.
type StepInfo ¶
type StepInfo struct {
Name string `json:"name"`
Detail string `json:"detail,omitempty"` // human-readable annotation
Edges []Edge `json:"edges"`
}
StepInfo describes a step and its outgoing edges for topology export.
type StopReason ¶
type StopReason string
StopReason classifies why a graph execution ended.
const ( StopCompleted StopReason = "completed" // normal termination (router returned "") StopYielded StopReason = "yielded" // HITL pause (__yield) StopMaxIter StopReason = "max_iter" // per-graph circuit breaker StopBudget StopReason = "budget" // global step budget exhausted StopError StopReason = "error" // Step returned non-nil error StopHookAbort StopReason = "hook_abort" // Before/After hook returned error )
type Store ¶
type Store interface {
Get(ctx context.Context, ns string, key string) ([]byte, error)
Put(ctx context.Context, ns string, key string, value []byte) error
Delete(ctx context.Context, ns string, key string) error
List(ctx context.Context, ns string, prefix string) ([]string, error)
// Tx runs a function inside a database transaction.
// The Store passed to fn is bound to the transaction.
// If fn returns nil, the transaction commits. If fn returns an error,
// the transaction rolls back.
// Nested Tx calls are NOT supported and must return an error.
Tx(ctx context.Context, fn func(Store) error) error
}
Store provides durable key-value storage with namespace isolation.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pgstore implements loom.Store backed by PostgreSQL.
|
Package pgstore implements loom.Store backed by PostgreSQL. |
|
provider
|
|
|
deepseek
Package deepseek implements the contract.LLM interface for the DeepSeek API.
|
Package deepseek implements the contract.LLM interface for the DeepSeek API. |
|
openai
Package openai implements contract.LLM for any OpenAI-compatible API.
|
Package openai implements contract.LLM for any OpenAI-compatible API. |