Help us shape the future of Go! Take the 2026 Go Developer Survey

workflow

package
v0.32.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package workflow provides the in-process workflow runner for TODO-loop workflows. It eliminates subprocess spawning (the BPM/exec.Command path that requires nohup and breaks across OS/process-group boundaries) by running the workflow loop in-process as a goroutine with a fresh Agent.

SP-141 phase 1: the loop logic lives here; pkg/agent's workflow_wiring.go constructs the fresh Agent (unexported fields make construction agent-internal) and calls RunTodoLoop. The arrow is one-way — this package defines the LoopAgent seam and never imports pkg/agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateWorkflowSessionID

func GenerateWorkflowSessionID() string

GenerateWorkflowSessionID returns a fresh workflow session identifier.

func StartWorkflowHeartbeat

func StartWorkflowHeartbeat(chatAgent LoopAgent, interval time.Duration) func()

StartWorkflowHeartbeat runs the budget/iteration heartbeat until the returned stop func is called.

Types

type LoopAgent

type LoopAgent interface {
	GetProvider() string
	GetModel() string
	GetMaxIterations() int
	SetMaxIterations(max int)
	GenerateResponse(messages []api.Message) (string, error)
	ProcessQueryWithContinuity(userQuery string) (string, error)
	ClearConversationHistory()
	FleetBudgetExceeded() bool
	// BudgetSnapshot reports (spent, limit) for the heartbeat; a nil-nil
	// return means "no fleet budget — use Cost() instead".
	BudgetSnapshot() (float64, float64, bool)
	Cost() float64
	Iteration() int
}

LoopAgent is the seam the loop needs from its runner agent — the exported-method surface the TODO loop actually uses. *agent.Agent satisfies it structurally (wired in pkg/agent/workflow_wiring.go).

type WorkflowBudgetConfig

type WorkflowBudgetConfig struct {
	USD    float64   `json:"usd,omitempty"`
	WarnAt []float64 `json:"warn_at,omitempty"`
}

WorkflowBudgetConfig is parsed from the "budget" section of a workflow JSON.

type WorkflowFileConfig

type WorkflowFileConfig struct {
	Description string                  `json:"description,omitempty"`
	Loop        *WorkflowLoopConfig     `json:"loop,omitempty"`
	Budget      *WorkflowBudgetConfig   `json:"budget,omitempty"`
	Progress    *WorkflowProgressConfig `json:"progress,omitempty"`
}

workflowFileConfig is the top-level structure parsed from the workflow JSON file. It mirrors only the fields the in-process runner cares about.

func ParseWorkflowFile

func ParseWorkflowFile(path string) (*WorkflowFileConfig, error)

parseWorkflowFile reads and parses a workflow JSON file for its loop configuration. Returns only the fields the in-process runner needs. ParseWorkflowFile reads and parses a workflow JSON definition.

type WorkflowLoopConfig

type WorkflowLoopConfig struct {
	TodoFile       string `json:"todo_file,omitempty"`
	GatePromptFile string `json:"gate_prompt_file,omitempty"`
	MaxRetries     int    `json:"max_retries,omitempty"`
	MaxIterations  int    `json:"max_iterations,omitempty"`
	BuildCommand   string `json:"build_command,omitempty"`
}

func (*WorkflowLoopConfig) ApplyDefaults

func (c *WorkflowLoopConfig) ApplyDefaults()

applyDefaults fills in zero-value fields with the same defaults used by cmd/agent_workflow_loader.go so the runner behaves identically.

type WorkflowProgressConfig

type WorkflowProgressConfig struct {
	HeartbeatSeconds int `json:"heartbeat_seconds,omitempty"`
}

WorkflowProgressConfig is parsed from the "progress" section.

type WorkflowResult

type WorkflowResult struct {
	ItemsProcessed int
	ItemsSkipped   int
	ItemsFailed    int
	Error          error
}

WorkflowResult is returned when the workflow completes.

func RunTodoLoop

func RunTodoLoop(ctx context.Context, loopAgent LoopAgent, configPath string, loop *WorkflowLoopConfig, gatePromptText string, stopBudget func()) (*WorkflowResult, error)

RunTodoLoop runs the TODO loop against a prepared loop agent (see pkg/agent/workflow_wiring.go for construction). ctx governs cancellation; configPath resolves the todo file relative to the workflow JSON; loop carries the parsed loop config; gatePromptText is the gate prompt's file contents; stopBudget retires the heartbeat/budget teardown started by the constructor.

Jump to

Keyboard shortcuts

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