Skip to content

feat(loop): sequential chain builder - #219

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/sequential-builder
Open

feat(loop): sequential chain builder#219
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/sequential-builder

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

Adds an explicit sequential orchestration abstraction: define stages, each stage's task may reference the previous stage's result, and the chain is executed in order with results flowing forward.

Components

  • ChainStage — one step in a chain (name, task, optional persona/tools/output_schema/isolate flag)
  • render_task(previous_result) — substitutes {previous_result} token
  • SequentialBuilder — validates the chain (at least one stage, no conflicting aliases) and renders each stage's task with the previous result

Design

  • Pure orchestration description + executor contract: no I/O, no subprocess
  • Executor is a callable the host supplies (e.g. wired to AgentControl or workflow_service), keeping this module host-agnostic and testable
  • Complements existing concurrent fan-out / fork_turns support

File

  • core/loop/sequential_builder.py (new, 121 lines)

Part of GenAI lesson 17 orchestration family.

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

设计说明

问题:多步骤任务常常是"前一步的输出是后一步的输入"(如:搜索 → 下载 → 解压 → 读取),现有 loop 结构没有显式表达这种链式依赖,每次都要手工拼 prompt。

解法ChainStage dataclass + SequentialBuilder 验证器——每个 stage 声明 render_task(),用 {previous_result} 占位符替换上一步输出。

关键设计决策

  • 用 dataclass 而非 dict——类型检查在构建期就能捕获占位符错误
  • SequentialBuilder 只做验证(占位符匹配、顺序完整性),不执行任务——保持 pure mechanism
  • 链式结构支持分支(每个 stage 可以声明依赖前 N 步),不是严格线性

测试建议:验证 {previous_result} 在 1 步/多步/缺失占位符三种场景下的行为

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant