fix(langgraph): inherited RunnableConfig should not prevent stateKey to be read (#1674)

This commit is contained in:
David Duong
2025-09-19 01:01:41 +02:00
committed by GitHub
parent 9cd80c64c9
commit 14cb042c13
2 changed files with 8 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---
Fix `stateKey` property in `pushMessage` being ignored when RunnableConfig is automatically inherited
+3 -10
View File
@@ -4,9 +4,9 @@ import {
coerceMessageLikeToMessage,
} from "@langchain/core/messages";
import type { RunnableConfig } from "@langchain/core/runnables";
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
import { v4 } from "uuid";
import { StateGraph } from "./state.js";
import { ensureLangGraphConfig } from "../pregel/utils/config.js";
import type { StreamMessagesHandler } from "../pregel/messages.js";
export const REMOVE_ALL_MESSAGES = "__remove_all__";
@@ -123,16 +123,9 @@ export function pushMessage(
stateKey?: string | null;
}
) {
const rawOptions:
| (RunnableConfig & { stateKey?: string | null })
| undefined =
options ?? AsyncLocalStorageProviderSingleton.getRunnableConfig();
const { stateKey: userStateKey, ...userConfig } = options ?? {};
const config = ensureLangGraphConfig(userConfig);
if (rawOptions == null) {
throw new Error("Calling pushMessage outside the context of a graph.");
}
const { stateKey: userStateKey, ...config } = rawOptions;
let stateKey: string | undefined = userStateKey ?? "messages";
if (userStateKey === null) stateKey = undefined;