[PR #6524] feat: Add batch_send utility function for simplified map-reduce workflows #5095

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

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

State: closed
Merged: No


📝 Summary

This PR introduces a new batch_send() utility function that simplifies map-reduce workflows in LangGraph by providing a convenient way to create multiple Send objects for the same node with different arguments. This enhancement reduces boilerplate code and improves readability when implementing parallel processing patterns.

🔧 Changes Made

  • Added batch_send() helper function (libs/langgraph/langgraph/types.py)

    • Creates multiple Send objects for the same target node with different arguments
    • Includes comprehensive docstring with usage examples
    • Exported in __all__ for public API
  • Added comprehensive unit tests (libs/langgraph/tests/test_utils.py)

    • Tests with simple arguments (integers)
    • Tests with dict arguments (common in state graphs)
    • Tests with empty lists
    • Tests with single argument
    • All tests verify correct Send object creation
  • Added repository architecture documentation (REPOSITORY_DIAGRAM.md)

    • Detailed overview of the LangGraph repository structure
    • Component descriptions and relationships
    • Helpful for new contributors and maintainers
  • Added Cursor rules configuration (.cursor/rules/add-tests.mdc)

    • Ensures consistent testing practices
  • Updated AGENTS.md

    • Cleared content for future updates

🎯 Motivation

Map-reduce patterns are common in LangGraph workflows, where you need to invoke the same node multiple times in parallel with different inputs. Previously, developers had to manually create multiple Send objects using list comprehensions or loops:

# Before
return [Send("process_item", item) for item in items]

# After
return batch_send("process_item", items)

The batch_send() function makes this pattern more explicit and easier to read, especially for developers new to LangGraph.

📋 Testing

All tests pass successfully:

  • Unit tests for batch_send() function with various input types
  • Validates correct Send object creation
  • Edge cases covered (empty lists, single items)

🔗 Related Issues

This enhancement addresses the need for simplified map-reduce workflows in LangGraph applications.


Checklist

  • Unit tests added and passing
  • Code follows project style guidelines
  • Documentation updated (docstrings and examples included)
  • Function exported in __all__
  • No breaking changes introduced

📚 Additional Context

The batch_send() function is a thin wrapper around list comprehension that creates Send objects, but provides:

  1. Better code clarity and intent
  2. Consistency across the codebase
  3. Easier discoverability for new users

Example usage in a state graph:

from langgraph.types import batch_send
from langgraph.graph import StateGraph

def split_work(state):
    items = state["items"]
    # Create multiple Send objects to process items in parallel
    return batch_send("process_item", items)

💡 Note: This PR is ready for review. Please provide feedback on the implementation and documentation approach.

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6524 **State:** closed **Merged:** No --- ## 📝 Summary This PR introduces a new `batch_send()` utility function that simplifies map-reduce workflows in LangGraph by providing a convenient way to create multiple `Send` objects for the same node with different arguments. This enhancement reduces boilerplate code and improves readability when implementing parallel processing patterns. ## 🔧 Changes Made - **Added `batch_send()` helper function** (`libs/langgraph/langgraph/types.py`) - Creates multiple `Send` objects for the same target node with different arguments - Includes comprehensive docstring with usage examples - Exported in `__all__` for public API - **Added comprehensive unit tests** (`libs/langgraph/tests/test_utils.py`) - Tests with simple arguments (integers) - Tests with dict arguments (common in state graphs) - Tests with empty lists - Tests with single argument - All tests verify correct `Send` object creation - **Added repository architecture documentation** (`REPOSITORY_DIAGRAM.md`) - Detailed overview of the LangGraph repository structure - Component descriptions and relationships - Helpful for new contributors and maintainers - **Added Cursor rules configuration** (`.cursor/rules/add-tests.mdc`) - Ensures consistent testing practices - **Updated `AGENTS.md`** - Cleared content for future updates ## 🎯 Motivation Map-reduce patterns are common in LangGraph workflows, where you need to invoke the same node multiple times in parallel with different inputs. Previously, developers had to manually create multiple `Send` objects using list comprehensions or loops: ```python # Before return [Send("process_item", item) for item in items] # After return batch_send("process_item", items) ``` The `batch_send()` function makes this pattern more explicit and easier to read, especially for developers new to LangGraph. ## 📋 Testing All tests pass successfully: - ✅ Unit tests for `batch_send()` function with various input types - ✅ Validates correct `Send` object creation - ✅ Edge cases covered (empty lists, single items) ## 🔗 Related Issues This enhancement addresses the need for simplified map-reduce workflows in LangGraph applications. --- ## ✅ Checklist - [x] Unit tests added and passing - [x] Code follows project style guidelines - [x] Documentation updated (docstrings and examples included) - [x] Function exported in `__all__` - [x] No breaking changes introduced --- ## 📚 Additional Context The `batch_send()` function is a thin wrapper around list comprehension that creates `Send` objects, but provides: 1. Better code clarity and intent 2. Consistency across the codebase 3. Easier discoverability for new users Example usage in a state graph: ```python from langgraph.types import batch_send from langgraph.graph import StateGraph def split_work(state): items = state["items"] # Create multiple Send objects to process items in parallel return batch_send("process_item", items) ``` > 💡 **Note:** This PR is ready for review. Please provide feedback on the implementation and documentation approach.
yindo added the pull-request label 2026-02-20 17:51:13 -05:00
yindo closed this issue 2026-02-20 17:51:13 -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#5095