Skip to content
Open
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
30 changes: 30 additions & 0 deletions integrations/langgraph/typescript/src/__tests__/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ async function runPrepareStream(
]);
}

describe("prepareRegenerateStream payload", () => {
it("preserves context-schema values when regenerating", async () => {
const { agent, capturedPayload } = buildMockedAgent();
(agent as any).assistant = MOCK_ASSISTANT;
(agent as any).activeRun.schemaKeys = {
config: ["model"],
context: ["model"],
};
(agent as any).getCheckpointByMessage = vi.fn().mockResolvedValue({
values: { messages: [] },
checkpoint: { checkpoint_id: "checkpoint-1" },
next: [],
});
(agent as any).client.threads.updateState.mockResolvedValue({
checkpoint: { checkpoint_id: "fork-1" },
});

await agent.prepareRegenerateStream(
{
threadId: "thread-1",
messageCheckpoint: { id: "message-1", type: "human", content: "hi" },
forwardedProps: { config: { configurable: { model: "gpt-5" } } },
} as any,
["values"],
);

expect(capturedPayload.value?.context).toEqual({ model: "gpt-5" });
});
});

// ─── Part A: prepareStream payload shape ─────────────────────────────────────

describe("prepareStream payload partitioning", () => {
Expand Down
18 changes: 18 additions & 0 deletions integrations/langgraph/typescript/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,23 @@ export class LangGraphAgent extends AbstractAgent {
});
}

const contextSchemaKeys = new Set(
this.activeRun!.schemaKeys?.context ?? [],
);
const payloadContext = Object.fromEntries(
Object.entries(payloadConfig?.configurable ?? {}).filter(([key]) =>
contextSchemaKeys.has(key),
),
);
const hasContext = Object.keys(payloadContext).length > 0;
if (hasContext && payloadConfig) {
const { configurable: _configurable, ...configWithoutConfigurable } =
payloadConfig;
payloadConfig = Object.keys(configWithoutConfigurable).length
? configWithoutConfigurable
: undefined;
}

const payload = {
...(input.forwardedProps ?? {}),
input: this.langGraphDefaultMergeState(
Expand All @@ -489,6 +506,7 @@ export class LangGraphAgent extends AbstractAgent {
checkpointId: fork.checkpoint.checkpoint_id!,
streamMode,
config: payloadConfig,
...(hasContext ? { context: payloadContext } : {}),
};
return {
streamResponse: this.client.runs.stream(
Expand Down