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 ¶
const DefaultRalphMaxRounds = 256
DefaultRalphMaxRounds 是默认轮数上限。
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 是一个工作流的运行结果。
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 SpawnAgentFunc ¶
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")。
type StepRunFunc ¶
StepRunFunc 是单步执行函数(ctx 取消时应尽快返回)。