Skip to content

Commit 14cb042

Browse files
authored
fix(langgraph): inherited RunnableConfig should not prevent stateKey to be read (#1674)
1 parent 9cd80c6 commit 14cb042

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

.changeset/lazy-friends-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@langchain/langgraph": patch
3+
---
4+
5+
Fix `stateKey` property in `pushMessage` being ignored when RunnableConfig is automatically inherited

libs/langgraph/src/graph/message.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
coerceMessageLikeToMessage,
55
} from "@langchain/core/messages";
66
import type { RunnableConfig } from "@langchain/core/runnables";
7-
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
87
import { v4 } from "uuid";
98
import { StateGraph } from "./state.js";
9+
import { ensureLangGraphConfig } from "../pregel/utils/config.js";
1010
import type { StreamMessagesHandler } from "../pregel/messages.js";
1111

1212
export const REMOVE_ALL_MESSAGES = "__remove_all__";
@@ -123,16 +123,9 @@ export function pushMessage(
123123
stateKey?: string | null;
124124
}
125125
) {
126-
const rawOptions:
127-
| (RunnableConfig & { stateKey?: string | null })
128-
| undefined =
129-
options ?? AsyncLocalStorageProviderSingleton.getRunnableConfig();
126+
const { stateKey: userStateKey, ...userConfig } = options ?? {};
127+
const config = ensureLangGraphConfig(userConfig);
130128

131-
if (rawOptions == null) {
132-
throw new Error("Calling pushMessage outside the context of a graph.");
133-
}
134-
135-
const { stateKey: userStateKey, ...config } = rawOptions;
136129
let stateKey: string | undefined = userStateKey ?? "messages";
137130
if (userStateKey === null) stateKey = undefined;
138131

0 commit comments

Comments
 (0)