refactor(langgraph): unify agent() return type as LangGraphAgent#152
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…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>
2 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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
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
AgentRefinterface 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
🤖 Generated with Claude Code