LangGraph Runtime (In-Memory)

0.27.3 · active · verified Fri Apr 10

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

Install

Imports

Quickstart

This quickstart demonstrates how to define a LangGraph, instantiate the `InMemoryGraphRuntime`, and register the graph. It also provides instructions on how to launch the FastAPI server using `uvicorn` to make the graph accessible via HTTP.

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}")

view raw JSON →