Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/lazy-friends-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---

Fix `stateKey` property in `pushMessage` being ignored when RunnableConfig is automatically inherited
13 changes: 3 additions & 10 deletions libs/langgraph/src/graph/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__";
Expand Down Expand Up @@ -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;

Expand Down
Loading