[PR #6878] feat(langgraph): add messages_key filtering for message streams #5369

Open
opened 2026-02-20 17:51:36 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6878

State: open
Merged: No


Description

Adds configurable key filtering for stream_mode="messages" so users can restrict message streaming to specific state key(s), preventing unintended leakage from internal message fields.

What changed

  • Added messages_key support to runtime streaming APIs:
    • Pregel.stream(..., messages_key=...)
    • Pregel.astream(..., messages_key=...)
  • Added compile-time default:
    • StateGraph.compile(messages_key=...)
  • Updated StreamMessagesHandler to filter emitted state messages by key when configured.
  • Preserved existing behavior by default (messages_key=None still streams all message-like fields).
  • Added sync + async regression tests and a standalone repro script:
    • tests/test_pregel.py::test_stream_mode_messages_with_messages_key_filter
    • tests/test_pregel_async.py::test_stream_mode_messages_with_messages_key_filter
    • reproduce_issue_6798.py

Issue

Closes #6798

Dependencies

None

Twitter handle

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6878 **State:** open **Merged:** No --- ## Description Adds configurable key filtering for `stream_mode="messages"` so users can restrict message streaming to specific state key(s), preventing unintended leakage from internal message fields. ### What changed - Added `messages_key` support to runtime streaming APIs: - `Pregel.stream(..., messages_key=...)` - `Pregel.astream(..., messages_key=...)` - Added compile-time default: - `StateGraph.compile(messages_key=...)` - Updated `StreamMessagesHandler` to filter emitted state messages by key when configured. - Preserved existing behavior by default (`messages_key=None` still streams all message-like fields). - Added sync + async regression tests and a standalone repro script: - `tests/test_pregel.py::test_stream_mode_messages_with_messages_key_filter` - `tests/test_pregel_async.py::test_stream_mode_messages_with_messages_key_filter` - `reproduce_issue_6798.py` ## Issue Closes #6798 ## Dependencies None ## Twitter handle
yindo added the pull-request label 2026-02-20 17:51:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#5369