Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/langgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dependencies": {
"@langchain/langgraph-checkpoint": "^0.1.1",
"@langchain/langgraph-sdk": "~0.1.0",
"@standard-schema/spec": "^1.0.0",
"uuid": "^10.0.0"
},
"peerDependencies": {
Expand Down
16 changes: 15 additions & 1 deletion libs/langgraph/src/graph/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import type { StandardSchemaV1 } from "@standard-schema/spec";
import { RunnableLike } from "../pregel/runnable_types.js";
import { BaseChannel } from "../channels/base.js";
import { BinaryOperator, BinaryOperatorAggregate } from "../channels/binop.js";
import { LastValue } from "../channels/last_value.js";

export type SingleReducer<ValueType, UpdateType = ValueType> =
| {
state?: StandardSchemaV1<ValueType>;
update?: StandardSchemaV1<UpdateType>;

jsonSchemaExtra?: {
langgraph_nodes?: string[];
langgraph_type?: "prompt" | "messages";
[key: string]: unknown;
};

reducer: BinaryOperator<ValueType, UpdateType>;
default?: () => ValueType;
}
Expand All @@ -18,19 +28,23 @@ export type SingleReducer<ValueType, UpdateType = ValueType> =
| null;

export interface StateDefinition {
[key: string]: BaseChannel | (() => BaseChannel);
[key: string]: BaseChannel | (() => BaseChannel) | StandardSchemaV1;
}

type ExtractValueType<C> = C extends BaseChannel
? C["ValueType"]
: C extends () => BaseChannel
? ReturnType<C>["ValueType"]
: C extends StandardSchemaV1
? StandardSchemaV1.InferOutput<C>
: never;

type ExtractUpdateType<C> = C extends BaseChannel
? C["UpdateType"]
: C extends () => BaseChannel
? ReturnType<C>["UpdateType"]
: C extends StandardSchemaV1
? StandardSchemaV1.InferInput<C>
: never;

export type StateType<SD extends StateDefinition> = {
Expand Down
14 changes: 7 additions & 7 deletions libs/langgraph/src/graph/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ export class StateGraph<
contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>
);

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

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

Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,7 @@ __metadata:
"@langchain/langgraph-sdk": "workspace:*"
"@langchain/openai": "npm:^0.4.0"
"@langchain/scripts": "npm:>=0.1.3 <0.2.0"
"@standard-schema/spec": "npm:^1.0.0"
"@swc/core": "npm:^1.3.90"
"@testing-library/dom": "npm:^10.4.0"
"@tsconfig/recommended": "npm:^1.0.3"
Expand Down Expand Up @@ -3542,6 +3543,13 @@ __metadata:
languageName: node
linkType: hard

"@standard-schema/spec@npm:^1.0.0":
version: 1.0.0
resolution: "@standard-schema/spec@npm:1.0.0"
checksum: 10/aee780cc1431888ca4b9aba9b24ffc8f3073fc083acc105e3951481478a2f4dc957796931b2da9e2d8329584cf211e4542275f188296c1cdff3ed44fd93a8bc8
languageName: node
linkType: hard

"@swc/core-darwin-arm64@npm:1.4.16":
version: 1.4.16
resolution: "@swc/core-darwin-arm64@npm:1.4.16"
Expand Down
Loading