Skip to content

Conversation

@leecode
Copy link

@leecode leecode commented Dec 12, 2025

Overview

check for interrupt before messages to ensure interrupts are not skipped when both keys exist in the stream step.

Type of change

Type: Fix bug

Related issues/PRs

Checklist

  • I have read the contributing guidelines
  • I have tested my changes locally using docs dev
  • All code examples have been tested and work correctly
  • I have used root relative paths for internal links
  • I have updated navigation in src/docs.json if needed

Additional notes

Problem

The current SQL agent human-in-the-loop example checks for messages before __interrupt__ in the stream loop:

if "messages" in step:
    step["messages"][-1].pretty_print()
elif "__interrupt__" in step:  # This may never execute
    print("INTERRUPTED:")

This creates a potential bug: if a stream step contains both messages and interrupt keys simultaneously, the interrupt handling block will never execute due to the elif condition.

Solution

Reorder the condition checks to prioritize interrupt detection:

  if "__interrupt__" in step:  # Check interrupt first
      print("INTERRUPTED:")
      interrupt = step["__interrupt__"][0]
      for request in interrupt.value["action_requests"]:
          print(request["description"])
  elif "messages" in step:
      step["messages"][-1].pretty_print()

This ensures that interrupts are always detected and handled correctly, even when messages are present in the same step.

check for __interrupt__ before messages to ensure interrupts are not skipped when both keys exist in the stream step.
@leecode leecode requested a review from lnhsingh as a code owner December 12, 2025 16:59
@github-actions github-actions bot added langchain For docs changes to LangChain oss external User is not a member of langchain-ai labels Dec 12, 2025
@leecode leecode closed this Dec 13, 2025
@leecode leecode reopened this Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external User is not a member of langchain-ai langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant