[PR #1918] [MERGED] feat(langgraph): add type bag pattern for GraphNode and ConditionalEdgeRouter #1841

Closed
opened 2026-02-15 20:17:01 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraphjs/pull/1918
Author: @hntrl
Created: 1/21/2026
Status: Merged
Merged: 1/23/2026
Merged by: @hntrl

Base: mainHead: hunter/type-util-type-bag


📝 Commits (10+)

📊 Changes

10 files changed (+1199 additions, -117 deletions)

View changed files

.changeset/type-bag-pattern.md (+36 -0)
📝 libs/langgraph-core/package.json (+2 -2)
📝 libs/langgraph-core/src/graph/index.ts (+3 -0)
📝 libs/langgraph-core/src/graph/state.ts (+37 -5)
📝 libs/langgraph-core/src/graph/types.ts (+257 -32)
libs/langgraph-core/src/tests/state_graph_compat.test-d.ts (+465 -0)
📝 libs/langgraph-core/src/tests/types.test-d.ts (+309 -3)
📝 libs/langgraph-core/src/web.ts (+3 -0)
📝 libs/langgraph-core/tsconfig.json (+17 -5)
📝 pnpm-lock.yaml (+70 -70)

📄 Description

Introduces a flexible type bag pattern that allows specifying separate schemas for input, output, context, and routing nodes in GraphNode and ConditionalEdgeRouter types.

This is a companion PR to the mixed schema support work, enabling nodes to have different input and output schemas with full type safety.

Changes

New exported types

  • GraphNodeTypes<InputSchema, OutputSchema, ContextSchema, Nodes> - Type bag interface for specifying separate schemas for GraphNode
  • GraphNodeReturnValue<Update, Nodes> - Extracted return type helper for node functions
  • ConditionalEdgeRouterTypes<InputSchema, ContextSchema, Nodes> - Type bag interface for ConditionalEdgeRouter (no OutputSchema since routers just read state)

Updated types

Both GraphNode and ConditionalEdgeRouter now support two patterns:

  1. Single schema (backward compatible):

    const node: GraphNode<typeof AgentState, MyContext, "agent" | "tool"> = ...
    
  2. Type bag pattern (new):

    const node: GraphNode<{
      InputSchema: typeof InputSchema;
      OutputSchema: typeof OutputSchema;
      ContextSchema: typeof ContextSchema;
      Nodes: "agent" | "tool";
    }> = (state, runtime) => {
      // state type inferred from InputSchema
      // return type validated against OutputSchema
      // runtime.configurable type inferred from ContextSchema
      return { answer: "response" };
    };
    

Files changed

  • libs/langgraph-core/src/graph/types.ts - Core type definitions with internal helpers
  • libs/langgraph-core/src/graph/index.ts - Export new types
  • libs/langgraph-core/src/web.ts - Export new types for web builds
  • libs/langgraph-core/src/tests/types.test-d.ts - Comprehensive type tests for both patterns

Test plan

  • All 146 existing type tests pass
  • New type tests cover:
    • GraphNode with type bag (StateSchema, Zod, Annotation)
    • ConditionalEdgeRouter with type bag (StateSchema, Zod, Annotation)
    • Input/output/context schema inference
    • Nodes type constraints for Command.goto and Send
    • Backward compatibility with single schema pattern

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraphjs/pull/1918 **Author:** [@hntrl](https://github.com/hntrl) **Created:** 1/21/2026 **Status:** ✅ Merged **Merged:** 1/23/2026 **Merged by:** [@hntrl](https://github.com/hntrl) **Base:** `main` ← **Head:** `hunter/type-util-type-bag` --- ### 📝 Commits (10+) - [`39a91dc`](https://github.com/langchain-ai/langgraphjs/commit/39a91dc142d8858acbc2b70563c2415af2a64da4) feat(langgraph): add mixed schema support for StateGraph input/output - [`7c6553f`](https://github.com/langchain-ai/langgraphjs/commit/7c6553f86c25b521adcfd39d52a91a67788589af) cr - [`d57f190`](https://github.com/langchain-ai/langgraphjs/commit/d57f1901d5e9c49a9a28b6a7c6b6c2f3dd994615) cr - [`2e2b774`](https://github.com/langchain-ai/langgraphjs/commit/2e2b774f922eb26fef655c88bce3c83764dd6f53) cr - [`aa3ee1a`](https://github.com/langchain-ai/langgraphjs/commit/aa3ee1ab54c4531c9b5d44f91501553b440ac2c4) cr - [`b2c5175`](https://github.com/langchain-ai/langgraphjs/commit/b2c517544c6ce6a3b412adfa5ce934ad6a4f6822) feat(langgraph): add type bag pattern for GraphNode and ConditionalEdgeRouter - [`4190743`](https://github.com/langchain-ai/langgraphjs/commit/419074366da9fc545e2997c7c87e16eefe89a6e8) add changeset - [`ba45a79`](https://github.com/langchain-ai/langgraphjs/commit/ba45a799faabd5b76d3c6c668d6589ac238a17a4) cr - [`1c55bc2`](https://github.com/langchain-ai/langgraphjs/commit/1c55bc2be10e4adf19206f23789f7d3f19d92779) cr - [`f04b5b8`](https://github.com/langchain-ai/langgraphjs/commit/f04b5b8bc1efa5725782f1f76d800a1f3942225d) cr ### 📊 Changes **10 files changed** (+1199 additions, -117 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/type-bag-pattern.md` (+36 -0) 📝 `libs/langgraph-core/package.json` (+2 -2) 📝 `libs/langgraph-core/src/graph/index.ts` (+3 -0) 📝 `libs/langgraph-core/src/graph/state.ts` (+37 -5) 📝 `libs/langgraph-core/src/graph/types.ts` (+257 -32) ➕ `libs/langgraph-core/src/tests/state_graph_compat.test-d.ts` (+465 -0) 📝 `libs/langgraph-core/src/tests/types.test-d.ts` (+309 -3) 📝 `libs/langgraph-core/src/web.ts` (+3 -0) 📝 `libs/langgraph-core/tsconfig.json` (+17 -5) 📝 `pnpm-lock.yaml` (+70 -70) </details> ### 📄 Description Introduces a flexible type bag pattern that allows specifying separate schemas for input, output, context, and routing nodes in `GraphNode` and `ConditionalEdgeRouter` types. This is a companion PR to the mixed schema support work, enabling nodes to have different input and output schemas with full type safety. ## Changes ### New exported types - **`GraphNodeTypes<InputSchema, OutputSchema, ContextSchema, Nodes>`** - Type bag interface for specifying separate schemas for GraphNode - **`GraphNodeReturnValue<Update, Nodes>`** - Extracted return type helper for node functions - **`ConditionalEdgeRouterTypes<InputSchema, ContextSchema, Nodes>`** - Type bag interface for ConditionalEdgeRouter (no OutputSchema since routers just read state) ### Updated types Both `GraphNode` and `ConditionalEdgeRouter` now support two patterns: 1. **Single schema** (backward compatible): ```typescript const node: GraphNode<typeof AgentState, MyContext, "agent" | "tool"> = ... ``` 2. **Type bag pattern** (new): ```typescript const node: GraphNode<{ InputSchema: typeof InputSchema; OutputSchema: typeof OutputSchema; ContextSchema: typeof ContextSchema; Nodes: "agent" | "tool"; }> = (state, runtime) => { // state type inferred from InputSchema // return type validated against OutputSchema // runtime.configurable type inferred from ContextSchema return { answer: "response" }; }; ``` ### Files changed - `libs/langgraph-core/src/graph/types.ts` - Core type definitions with internal helpers - `libs/langgraph-core/src/graph/index.ts` - Export new types - `libs/langgraph-core/src/web.ts` - Export new types for web builds - `libs/langgraph-core/src/tests/types.test-d.ts` - Comprehensive type tests for both patterns ## Test plan - [x] All 146 existing type tests pass - [x] New type tests cover: - GraphNode with type bag (StateSchema, Zod, Annotation) - ConditionalEdgeRouter with type bag (StateSchema, Zod, Annotation) - Input/output/context schema inference - Nodes type constraints for Command.goto and Send - Backward compatibility with single schema pattern --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 20:17:01 -05:00
yindo closed this issue 2026-02-15 20:17:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#1841