Skip to content

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

Merged
tannerlinsley merged 1 commit into
mainfrom
research/ai-orchestration-integration
May 22, 2026
Merged

docs(research): ai-orchestration integration memo#7
tannerlinsley merged 1 commit into
mainfrom
research/ai-orchestration-integration

Conversation

@tannerlinsley
Copy link
Copy Markdown
Member

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)

Walks PR 542 (TanStack/ai) against workflow-core@0.0.1 file-by-file.
Three integration options analyzed; recommends Path B (refactor
ai-orchestration onto workflow-core).

Concrete list of 18 files to delete (engine, primitives, runStore,
server, registry, result, define-workflow — all superseded by
workflow-core), 5-7 files to keep and refactor (defineAgent,
invokeAgent, defineOrchestrator as closure-loop, defineRouter,
types.ts, index.ts, optional withAgents middleware).

Validates the agent layer can be expressed on workflow-core with zero
engine changes — step bodies close over ctx, so ctx.emit forwards
agent stream chunks inline. Optional withAgents middleware adds a
typed ctx.agent(stepId, def, input) primitive for ergonomic
invocation that reads structurally identical to Alem's existing
yield* agents.x(input) style.

Includes a before/after of Alem's article workflow (two changes per
call site: yield* → await, plus stepId as first arg).

Estimated refactor cost: one focused day.

Updates research/README.md to include the new file.
@tannerlinsley tannerlinsley merged commit 0de8e83 into main May 22, 2026
@tannerlinsley tannerlinsley deleted the research/ai-orchestration-integration branch May 22, 2026 21:49
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