workflow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

ralph.go 复刻官方 workflow/tool-ralph 的纯编排:围绕一个固定目标,每轮让一个 全新子代理返回结构化报告,continue 则携带有界 handoff 进入下一轮,complete 成功收尾、blocked 需人工、达到 maxRounds 记为 budget-limited。

Package workflow 提供工作流引擎(任务 S12:Workflow Engine + tool-workflow)。

对齐上游:packages/workflow/workflow + tool-workflow

设计要点:

  • 以「脚本全局函数」方式组织编排原语:Pipeline(串行) / Parallel(并行) / Agent(子代理步骤),均为顶层函数,业务侧直接调用即可拼装工作流;
  • Step 是可执行的最小单元(运行函数 + 名称);Workflow 持有逐步序列;
  • Run:Pipeline 串行执行、Parallel 并发执行(goroutine + errgroup 等价语义), 收集各步输出;取消(ctx cancel)会级联取消正在进行的步骤;
  • WorkflowResult 聚合各步输出与取消标志,供上层对比/汇总。

Index

Constants

View Source
const DefaultRalphMaxRounds = 256

DefaultRalphMaxRounds 是默认轮数上限。

Variables

This section is empty.

Functions

func ValidateReport

func ValidateReport(r RoundReport) error

ValidateReport 校验报告与状态是否自洽。

Types

type Mode

type Mode string

Mode 是工作流的执行模式。

const (
	ModePipeline Mode = "pipeline" // 串行
	ModeParallel Mode = "parallel" // 并行
)

type RalphResult

type RalphResult struct {
	Status RunStatus
	Rounds int
	Final  RoundReport
}

RalphResult 是循环结果。

func RunRalph

func RunRalph(ctx context.Context, objective string, runner RoundRunner, maxRounds, maxHandoffChars int) (*RalphResult, error)

RunRalph 执行 Ralph 循环。maxRounds<=0 用默认值;maxHandoffChars>0 时校验 handoff 长度。

type Result

type Result struct {
	Name      string   `json:"name"`
	Outputs   []string `json:"outputs"`   // 各步输出(保序)
	Cancelled bool     `json:"cancelled"` // 是否被取消
}

Result 是一个工作流的运行结果。

func (*Result) Errors

func (r *Result) Errors() error

Errors 返回本次运行产生的首个错误(无则 nil)。

type RoundReport

type RoundReport struct {
	Status    RoundStatus `json:"status"`
	Summary   string      `json:"summary"`
	Evidence  string      `json:"evidence"`
	NextSteps []string    `json:"nextSteps"`
	Blocker   string      `json:"blocker"`
}

RoundReport 是单轮子代理返回的结构化报告。

type RoundRunner

type RoundRunner func(ctx context.Context, objective, priorHandoff string) (RoundReport, error)

RoundRunner 运行一轮:传入目标与上一轮 handoff(首轮为空),返回本轮报告。

type RoundStatus

type RoundStatus string

RoundStatus 是单轮状态。

const (
	StatusContinue RoundStatus = "continue"
	StatusComplete RoundStatus = "complete"
	StatusBlocked  RoundStatus = "blocked"
)

type RunStatus

type RunStatus string

RunStatus 是整个 Ralph 循环的收尾状态。

const (
	RunCompleted     RunStatus = "complete"
	RunBlocked       RunStatus = "blocked"
	RunBudgetLimited RunStatus = "budget-limited"
)

type SpawnAgentFunc

type SpawnAgentFunc func(ctx context.Context, backendName, input string) (string, error)

SpawnAgentFunc 由上层注入:按后端名运行一个子代理并返回输出。

type Step

type Step struct {
	Name string // 步骤名(诊断/汇总用)
	Run  StepRunFunc
}

Step 是最小工作流单元。

func Agent

func Agent(name, backendName, input string, spawn SpawnAgentFunc) *Step

Agent 构造一个子代理步骤(包装 subagent in-process 调用;backendName 可为 "in-process"/"acp"/"fork-copy")。

func Seq

func Seq(w *Workflow) *Step

Seq 把子工作流包装成单步(用于并行编排多个子工作流做聚合)。

type StepRunFunc

type StepRunFunc func(ctx context.Context) (string, error)

StepRunFunc 是单步执行函数(ctx 取消时应尽快返回)。

type Workflow

type Workflow struct {
	Name  string
	Mode  Mode
	Steps []*Step
}

Workflow 是一组 Step 的组合(串行或并行)。

func Parallel

func Parallel(name string, steps ...*Step) *Workflow

Parallel 构造并行工作流(各步并发执行)。

func Pipeline

func Pipeline(name string, steps ...*Step) *Workflow

Pipeline 构造串行工作流(逐步依序执行)。

func (*Workflow) Run

func (w *Workflow) Run(ctx context.Context) (*Result, error)

Run 执行工作流,返回聚合结果。ctx 取消会级联终止。

Jump to

Keyboard shortcuts

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