[PR #6523] feat: add batch_send utility function for map-reduce workflows #5093

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/6523

State: closed
Merged: No


📝 Summary

This PR introduces a new convenience function batch_send() to simplify map-reduce workflows in LangGraph. Instead of manually writing list comprehensions with Send objects for parallel node execution, developers can now use this cleaner helper function.

🔧 Changes Made

1. Added batch_send() function

File: libs/langgraph/langgraph/types.py

  • New utility function that creates multiple Send objects for the same node
  • Simplifies map-reduce patterns where one node needs to be invoked multiple times in parallel
  • Includes comprehensive docstring with usage example
  • Added to __all__ exports for public API

2. Added comprehensive unit tests

File: libs/langgraph/tests/test_utils.py

  • Test with simple arguments (integers)
  • Test with dictionary arguments (common in state graphs)
  • Test with empty lists
  • Test with single argument
  • Ensures correct Send object creation

3. Added repository architecture documentation

File: REPOSITORY_DIAGRAM.md

  • Comprehensive overview of LangGraph monorepo structure
  • Visual dependency graphs using Mermaid diagrams
  • Detailed explanation of each library (checkpoint, langgraph, prebuilt, CLI, SDKs)
  • Core concepts and workflow diagrams
  • Development guide and learning path

4. Cleared AGENTS.md

  • Removed previous content

💡 Motivation

The new batch_send() function improves code readability and reduces boilerplate for common map-reduce patterns:

Before (Manual List Comprehension):

def continue_to_jokes(state: OverallState):
    return [Send("generate_joke", {"subject": s}) for s in state["subjects"]]

After (Using batch_send):

from langgraph.types import batch_send

def continue_to_jokes(state: OverallState):
    return batch_send("generate_joke", [{"subject": s} for s in state["subjects"]])

This makes the intent clearer and is more maintainable.

Checklist

  • Unit Tests added (4 comprehensive test cases)
  • Code follows existing patterns and style
  • Function properly exported in __all__
  • Comprehensive documentation added to function with examples
  • Repository documentation enhanced with visual diagrams
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6523 **State:** closed **Merged:** No --- ## 📝 Summary This PR introduces a new convenience function `batch_send()` to simplify map-reduce workflows in LangGraph. Instead of manually writing list comprehensions with `Send` objects for parallel node execution, developers can now use this cleaner helper function. ## 🔧 Changes Made ### 1. Added `batch_send()` function **File:** `libs/langgraph/langgraph/types.py` - New utility function that creates multiple `Send` objects for the same node - Simplifies map-reduce patterns where one node needs to be invoked multiple times in parallel - Includes comprehensive docstring with usage example - Added to `__all__` exports for public API ### 2. Added comprehensive unit tests **File:** `libs/langgraph/tests/test_utils.py` - Test with simple arguments (integers) - Test with dictionary arguments (common in state graphs) - Test with empty lists - Test with single argument - Ensures correct `Send` object creation ### 3. Added repository architecture documentation **File:** `REPOSITORY_DIAGRAM.md` - Comprehensive overview of LangGraph monorepo structure - Visual dependency graphs using Mermaid diagrams - Detailed explanation of each library (checkpoint, langgraph, prebuilt, CLI, SDKs) - Core concepts and workflow diagrams - Development guide and learning path ### 4. Cleared AGENTS.md - Removed previous content ## 💡 Motivation The new `batch_send()` function improves code readability and reduces boilerplate for common map-reduce patterns: **Before (Manual List Comprehension):** ```python def continue_to_jokes(state: OverallState): return [Send("generate_joke", {"subject": s}) for s in state["subjects"]] ``` **After (Using batch_send):** ```python from langgraph.types import batch_send def continue_to_jokes(state: OverallState): return batch_send("generate_joke", [{"subject": s} for s in state["subjects"]]) ``` This makes the intent clearer and is more maintainable. ## ✅ Checklist - [x] Unit Tests added (4 comprehensive test cases) - [x] Code follows existing patterns and style - [x] Function properly exported in `__all__` - [x] Comprehensive documentation added to function with examples - [x] Repository documentation enhanced with visual diagrams
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#5093