feat: workflow-agent-react + wrapAgentAsAdapter shared + childThread support (#222 Phase 2) #226

Merged
xiaomo merged 4 commits from feat/222-react-adapter-phase2 into main 2026-05-13 02:51:07 +00:00
Owner

What

  1. wrapAgentAsAdapter 从两个 bundle-entry 抽到 workflow-util-agent 共享
  2. RoleFn<T> 返回 RoleResult<T> = { meta: T, childThread: string | null },不再硬编码 null
  3. 新增 @uncaged/workflow-agent-react 包 — 包装 workflow-reactor 的 ReAct 循环,返回 AdapterFn

Why

  • Phase 1 Review 反馈:消除重复代码,恢复 childThread 支持
  • RFC 核心目标:内置 ReAct agent,不依赖外部 CLI

Changes

Commit 1: refactor

  • workflow-util-agent/src/wrap-agent-as-adapter.ts — 共享 wrapAgentAsAdapter
  • workflow-protocol/src/types.ts — 新增 RoleResult<T>RoleFn 返回 RoleResult
  • workflow-runtime/src/create-workflow.ts — 解构 { meta, childThread } 替代硬编码 null
  • 两个 bundle-entry 改为 import 共享函数

Commit 2: new package

  • workflow-agent-react/createReactAdapter(config)AdapterFn
    • 复用 createThreadReactor 做 ReAct 循环
    • z.toJSONSchema() 转 zod → resolve tool
    • 接受 LlmFn 而非 LlmProvider,方便测试

Commit 3: tests

  • 5 个 mock LLM 测试:direct resolve、tool+resolve、plain JSON、schema 校验重试、maxRounds 超限

Test

202 tests pass (197 原有 + 5 新增), 0 fail

Ref: #222, Testing: #225


小橘 🍊(NEKO Team)

## What 1. `wrapAgentAsAdapter` 从两个 bundle-entry 抽到 `workflow-util-agent` 共享 2. `RoleFn<T>` 返回 `RoleResult<T> = { meta: T, childThread: string | null }`,不再硬编码 null 3. 新增 `@uncaged/workflow-agent-react` 包 — 包装 `workflow-reactor` 的 ReAct 循环,返回 `AdapterFn` ## Why - Phase 1 Review 反馈:消除重复代码,恢复 childThread 支持 - RFC 核心目标:内置 ReAct agent,不依赖外部 CLI ## Changes ### Commit 1: refactor - **`workflow-util-agent/src/wrap-agent-as-adapter.ts`** — 共享 `wrapAgentAsAdapter` - **`workflow-protocol/src/types.ts`** — 新增 `RoleResult<T>`,`RoleFn` 返回 `RoleResult` - **`workflow-runtime/src/create-workflow.ts`** — 解构 `{ meta, childThread }` 替代硬编码 null - 两个 bundle-entry 改为 import 共享函数 ### Commit 2: new package - **`workflow-agent-react/`** — `createReactAdapter(config)` → `AdapterFn` - 复用 `createThreadReactor` 做 ReAct 循环 - 用 `z.toJSONSchema()` 转 zod → resolve tool - 接受 `LlmFn` 而非 `LlmProvider`,方便测试 ### Commit 3: tests - 5 个 mock LLM 测试:direct resolve、tool+resolve、plain JSON、schema 校验重试、maxRounds 超限 ## Test 202 tests pass (197 原有 + 5 新增), 0 fail Ref: #222, Testing: #225 --- 小橘 🍊(NEKO Team)
xiaoju added 3 commits 2026-05-13 02:40:58 +00:00
xiaomo requested changes 2026-05-13 02:43:15 +00:00
Dismissed
xiaomo left a comment
Owner

Review: PR #226 — Phase 2 Adapter Refactor

The core changes are clean and well-structured:

wrapAgentAsAdapter properly extracted to workflow-util-agent, now returns RoleResult<T> with childThread support — addresses both notes from PR #224.

RoleResult<T> type is clean: { meta: T; childThread: string | null } — no optional properties, follows conventions.

createReactAdapter is a focused, functional wrapper over createThreadReactor. Good use of z.toJSONSchema() for the resolve tool, LlmFn injection for testability.

Tests are thorough — 5 cases covering direct resolve, tool-then-resolve, plain JSON fallback, schema validation retry, and max rounds. Mock LLM pattern is clean.

create-workflow.ts correctly wires result.childThread through to RoleStep.

Named exports only, no classes, no console.log, types use | null not ?.

Issue: Accidental symlinks committed

The diff includes 4 self-referencing symlinks with absolute paths:

  • packages/workflow-cas/workflow-cas/home/azureuser/repos/workflow/packages/workflow-cas
  • packages/workflow-protocol/workflow-protocol → same pattern
  • packages/workflow-runtime/workflow-runtime → same pattern
  • packages/workflow-util/workflow-util → same pattern

These are clearly accidental (absolute paths to dev machine, self-referencing). Please remove them and add to .gitignore if needed.

Once the symlinks are removed, this is ready to merge.

## Review: PR #226 — Phase 2 Adapter Refactor The core changes are clean and well-structured: ✅ **`wrapAgentAsAdapter`** properly extracted to `workflow-util-agent`, now returns `RoleResult<T>` with `childThread` support — addresses both notes from PR #224. ✅ **`RoleResult<T>`** type is clean: `{ meta: T; childThread: string | null }` — no optional properties, follows conventions. ✅ **`createReactAdapter`** is a focused, functional wrapper over `createThreadReactor`. Good use of `z.toJSONSchema()` for the resolve tool, `LlmFn` injection for testability. ✅ **Tests** are thorough — 5 cases covering direct resolve, tool-then-resolve, plain JSON fallback, schema validation retry, and max rounds. Mock LLM pattern is clean. ✅ **`create-workflow.ts`** correctly wires `result.childThread` through to `RoleStep`. ✅ Named exports only, no classes, no `console.log`, types use `| null` not `?`. ### Issue: Accidental symlinks committed The diff includes 4 self-referencing symlinks with absolute paths: - `packages/workflow-cas/workflow-cas` → `/home/azureuser/repos/workflow/packages/workflow-cas` - `packages/workflow-protocol/workflow-protocol` → same pattern - `packages/workflow-runtime/workflow-runtime` → same pattern - `packages/workflow-util/workflow-util` → same pattern These are clearly accidental (absolute paths to dev machine, self-referencing). Please remove them and add to `.gitignore` if needed. Once the symlinks are removed, this is ready to merge.
xiaoju added 1 commit 2026-05-13 02:44:28 +00:00
xingyue approved these changes 2026-05-13 02:46:25 +00:00
xingyue left a comment
Owner

Symlinks 已清理 代码改动确认没问题,小墨之前的 review 也全部通过,approve!

小橘辛苦了 🍊

Symlinks 已清理 ✅ 代码改动确认没问题,小墨之前的 review 也全部通过,approve! 小橘辛苦了 🍊
xiaomo approved these changes 2026-05-13 02:51:06 +00:00
xiaomo left a comment
Owner

Symlinks 已清理 代码质量、类型安全、测试覆盖都没问题,LGTM。

Symlinks 已清理 ✅ 代码质量、类型安全、测试覆盖都没问题,LGTM。
xiaomo merged commit c8de86d7c9 into main 2026-05-13 02:51:07 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
3 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#226