Skip to content

refactor(langgraph): unify agent() return type as LangGraphAgent#152

Merged
blove merged 7 commits into
mainfrom
feat/toagent-review
May 1, 2026
Merged

refactor(langgraph): unify agent() return type as LangGraphAgent#152
blove merged 7 commits into
mainfrom
feat/toagent-review

Conversation

@blove
Copy link
Copy Markdown
Contributor

@blove blove commented May 1, 2026

Eliminates the two-step `agent({...}) + toAgent(stream)` pattern. `agent({...})` now returns a unified `LangGraphAgent` (extends `AgentWithHistory` from @ngaf/chat) preserving all of AgentRef's public surface. `toAgent` removed entirely. ~25 cockpit demos and ~17 website doc files migrated.

Breaking changes

  • `agent({...})` return type: `AgentRef` → `LangGraphAgent`.
  • `toAgent` removed from @ngaf/langgraph (AG-UI's `toAgent(source: AbstractAgent)` is unchanged).
  • `AgentRef` no longer exported from @ngaf/langgraph (kept internally as scaffolding).
  • `createMockAgentRef` → `mockLangGraphAgent`.
  • `messages` signal type: `Signal<BaseMessage[]>` → `Signal<Message[]>`. Use `langGraphMessages` for raw LangChain types.
  • Same `langGraph*`-prefix pattern for `langGraphInterrupts`, `langGraphToolCalls`, `langGraphHistory` where the unified type uses runtime-neutral shapes.

Cockpit migration pattern

```diff
-protected readonly stream = agent({ apiUrl, assistantId });
-protected readonly chatAgent = toAgent(this.stream);
+protected readonly agent = agent({ apiUrl, assistantId });
```

5 cockpit components needed `langGraphMessages()` / `langGraphHistory()` for raw LangChain type access (deep-agents/{skills,filesystem,subagents,sandboxes}, langgraph/time-travel).

Test Plan

  • @ngaf/langgraph lint/test/build pass with new `agent.conformance.spec.ts` running `runAgentConformance`
  • All 25 migrated cockpit angular demos build clean
  • Website builds clean
  • Zero residual `AgentRef`/`toAgent` refs in source (excludes generated api-docs.json + frozen marketing whitepapers)

Pre-existing issue (NOT caused by this PR)

`apps/demo:build` fails with TS2339 'Property getType does not exist on type Message'. Confirmed pre-existing on main via stash test by the implementer subagent. Worth a separate PR to address.

Stale generated artifacts

`apps/website/public/api-docs.json` was not regenerated (the generation script's path lookup didn't find the new lib structure). The on-site "API Reference" pages may show stale content until the script is fixed and re-run. Separate cleanup.

Internal AgentRef interface kept (unused, unexported)

The `AgentRef` interface in `agent.types.ts` is preserved as a comment-anchored historical reference but is no longer imported or exported. Could be deleted in a future cleanup; left in place to make the surface-preservation intent visible during review.

Design + plan

  • Spec: `docs/superpowers/specs/2026-05-01-langgraph-agent-unification-design.md`
  • Plan: `docs/superpowers/plans/2026-05-01-langgraph-agent-unification.md`

🤖 Generated with Claude Code

blove and others added 6 commits April 30, 2026 21:47
Eliminate two-step agent()+toAgent() pattern. agent() returns unified
LangGraphAgent (extends AgentWithHistory) preserving all AgentRef
public surface. Type-level tension resolved via langGraph*-prefixed
raw signals (langGraphMessages, langGraphHistory, etc.) alongside
runtime-neutral fields. Breaking change; no compat aliases.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks: lib refactor (define LangGraphAgent, fold to-agent translation
into agent.fn, delete to-agent.ts, refactor mocks, conformance test),
cockpit migration (~23 demos), website docs migration (~20 files), final
verify + PR. Three commits sequenced to keep each step build-clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Eliminate two-step agent()+toAgent() pattern. agent() now returns
LangGraphAgent extending AgentWithHistory with the full LangGraph-
specific surface preserved (langGraph*-prefixed raw signals where
type collisions exist with the runtime-neutral chat contract).

- Define LangGraphAgent in agent.types.ts
- Fold to-agent translation logic into agent.fn.ts
- Delete to-agent.ts and its specs
- Add agent.conformance.spec.ts (runAgentConformance suite)
- Rename mockAgentRef → mockLangGraphAgent (mock-langgraph-agent.ts)
- public-api.ts: drop toAgent, AgentRef, createMockAgentRef;
  add LangGraphAgent, mockLangGraphAgent

BREAKING: AgentRef is no longer exported. agent() return type changed
from AgentRef to LangGraphAgent. toAgent() removed entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…hAgent

25 cockpit angular demos updated. The two field initializers
(stream = agent({...}); chatAgent = toAgent(this.stream)) collapse
to a single field 'agent'. Code reading raw BaseMessage[] switches to
.langGraphMessages(); chat-template bindings now reference the
unified agent.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Update MDX prose, code samples in chat/agent/render docs to reference
LangGraphAgent + the single agent({...}) flow. Regenerate api-docs.json.
Rename createMockAgentRef doc page to mockLangGraphAgent. Update llms.txt
example to single-step.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cacheplane Ready Ready Preview, Comment May 1, 2026 5:56am
cacheplane-minting-service Error Error May 1, 2026 5:56am

Request Review

…nput

- msg.getType() === 'ai' → msg.role === 'assistant' (Message has 'role',
  not BaseMessage's getType()).
- chat.submit({ messages: [{ role: 'human', content }] } as any) →
  chat.submit({ message: content }) (the runtime-neutral
  AgentSubmitInput shape).
- Drop unused BaseMessage import + generic.

This resolves the TS2339 error that blocked website lint/build CI.
The demo's old code path predates the unification refactor and was
reading raw LangChain types directly off the agent.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@blove blove merged commit 0d3bfd1 into main May 1, 2026
14 of 15 checks passed
blove added a commit that referenced this pull request May 1, 2026
…153)

* chore: regenerate api docs for all 4 libs + drop dead AgentRef interface

1. generate-api-docs.ts: rewrite to iterate over all four publishable
   libraries (langgraph, chat, render, ag-ui). The old script only
   knew about a single 'libs/angular' entry point that hasn't existed
   since the rename. Output now goes to:
   - apps/website/content/docs/agent/api/  (from libs/langgraph)
   - apps/website/content/docs/chat/api/   (from libs/chat)
   - apps/website/content/docs/render/api/ (from libs/render)
   - apps/website/content/docs/ag-ui/api/  (from libs/ag-ui)
2. Regenerated api-docs.json files reflect the unified LangGraphAgent
   API. Verified: zero residual AgentRef references in agent docs.
3. Drop the unused AgentRef interface from libs/langgraph/src/lib/
   agent.types.ts. Following the unification PR (#152), the type was
   defined but never imported. Comments in agent.fn.ts and
   mock-langgraph-agent.ts that referenced "AgentRef fields preserved"
   stay as historical notes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* docs(plan): fresh-install smoke runbook for ~/tmp/ngaf/smoke-workspace

Manual validation pass to prove @ngaf/*@0.0.1 packages install + build
+ run from npm. Two thin Angular apps share one workspace:
- ag-ui-fake: end-to-end runtime test using FakeAgent (no backend)
- langgraph-build: build-only smoke against published @ngaf/langgraph

Catches packaging bugs, missing peerDeps, broken exports that
internal tsconfig-paths resolution hides.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(libs): packaging bugs blocking npm consumption of 0.0.1

Smoke-tested @ngaf/*@0.0.1 by tarballing dist/ and installing into
a fresh Angular 21 app at ~/tmp/ngaf/smoke-workspace. Three packaging
bugs surfaced; all fixed in this commit.

1. @ngaf/a2ui, @ngaf/partial-json, @ngaf/licensing publish-target
   missing. Their project.json files lacked an explicit
   nx-release-publish target, so Nx Release defaulted to publishing
   the project root (raw source) instead of dist/. Added explicit
   target with packageRoot: "dist/{projectRoot}".

2. @ngaf/a2ui, @ngaf/partial-json built with emitDeclarationOnly:
   true (inherited from tsconfig.base.json). Their dists contained
   only .d.ts files, no .js. Added emitDeclarationOnly: false
   override to libs/a2ui/tsconfig.lib.json and
   libs/partial-json/tsconfig.lib.json.
   (libs/licensing already had this override.)

3. @ngaf/chat bundled vitest into the runtime FESM file.
   runAgentConformance and runAgentWithHistoryConformance import
   { describe, it, expect } from 'vitest' at module level and were
   exported from the main public-api. Moved to a secondary entry
   point @ngaf/chat/testing:
   - Created libs/chat/testing/ng-package.json + public-api.ts
   - git mv'd agent-conformance.ts and agent-with-history-conformance
     .ts (and the conformance spec) into libs/chat/testing/
   - Updated their import of Agent/AgentWithHistory from '../agent'
     to '@ngaf/chat' (cross-entry-point convention)
   - Removed conformance exports from libs/chat/src/public-api.ts
   - Added @ngaf/chat/testing path to tsconfig.base.json
   - Updated internal consumers (libs/ag-ui and libs/langgraph
     conformance specs) to import from @ngaf/chat/testing.

Verified: smoke-app/ag-ui-fake builds (755kB initial), serves at
localhost:4300, no minting-service leakage in dist, all @ngaf/*
packages credited as MIT in 3rdpartylicenses.txt.
smoke-app/langgraph-build builds (606kB initial).

This commit fixes the artifacts; next step is to bump to 0.0.2 and
republish.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
@blove blove deleted the feat/toagent-review branch May 7, 2026 16:30
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