mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-27 12:04:58 +02:00
LangGraph Worker Python gRPC Server
This directory contains a Python implementation of the gRPC server defined in server.proto. The server implements the Worker service which provides methods for streaming nodes and invoking reducers.
Setup
- Install the required dependencies:
pip install -r requirements.txt
- Compile the Protocol Buffer definition to generate Python code:
python compile_proto.py
This will generate the necessary Python modules in the stubs directory.
Server Implementation
The server implementation is in grpc_server.py. It provides:
- A
WorkerServicerclass that implements theWorkerservice defined in the proto file - Methods to register handlers for nodes and reducers
- Helper methods to create write and error events
Running the Server
To run the server:
python grpc_server.py [port]
By default, the server listens on port 50051.
Customizing the Server
To customize the server behavior, modify the register_handlers function in grpc_server.py to register your own node and reducer handlers.
Example:
def register_handlers(servicer: WorkerServicer):
# Custom node handler
def my_node_handler(inputs, config, path):
# Process inputs and return results
return {"output": b"Processed result"}
# Register the handler
servicer.register_node_handler("my_node", my_node_handler)
Protocol Buffer Definition
The Protocol Buffer definition in server.proto defines:
Config: Configuration for checkpointsPregelExecutableTask: Task information for executionEvent: Output events (write or error)Workerservice: Service with methods for streaming nodes and invoking reducers