LangGraph Runtime (In-Memory)
The `langgraph-runtime-inmem` library provides an in-memory implementation for the LangGraph API server's state management, enabling local development and testing of LangGraph agents without requiring an external database. It's designed for ephemeral, single-process usage. Currently at version 0.27.3, it follows the rapid release cadence of the broader LangGraph ecosystem, with frequent updates.
Warnings
- gotcha The `InMemoryGraphRuntime` is ephemeral. All state (including graph run history and current step) is stored only in RAM and will be lost if the server process restarts. It does not support shared state across multiple server instances.
- breaking This library requires Python 3.11 or newer. Attempting to install or run with older Python versions will result in dependency resolution errors or runtime failures.
- gotcha Version alignment between `langgraph-runtime-inmem` and `langgraph` is crucial. Significant API changes in `langgraph` often require corresponding updates in `langgraph-runtime-inmem` to maintain compatibility.
Install
-
pip install langgraph-runtime-inmem
Imports
- InMemoryGraphRuntime
from langgraph_runtime_inmem import InMemoryGraphRuntime
- app
from langgraph_runtime_inmem.server import app
Quickstart
from langgraph.graph import StateGraph
from langgraph_runtime_inmem import InMemoryGraphRuntime
from langgraph_runtime_inmem.server import app
# 1. Define a simple LangGraph
def create_simple_graph():
builder = StateGraph(dict)
builder.add_node("start", lambda x: {"step": "start"})
builder.add_node("end", lambda x: {"step": "end"})
builder.add_edge("start", "end")
builder.set_entry_point("start")
return builder.compile()
# 2. Instantiate the in-memory runtime
runtime = InMemoryGraphRuntime()
# 3. Register your graph with a unique ID
my_graph = create_simple_graph()
runtime.add_graph("my_first_graph", my_graph)
print("Graph 'my_first_graph' registered with the InMemoryGraphRuntime.")
print("To run the API server, execute:")
print("uvicorn langgraph_runtime_inmem.server:app --host 0.0.0.0 --port 8000")
print("You can then interact with the graph via HTTP, e.g., POST /graph/my_first_graph/invoke")
# Example of direct interaction (not via HTTP, for demonstration):
# state = runtime.invoke("my_first_graph", {}, config={})
# print(f"Direct invocation result: {state}")