Skip to content
Source
Sign inSign up
TanStack/workflow

docs(research): ai-orchestration integration memo #7

Mergedtannerlinsleymerged 1 commit intomain fromrefs/pull/7/headmerged by tannerlinsley

tannerlinsleycommented

Memo on what can be removed from TanStack/ai#542 now that `@tanstack/workflow-core@0.0.1` is on npm, and how the AI-specific APIs there compose with the shipping engine.

TL;DR

Path B — refactor ai-orchestration to sit on workflow-core. Sheds 18 of 25 source files. The AI layer narrows to: `defineAgent`, `defineOrchestrator`, `defineRouter`, `invokeAgent` (kept as a helper for the three-shape detection), a slim AI-only `types.ts`, and an optional `withAgents` middleware that adds `ctx.agent(stepId, def, input)` for ergonomic invocation.

Key findings

  • Workflow-core needs zero engine changes to host the agent layer. Step bodies close over `ctx`, so `ctx.emit` forwards agent stream chunks inline.
  • The shape mismatch is real but tractable: PR 542's generator engine (`yield* agents.x(input)`) doesn't compose with workflow-core's closure engine, but `defineOrchestrator` rewrites cleanly as a `createWorkflow().handler(async (ctx) => { router loop })`.
  • Before/after on Alem's article workflow: two changes per call site — `yield*` → `await`, plus stepId as first arg. Otherwise structurally identical.
  • Estimated refactor cost: one focused day.

What's in the doc

  • The shape mismatch, table form
  • Three integration options with verdicts (A: don't, B: take this, C: don't)
  • Concrete delete list (18 files) and keep+refactor list (5-7 files)
  • Walk-through of why no engine changes are required
  • `withAgents` middleware sketch (optional, ergonomic)
  • One full before/after of a real workflow port
  • Estimated cost table

Test plan

  • Docs-only change, no source touched
  • `pnpm format` clean
  • CI green (billing-blocked at TanStack org level)
    1. tannerlinsley merged this0de8e83

    2. tannerlinsley closed this

Sign in to join this conversation.