Skip to content

Commit c38483e

Browse files
committed
feat(langgraph): add support for standard schema in state definition
1 parent c9c8092 commit c38483e

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

libs/langgraph/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"@langchain/langgraph-checkpoint": "^0.1.0",
3636
"@langchain/langgraph-sdk": "~0.0.105",
37+
"@standard-schema/spec": "^1.0.0",
3738
"uuid": "^10.0.0",
3839
"zod": "^3.25.32"
3940
},

libs/langgraph/src/graph/annotation.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
import type { StandardSchemaV1 } from "@standard-schema/spec";
12
import { RunnableLike } from "../pregel/runnable_types.js";
23
import { BaseChannel } from "../channels/base.js";
34
import { BinaryOperator, BinaryOperatorAggregate } from "../channels/binop.js";
45
import { LastValue } from "../channels/last_value.js";
56

67
export type SingleReducer<ValueType, UpdateType = ValueType> =
78
| {
9+
state?: StandardSchemaV1<ValueType>;
10+
update?: StandardSchemaV1<UpdateType>;
11+
12+
jsonSchemaExtra?: {
13+
langgraph_nodes?: string[];
14+
langgraph_type?: "prompt" | "messages";
15+
[key: string]: unknown;
16+
};
17+
818
reducer: BinaryOperator<ValueType, UpdateType>;
919
default?: () => ValueType;
1020
}
@@ -18,19 +28,23 @@ export type SingleReducer<ValueType, UpdateType = ValueType> =
1828
| null;
1929

2030
export interface StateDefinition {
21-
[key: string]: BaseChannel | (() => BaseChannel);
31+
[key: string]: BaseChannel | (() => BaseChannel) | StandardSchemaV1;
2232
}
2333

2434
type ExtractValueType<C> = C extends BaseChannel
2535
? C["ValueType"]
2636
: C extends () => BaseChannel
2737
? ReturnType<C>["ValueType"]
38+
: C extends StandardSchemaV1
39+
? StandardSchemaV1.InferOutput<C>
2840
: never;
2941

3042
type ExtractUpdateType<C> = C extends BaseChannel
3143
? C["UpdateType"]
3244
: C extends () => BaseChannel
3345
? ReturnType<C>["UpdateType"]
46+
: C extends StandardSchemaV1
47+
? StandardSchemaV1.InferInput<C>
3448
: never;
3549

3650
export type StateType<SD extends StateDefinition> = {

libs/langgraph/src/graph/state.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,18 @@ export class StateGraph<
279279
contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>
280280
);
281281

282-
/** @deprecated Use `Annotation.Root` or `zod` for state definition instead. */
283282
constructor(
284-
fields: SD extends StateDefinition
285-
? SD | StateGraphArgs<S>
286-
: StateGraphArgs<S>,
283+
fields: SD extends InteropZodObject
284+
? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>
285+
: never,
287286
contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>
288287
);
289288

289+
/** @deprecated Use `Annotation.Root` or `zod` for state definition instead. */
290290
constructor(
291-
fields: SD extends InteropZodObject
292-
? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>
293-
: never,
291+
fields: SD extends StateDefinition
292+
? SD | StateGraphArgs<S>
293+
: StateGraphArgs<S>,
294294
contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>
295295
);
296296

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ __metadata:
21722172
"@langchain/langgraph-sdk": "workspace:*"
21732173
"@langchain/openai": "npm:^0.4.0"
21742174
"@langchain/scripts": "npm:>=0.1.3 <0.2.0"
2175+
"@standard-schema/spec": "npm:^1.0.0"
21752176
"@swc/core": "npm:^1.3.90"
21762177
"@testing-library/dom": "npm:^10.4.0"
21772178
"@tsconfig/recommended": "npm:^1.0.3"
@@ -3107,6 +3108,13 @@ __metadata:
31073108
languageName: node
31083109
linkType: hard
31093110

3111+
"@standard-schema/spec@npm:^1.0.0":
3112+
version: 1.0.0
3113+
resolution: "@standard-schema/spec@npm:1.0.0"
3114+
checksum: 10/aee780cc1431888ca4b9aba9b24ffc8f3073fc083acc105e3951481478a2f4dc957796931b2da9e2d8329584cf211e4542275f188296c1cdff3ed44fd93a8bc8
3115+
languageName: node
3116+
linkType: hard
3117+
31103118
"@swc/core-darwin-arm64@npm:1.4.16":
31113119
version: 1.4.16
31123120
resolution: "@swc/core-darwin-arm64@npm:1.4.16"

0 commit comments

Comments
 (0)