Skip to main content

Cross-chain node communication framework for LangGraph - Enable direct node-to-node communication across multiple LangGraph chains

Project description

LangGraph Cross-Chain Communication Framework

Python 3.9+ License: MIT

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 communication
  • shared_state.py - Using shared state between chains
  • multi_agent_system.py - Building a multi-agent system
  • distributed_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgraph_crosschain-0.1.2.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgraph_crosschain-0.1.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

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

Hashes for langgraph_crosschain-0.1.2.tar.gz
Algorithm Hash digest
SHA256 acdabc505a75b9ed732dd961fa3cb5740c920760a929f7f8bd19add1bc59c17c
MD5 04bfde2c8d0b7e95985c672c1e5898d6
BLAKE2b-256 12f2330f681ac0696e7c62fe638309d7307666f549187581495836507eab4a0c

See more details on using hashes here.

File details

Details for the file langgraph_crosschain-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langgraph_crosschain-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a1d075f92c01161dd0b354f18acd7fac7ef503c94132762dc3402559648fec9
MD5 b4140565e1e1138f8f553543f956a13c
BLAKE2b-256 0b0b08583c0460d0f40cfd07c4d6725c22681000f6c17981ce6c2a557a906af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page