LangGraph Adapter

Status: ✅ Full
Language: Python
Package: hippocortex[langgraph]

Install

pip install hippocortex[langgraph]

Quick Start

from hippocortex.adapters import langgraph as hx_langgraph

# Build your graph normally
graph = builder.compile()

# Wrap with memory
graph = hx_langgraph.wrap(graph, api_key="hx_live_...")

# Use normally — memory is automatic
result = await graph.ainvoke({"messages": [{"role": "user", "content": "deploy"}]})

Supported Methods

MethodDescription
ainvoke()Async invoke with memory hooks
invoke()Sync invoke with memory hooks
astream()Async streaming with per-node capture

What It Does

  1. Before invoke: Extracts the user query from input state, synthesizes context, and prepends a system message.
  2. During stream: Captures each node's output as a tool call event.
  3. After invoke: Captures the final assistant response.

Configuration

graph = hx_langgraph.wrap(
    graph,
    api_key="hx_live_...",       # Required (or set HIPPOCORTEX_API_KEY)
    base_url="http://...",        # Override API URL
    session_id="my-session",      # Custom session ID
    capture_nodes=True,           # Capture node transitions (default: True)
    inject_memory=True,           # Inject synthesized context (default: True)
    input_key="messages",         # Key in state dict for messages (default: "messages")
)

Input Format Support

The adapter extracts user queries from various input formats:

  • {"messages": [{"role": "user", "content": "..."}]} — Standard message format
  • {"messages": [HumanMessage("...")]} — LangChain message objects
  • {"input": "..."} — Simple input key
  • {"question": "..."} — Question key

Proxy Behavior

The HippocortexGraph wrapper proxies all attribute access to the underlying graph, so you can access any graph properties directly:

wrapped = hx_langgraph.wrap(graph, api_key="hx_live_...")
wrapped.get_state(...)  # Proxied to underlying graph

Limitations

  • State checkpointing hooks capture node transitions via astream only. For ainvoke/invoke, only the final input/output is captured.
  • The adapter creates LangChain SystemMessage objects if langchain-core is installed; otherwise falls back to dict format.