Documentation
¶
Overview ¶
Package workflow defines the execution blackboard and high-level agent runtime types.
Package workflow defines the execution blackboard (Board: Vars + Channels), the Runtime orchestration API (Run, MemorySession, prepare/finish), Agent/Strategy/Memory abstractions, and Request/Result types.
Graph execution Strategy lives in subpackage workflow/flowgraph (imports graph). Callers typically construct a Runtime with WithPrepareBoard for platform-specific board setup and WithDependencies for Factory + Executor when using flowgraph.
Index ¶
- Constants
- func GetDep[T any](d *Dependencies, key string) (T, error)
- func GetTyped[T any](b *Board, key string) (T, bool)
- func MessageText(m model.Message) string
- func SetDep[T any](d *Dependencies, key string, val T)
- type Agent
- type AgentCapabilities
- type AgentCard
- type AgentOption
- type Artifact
- type BaseSession
- type Board
- func (b *Board) AppendChannelMessage(name string, msg model.Message)
- func (b *Board) AppendSliceVar(key string, value any) error
- func (b *Board) Channel(name string) []model.Message
- func (b *Board) ChannelsCopy() map[string][]model.Message
- func (b *Board) GetVar(key string) (any, bool)
- func (b *Board) GetVarString(key string) string
- func (b *Board) RestoreFrom(snap *BoardSnapshot)
- func (b *Board) SetChannel(name string, msgs []model.Message)
- func (b *Board) SetVar(key string, value any)
- func (b *Board) Snapshot() *BoardSnapshot
- func (b *Board) UpdateSliceVarItem(key string, match func(any) bool, update func(any) any)
- func (b *Board) Vars() map[string]any
- type BoardSnapshot
- type Cloneable
- type Dependencies
- type Memory
- type MemoryFactory
- type MemorySession
- type Request
- type RequestConfig
- type Result
- type RunConfig
- type RunOption
- type Runnable
- type Runtime
- type RuntimeOption
- type Skill
- type Strategy
- type StrategyCapabilities
- type StreamCallback
- type StreamEvent
- type Task
- type TaskManager
- type TaskStatus
Constants ¶
const ( VarQuery = "query" VarAnswer = "answer" VarMessages = "messages" VarRunID = "__run_id" VarStartTime = "__start_time" VarInternalUsage = "__usage" VarInterruptedNode = "__interrupted_node" VarOutputSchema = "__output_schema" VarPrevMessageCount = "__prev_message_count" VarSummaryIndex = "__summary_index" )
Board variable keys for the workflow/runtime layer.
const MainChannel = ""
MainChannel is the default message channel key (empty string).
Variables ¶
This section is empty.
Functions ¶
func GetDep ¶
func GetDep[T any](d *Dependencies, key string) (T, error)
GetDep retrieves a typed dependency. It returns an error if the key is missing or the stored value does not match the requested type.
func MessageText ¶
MessageText returns the plain text content of a user message, or "".
func SetDep ¶
func SetDep[T any](d *Dependencies, key string, val T)
SetDep stores a typed dependency value. The type parameter is for documentation only at the call site; retrieval is type-checked by GetDep.
Types ¶
type AgentCapabilities ¶
type AgentCapabilities struct {
Streaming bool `json:"streaming,omitempty"`
PushNotification bool `json:"push_notification,omitempty"`
StateTransition bool `json:"state_transition,omitempty"`
}
AgentCapabilities declares optional runtime features.
type AgentCard ¶
type AgentCard struct {
Name string
Description string
Skills []Skill
InputModes []string
OutputModes []string
Capabilities AgentCapabilities
}
AgentCard describes capabilities for discovery (e.g. A2A).
type AgentOption ¶
type AgentOption func(*simpleAgent)
AgentOption configures NewAgent.
func WithAgentDescription ¶
func WithAgentDescription(desc string) AgentOption
WithAgentDescription sets the card description.
func WithAgentTools ¶
func WithAgentTools(tools []string) AgentOption
WithAgentTools sets tool names exposed to the runtime.
type BaseSession ¶
type BaseSession struct{}
BaseSession is a no-op MemorySession for tests or disabled memory.
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board is the graph execution blackboard: typed message channels plus control vars. Card-based kanban coordination lives in kanban.Board, not here.
Thread safety: public methods use a mutex (matches historical graph.Board behavior).
func NewBoard ¶
func NewBoard() *Board
NewBoard creates an empty Board with an initialized main channel.
func RestoreBoard ¶
func RestoreBoard(snap *BoardSnapshot) *Board
RestoreBoard reconstructs a Board from a snapshot.
func (*Board) AppendChannelMessage ¶
AppendChannelMessage appends a message to a channel.
func (*Board) AppendSliceVar ¶
AppendSliceVar atomically appends a value to a slice stored in a board variable. It returns an error if the existing value is not a []any (instead of silently overwriting).
func (*Board) Channel ¶
Channel returns a copy of messages for the given channel (empty slice if missing).
func (*Board) ChannelsCopy ¶
ChannelsCopy returns a deep copy of all channel message lists (for parallel merge).
func (*Board) GetVarString ¶
GetVarString retrieves a board variable as a string, returning "" if missing or wrong type.
func (*Board) RestoreFrom ¶
func (b *Board) RestoreFrom(snap *BoardSnapshot)
RestoreFrom overwrites this board from a snapshot (executor retry rollback).
func (*Board) SetChannel ¶
SetChannel replaces the entire message list for a channel.
func (*Board) Snapshot ¶
func (b *Board) Snapshot() *BoardSnapshot
Snapshot returns a serializable snapshot (vars + channels only).
func (*Board) UpdateSliceVarItem ¶
UpdateSliceVarItem finds and updates the first matching item in a slice variable.
type BoardSnapshot ¶
type BoardSnapshot struct {
Vars map[string]any `json:"vars"`
Channels map[string][]model.Message `json:"channels,omitempty"`
}
BoardSnapshot is a serializable representation of execution state (no kanban cards).
type Cloneable ¶
type Cloneable interface {
Clone() any
}
Cloneable may be implemented by values stored in Board vars to provide a type-safe deep copy instead of the JSON fallback.
type Dependencies ¶
type Dependencies struct {
// contains filtered or unexported fields
}
Dependencies is a type-safe container for resources available to Strategy.Build. Each Strategy defines its own key constants and retrieves values via GetDep.
func NewDependencies ¶
func NewDependencies() *Dependencies
NewDependencies creates an empty Dependencies container.
func (*Dependencies) Set ¶
func (d *Dependencies) Set(key string, val any)
Set stores a dependency value under the given key.
type Memory ¶
type Memory interface {
Session(ctx context.Context, contextID string) (MemorySession, error)
}
Memory provides per-agent session memory.
type MemoryFactory ¶
MemoryFactory creates a Memory for an agent.
type MemorySession ¶
type MemorySession interface {
Load(ctx context.Context) ([]model.Message, error)
Vars(ctx context.Context) (map[string]any, error)
Save(ctx context.Context, messages []model.Message) error
Close(ctx context.Context, runErr error) error
}
MemorySession is one Run's memory lifecycle (Load → Vars → Save → Close). All methods accept a context.Context to support timeout and cancellation for implementations backed by databases or network services.
type Request ¶
type Request struct {
TaskID string
ContextID string
RuntimeID string
RunID string
Message model.Message
Inputs map[string]any
Config *RequestConfig
// Extensions carries platform-specific data (e.g. executor options for flowgraph).
Extensions map[string]any
}
Request is one agent turn: user message plus optional inputs and metadata.
func NewTextRequest ¶
NewTextRequest builds a Request whose Message is a single user text turn.
type RequestConfig ¶
type RequestConfig struct {
AcceptedOutputModes []string `json:"accepted_output_modes,omitempty"`
}
RequestConfig holds optional request-level settings (A2A alignment, etc.).
type Result ¶
type Result struct {
TaskID string
Status TaskStatus
Messages []model.Message
Artifacts []Artifact
Usage model.TokenUsage
State map[string]any
Err error
// LastBoard is the board after Execute (for platform persistence hooks). Not serialized.
LastBoard *Board `json:"-"`
}
Result is returned by Runtime.Run after execution and finish logic.
type RunConfig ¶
type RunConfig struct {
History []model.Message
StreamCallback StreamCallback
MaxIterations int
}
RunConfig holds resolved run-level settings. Exported so that Strategy implementations (e.g. flowgraph) can read stream callback, max iterations, etc.
func ApplyRunOpts ¶
ApplyRunOpts resolves a slice of RunOption into a RunConfig.
type RunOption ¶
type RunOption func(*RunConfig)
RunOption configures a single Run call.
func WithHistory ¶
WithHistory injects message history into the main channel when no Memory session is used. Ignored when a non-nil Memory session is opened (MemoryFactory path wins).
func WithMaxIterations ¶
WithMaxIterations caps the number of graph execution steps.
func WithStreamCallback ¶
func WithStreamCallback(cb StreamCallback) RunOption
WithStreamCallback sets a streaming event callback for the execution.
type Runnable ¶
type Runnable interface {
Execute(ctx context.Context, board *Board, req *Request, opts ...RunOption) (*Board, error)
}
Runnable is the compiled execution unit produced by Strategy.Build.
type Runtime ¶
type Runtime interface {
Run(ctx context.Context, agent Agent, req *Request, opts ...RunOption) (*Result, error)
}
Runtime executes one agent Request using Strategy + optional Memory.
func NewRuntime ¶
func NewRuntime(opts ...RuntimeOption) Runtime
NewRuntime constructs a Runtime with optional MemoryFactory and board preparation hook.
type RuntimeOption ¶
type RuntimeOption func(*runtime)
RuntimeOption configures NewRuntime.
func WithDependencies ¶
func WithDependencies(d *Dependencies) RuntimeOption
WithDependencies supplies Strategy.Build with factories and executors (flowgraph uses these).
func WithMemoryFactory ¶
func WithMemoryFactory(f MemoryFactory) RuntimeOption
WithMemoryFactory sets the MemoryFactory used by openSession.
func WithPrepareBoard ¶
func WithPrepareBoard(fn func(ctx context.Context, agent Agent, req *Request, session MemorySession, opts []RunOption) (*Board, error)) RuntimeOption
WithPrepareBoard sets a custom board preparation (platform graph vars, schema, etc.). When nil, prepareBoard uses the generic Request + session + history path only.
type Skill ¶
type Skill struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
Skill is a lightweight skill declaration on an AgentCard.
type Strategy ¶
type Strategy interface {
Kind() string
Build(ctx context.Context, deps *Dependencies) (Runnable, error)
Capabilities() StrategyCapabilities
}
Strategy describes how to execute one turn (graph, script, remote, …).
type StrategyCapabilities ¶
type StrategyCapabilities struct {
AnswerKey string
}
StrategyCapabilities describes how Runtime reads outputs from the Board.
func (StrategyCapabilities) AnswerVar ¶
func (c StrategyCapabilities) AnswerVar() string
AnswerVar returns the board var key for the final answer, defaulting to "answer".
type StreamCallback ¶
type StreamCallback func(event StreamEvent)
StreamCallback receives streaming events during execution.
type StreamEvent ¶
type StreamEvent struct {
Type string `json:"type"`
NodeID string `json:"node_id"`
Payload any `json:"payload,omitempty"`
}
StreamEvent carries a streaming event emitted by a node during execution.
type Task ¶
type Task struct {
ID string `json:"id"`
Status TaskStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
Result *Result `json:"result,omitempty"`
}
Task represents a tracked unit of work managed by a TaskManager.
type TaskManager ¶
type TaskManager interface {
GetTask(id string) (*Task, error)
CancelTask(id string) error
ListTasks() ([]*Task, error)
}
TaskManager is an optional capability for run/task orchestration (list/cancel). Default Runtime implementations may return a no-op or nil adapter.
type TaskStatus ¶
type TaskStatus string
TaskStatus is the terminal or intermediate status of a run.
const ( StatusCompleted TaskStatus = "completed" StatusWorking TaskStatus = "working" StatusFailed TaskStatus = "failed" StatusInputRequired TaskStatus = "input_required" StatusCanceled TaskStatus = "canceled" StatusInterrupted TaskStatus = "interrupted" StatusAborted TaskStatus = "aborted" )