docs/en/agent-integrations/07-langchain-langgraph.md
Wire OpenViking into your LangChain or LangGraph agent as the context backend. The SDK provides a retriever, chat history, context wrapper, agent tools, LangGraph store, and middleware — all connecting to a running OpenViking server over HTTP.
pip install "openviking[langchain]" # retriever + chat history
pip install "openviking[langgraph]" # full LangGraph support (includes langchain)
from openviking.integrations.langchain import create_openviking_tools
tools = create_openviking_tools(
url="http://localhost:1933",
api_key="...",
profile="agent",
)
When url is omitted, the adapters load connection settings from the OpenViking CLI config. Embedding and VLM providers are configured in OpenViking, not in your app.
| I want to… | Use this |
|---|---|
| Retrieve relevant context for RAG | OpenVikingRetriever |
| Wrap a runnable with full session lifecycle (recall + capture + commit) | with_openviking_context() |
| Give the agent explicit memory tools | create_openviking_tools() |
| Store durable cross-thread state | OpenVikingStore |
| Inject context into LangGraph as middleware | OpenVikingContextMiddleware |
| Back LangChain chat history with OpenViking | OpenVikingChatMessageHistory |
from openviking.integrations.langchain import OpenVikingRetriever
retriever = OpenVikingRetriever(url="http://localhost:1933", api_key="...")
docs = retriever.invoke("What did the user decide about deployment?")
from langchain_core.messages import AIMessage
from langchain_core.runnables import RunnableLambda
from openviking.integrations.langchain import with_openviking_context
chain = with_openviking_context(
RunnableLambda(lambda msgs: AIMessage(content="...")),
url="http://localhost:1933",
api_key="...",
)
from openviking.integrations.langchain import create_openviking_tools
tools = create_openviking_tools(url="http://localhost:1933", profile="agent")
# Includes: viking_find, viking_search, viking_browse, viking_read,
# viking_grep, viking_store, viking_add_resource, and more
from openviking.integrations.langchain import OpenVikingStore
store = OpenVikingStore(url="http://localhost:1933", api_key="...")
store.put(("users", "ada"), "preferences", {"color": "azure"})
items = store.search(("users",), query="azure", limit=3)
from openviking.integrations.langchain import OpenVikingContextMiddleware
middleware = OpenVikingContextMiddleware(
url="http://localhost:1933",
api_key="...",
capture_on_after_agent=True,
)
The repository includes runnable examples that work without model credentials using an in-memory test client:
uv run --extra langgraph python examples/langchain-langgraph/langchain/rag/quick_app.py
uv run --extra langgraph python examples/langchain-langgraph/langchain/context-backend/quick_app.py
uv run --extra langgraph python examples/langchain-langgraph/langchain/message-history/quick_app.py
uv run --extra langgraph python examples/langchain-langgraph/langgraph/agent/quick_app.py
uv run --extra langgraph python examples/langchain-langgraph/langgraph/middleware/quick_app.py
For a real OpenViking server and OpenAI-compatible model flow, see the live LangGraph app.