Skip to content

Commit 2e378a5

Browse files
committed
fix: fix both lg hitl post interrupt calls
1 parent 19294ec commit 2e378a5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[st
118118
config["configurable"] = {**(config.get('configurable', {})), "thread_id": thread_id}
119119

120120
agent_state = await self.graph.aget_state(config)
121-
self.active_run["mode"] = "continue" if thread_id and self.active_run.get("node_name") != "__end__" and self.active_run.get("node_name") else "start"
121+
resume_input = forwarded_props.get('command', {}).get('resume', None)
122+
123+
if resume_input is None and thread_id and self.active_run.get("node_name") != "__end__" and self.active_run.get("node_name"):
124+
self.active_run["mode"] = "continue"
125+
else:
126+
self.active_run["mode"] = "start"
122127

123128
prepared_stream_response = await self.prepare_stream(input=input, agent_state=agent_state, config=config)
124129

@@ -264,6 +269,7 @@ async def prepare_stream(self, input: RunAgentInput, agent_state: State, config:
264269
interrupts = agent_state.tasks[0].interrupts if agent_state.tasks and len(agent_state.tasks) > 0 else []
265270
has_active_interrupts = len(interrupts) > 0
266271
resume_input = forwarded_props.get('command', {}).get('resume', None)
272+
267273
self.active_run["schema_keys"] = self.get_schema_keys(config)
268274

269275
non_system_messages = [msg for msg in langchain_messages if not isinstance(msg, SystemMessage)]

typescript-sdk/integrations/langgraph/src/agent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ export class LangGraphAgent extends AbstractAgent {
257257
this.activeRun!.graphInfo = await this.client.assistants.getGraph(this.assistant.assistant_id);
258258

259259
const mode =
260-
threadId && this.activeRun!.nodeName != "__end__" && this.activeRun!.nodeName
260+
!forwardedProps?.command?.resume && threadId && this.activeRun!.nodeName != "__end__" && this.activeRun!.nodeName
261261
? "continue"
262262
: "start";
263263

264-
if (mode === "continue" && !forwardedProps?.command?.resume) {
264+
if (mode === "continue") {
265265
const nodeBefore = this.activeRun!.graphInfo.edges.find(e => e.target === this.activeRun!.nodeName);
266266
await this.client.threads.updateState(threadId, {
267267
values: inputState,
@@ -447,7 +447,7 @@ export class LangGraphAgent extends AbstractAgent {
447447
event: chunkData,
448448
});
449449

450-
this.handleSingleEvent(chunkData, state);
450+
this.handleSingleEvent(chunkData);
451451
}
452452

453453
state = await this.client.threads.getState(threadId);
@@ -500,7 +500,7 @@ export class LangGraphAgent extends AbstractAgent {
500500
}
501501
}
502502

503-
handleSingleEvent(event: any, state: State): void {
503+
handleSingleEvent(event: any): void {
504504
switch (event.event) {
505505
case LangGraphEventTypes.OnChatModelStream:
506506
let shouldEmitMessages = event.metadata["emit-messages"] ?? true;

0 commit comments

Comments
 (0)