Cross-chain node communication framework for LangGraph - Enable direct node-to-node communication across multiple LangGraph chains
Project description
LangGraph Cross-Chain Communication Framework
A Python package extending LangGraph to enable cross-chain node communication - allowing nodes in different chains to call and communicate with each other directly.
๐ฏ Project Overview
This framework addresses a critical gap in current AI agent frameworks by enabling:
- Cross-Chain Node Calls: Direct communication between nodes in different chains (Chain1.Node2 โ Chain2.Node3)
- Shared State Management: Share state between separate chain instances
- Dynamic Inter-Chain Workflows: Create flexible workflows that span multiple chains
- Modular Components: Build reusable chain components that can communicate seamlessly
๐ก Innovation Gap Being Addressed
๐ Quick Start
Installation
pip install langgraph-crosschain
Or install from source:
git clone https://github.com/yourusername/langgraph-crosschain.git
cd langgraph-crosschain
pip install -e .
Basic Example
from langgraph.graph import StateGraph
from langgraph_crosschain import ChainRegistry, CrossChainNode
# Create a registry to manage chains
registry = ChainRegistry()
# Define your chains
def analyzer_node(state):
# Process data
return {"analyzed": True, "result": state.get("data")}
def processor_node(state):
# Call a node in another chain
node = CrossChainNode("chain2", "processor", processor_node)
result = node.call_remote("chain1", "analyzer", {"data": "test"})
return {"processed": True, "result": result}
# Build your chains
chain1 = StateGraph(...)
chain2 = StateGraph(...)
# Register chains
registry.register("chain1", chain1.compile())
registry.register("chain2", chain2.compile())
# Now chains can communicate with each other!
๐ Core Components
ChainRegistry
Central registry for managing multiple chain instances:
from langgraph_crosschain import ChainRegistry
registry = ChainRegistry()
registry.register("my_chain", chain_instance)
chain = registry.get("my_chain")
CrossChainNode
Base class for nodes that can communicate across chains:
from langgraph_crosschain import CrossChainNode
node = CrossChainNode(
chain_id="chain1",
node_id="processor",
func=my_node_function
)
# Call a node in another chain
result = node.call_remote("chain2", "analyzer", {"data": "test"})
# Broadcast to multiple chains
node.broadcast(["chain2", "chain3"], "receiver", {"data": "broadcast"})
MessageRouter
Handles routing of messages between chains:
from langgraph_crosschain import MessageRouter
router = MessageRouter()
# Messages are automatically routed by CrossChainNode
SharedStateManager
Manages shared state across multiple chains:
from langgraph_crosschain import SharedStateManager
state_manager = SharedStateManager()
state_manager.set("shared_data", {"key": "value"})
data = state_manager.get("shared_data")
# Subscribe to state changes
def on_change(value):
print(f"State changed: {value}")
state_manager.subscribe("shared_data", on_change)
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Chain Registry โ
โ (Manages all chain instances) โ
โโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโดโโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโโโ โโโโโโโโโโผโโโโโโโ
โ Chain 1 โ โ Chain 2 โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โ โ Node A โ โโโโโโบโ โ Node X โ โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โ โ Node B โ โโโโโโโ โ Node Y โ โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ Message Router โ
โ (Routes messages) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ Shared State Manager โ
โ (Shared state store) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Use Cases
1. Multi-Agent Systems
Create specialized chains for different tasks that collaborate:
# Analytics chain
analytics_chain = build_analytics_chain()
registry.register("analytics", analytics_chain)
# Execution chain
execution_chain = build_execution_chain()
registry.register("execution", execution_chain)
# Chains can now call each other as needed
2. Modular Workflows
Break complex workflows into reusable, communicating components:
# Data ingestion chain
ingestion = build_ingestion_chain()
# Processing chain (calls ingestion)
processing = build_processing_chain()
# Output chain (calls processing)
output = build_output_chain()
3. Distributed Processing
Distribute workload across multiple specialized chains:
# Master chain coordinates work
master_node.broadcast(
["worker1", "worker2", "worker3"],
"process_task",
{"task": task_data}
)
๐งช Testing
Run the test suite:
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=langgraph_crosschain --cov-report=html
๐ง Development
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/langgraph-crosschain.git
cd langgraph-crosschain
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Code Quality
# Format code
black langgraph_crosschain tests
# Lint code
ruff check langgraph_crosschain tests
# Type checking
mypy langgraph_crosschain
๐ Examples
Check out the examples directory for complete working examples:
basic_communication.py- Simple cross-chain communicationshared_state.py- Using shared state between chainsmulti_agent_system.py- Building a multi-agent systemdistributed_workflow.py- Distributed processing example
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built on top of LangGraph
- Inspired by the need for more modular AI agent architectures
- Thanks to all contributors!
๐บ๏ธ Roadmap
- Core cross-chain communication
- Shared state management
- Message routing
- Async/await support
- Distributed execution
- Event streaming
- Performance monitoring
- Web UI for visualization
- More examples and tutorials
Star โญ this repo if you find it useful!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langgraph_crosschain-0.1.2.tar.gz.
File metadata
- Download URL: langgraph_crosschain-0.1.2.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acdabc505a75b9ed732dd961fa3cb5740c920760a929f7f8bd19add1bc59c17c
|
|
| MD5 |
04bfde2c8d0b7e95985c672c1e5898d6
|
|
| BLAKE2b-256 |
12f2330f681ac0696e7c62fe638309d7307666f549187581495836507eab4a0c
|
File details
Details for the file langgraph_crosschain-0.1.2-py3-none-any.whl.
File metadata
- Download URL: langgraph_crosschain-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a1d075f92c01161dd0b354f18acd7fac7ef503c94132762dc3402559648fec9
|
|
| MD5 |
b4140565e1e1138f8f553543f956a13c
|
|
| BLAKE2b-256 |
0b0b08583c0460d0f40cfd07c4d6725c22681000f6c17981ce6c2a557a906af8
|