feat(protocol): AdapterFn replaces AgentBinding in createWorkflow (#222 Phase 1) #224

Merged
xiaomo merged 1 commits from feat/222-adapter-fn-phase1 into main 2026-05-13 02:30:29 +00:00
Owner

What

新增 AdapterFn / RoleFn<T> / AdapterBinding 类型,createWorkflow 改为接受 AdapterBinding。Adapter 直接返回类型安全的 T,engine 不再调用 runtime.extract

Why

现有 AgentFn → string → Extract → meta 流程浪费一轮 LLM 调用。AdapterFn 让 adapter 自己决定如何拿到 structured output(ReAct agent 可以内置 resolve tool 一步到位)。

RFC: docs/plans/2026-05-12-react-agent.md

Changes

  • workflow-protocol/src/types.ts — 新增 RoleFn<T>, AdapterFn, AdapterBinding;旧类型标记 @deprecated
  • workflow-runtime/src/create-workflow.ts — 接受 AdapterBinding,调用 adapter(prompt, schema)RoleFn,直接获取 meta
  • workflow-util-agent/src/build-agent-prompt.ts — 新增 buildThreadInput(ctx: ThreadContext)
  • workflow-template-develop/bundle-entry.tswrapAgentAsAdapter 包装 cursor agent
  • workflow-template-solve-issue/bundle-entry.ts — 同上包装 hermes + workflowAsAgent
  • solve-issue-template.test.ts — 适配新接口

Test

197 tests pass, 0 fail

Ref: #222, Testing: #223


小橘 🍊(NEKO Team)

## What 新增 `AdapterFn` / `RoleFn<T>` / `AdapterBinding` 类型,`createWorkflow` 改为接受 `AdapterBinding`。Adapter 直接返回类型安全的 `T`,engine 不再调用 `runtime.extract`。 ## Why 现有 `AgentFn → string → Extract → meta` 流程浪费一轮 LLM 调用。`AdapterFn` 让 adapter 自己决定如何拿到 structured output(ReAct agent 可以内置 resolve tool 一步到位)。 RFC: `docs/plans/2026-05-12-react-agent.md` ## Changes - **`workflow-protocol/src/types.ts`** — 新增 `RoleFn<T>`, `AdapterFn`, `AdapterBinding`;旧类型标记 `@deprecated` - **`workflow-runtime/src/create-workflow.ts`** — 接受 `AdapterBinding`,调用 `adapter(prompt, schema)` 拿 `RoleFn`,直接获取 meta - **`workflow-util-agent/src/build-agent-prompt.ts`** — 新增 `buildThreadInput(ctx: ThreadContext)` - **`workflow-template-develop/bundle-entry.ts`** — `wrapAgentAsAdapter` 包装 cursor agent - **`workflow-template-solve-issue/bundle-entry.ts`** — 同上包装 hermes + workflowAsAgent - **`solve-issue-template.test.ts`** — 适配新接口 ## Test 197 tests pass, 0 fail Ref: #222, Testing: #223 --- 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-05-13 02:28:56 +00:00
- Add RoleFn<T>, AdapterFn, AdapterBinding types to workflow-protocol
- Mark AgentFn, AgentFnResult, AgentBinding as @deprecated
- Refactor createWorkflow to accept AdapterBinding instead of AgentBinding
- Adapter returns typed meta directly — no more extract call in workflow loop
- Add buildThreadInput (ThreadContext-based), keep buildAgentPrompt as deprecated wrapper
- Update template bundle-entries to wrap AgentFn as AdapterFn
- Update solve-issue tests to use AdapterFn directly
xiaomo approved these changes 2026-05-13 02:30:25 +00:00
xiaomo left a comment
Owner

LGTM — clean Phase 1 adapter refactor.

Type safety: AdapterFn generic flows correctly from schema: z.ZodType<T>RoleFn<T>Promise<T>. The as T cast in wrapAgentAsAdapter is pragmatic for the bridge layer.

Conventions: No optional props (uses | null), functional types only, named exports, @deprecated tags on old types.

Two minor notes for Phase 2:

  1. wrapAgentAsAdapter is duplicated in both develop/bundle-entry.ts and solve-issue/bundle-entry.ts. Consider extracting to a shared util (e.g. workflow-util-agent) when the old agent types are removed.
  2. childThread is hardcoded to null in advanceOneRound. If any workflow relies on child thread propagation via AgentFnResult, this is a silent regression. Looks intentional for Phase 1 but worth tracking.

197 tests pass. Ship it. 🍊

**LGTM — clean Phase 1 adapter refactor.** Type safety: `AdapterFn` generic flows correctly from `schema: z.ZodType<T>` → `RoleFn<T>` → `Promise<T>`. The `as T` cast in `wrapAgentAsAdapter` is pragmatic for the bridge layer. Conventions: No optional props (uses `| null`), functional types only, named exports, `@deprecated` tags on old types. ✅ Two minor notes for Phase 2: 1. **`wrapAgentAsAdapter` is duplicated** in both `develop/bundle-entry.ts` and `solve-issue/bundle-entry.ts`. Consider extracting to a shared util (e.g. `workflow-util-agent`) when the old agent types are removed. 2. **`childThread` is hardcoded to `null`** in `advanceOneRound`. If any workflow relies on child thread propagation via `AgentFnResult`, this is a silent regression. Looks intentional for Phase 1 but worth tracking. 197 tests pass. Ship it. 🍊
xiaomo merged commit 1f4bd3f431 into main 2026-05-13 02:30:29 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#224