Skip to main content

hindsight-langgraph

LangGraph and LangChain integration for Hindsight — persistent long-term memory for AI agents.

Provides three integration patterns:

  • Tools — retain/recall/reflect as LangChain @tool functions for agent-driven memory. Works with both LangChain and LangGraph.
  • Nodes (LangGraph) — pre-built graph nodes for automatic memory injection and storage
  • Memory Instructions — pre-fetch memories into a system prompt string. Works with any LangChain model, no graph needed.

Prerequisites

Installation

pip install hindsight-langgraph

Quick Start: Tools

Bind Hindsight memory tools to your LangGraph agent so it can store and retrieve memories on demand.

from hindsight_langgraph import create_hindsight_tools
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Set HINDSIGHT_API_KEY env var to authenticate
tools = create_hindsight_tools(bank_id="user-123")

agent = create_react_agent(
    ChatOpenAI(model="gpt-4o"),
    tools=tools,
)

result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "Remember that I prefer dark mode"}]}
)

Dynamic Bank IDs with Tools

If you build the agent once and serve multiple users, omit the static bank_id and resolve it per request from config["configurable"]:

tools = create_hindsight_tools(bank_id_from_config="user_id")
agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools=tools)

result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "Remember that I prefer dark mode"}]},
    config={"configurable": {"user_id": "user-456"}},
)

Passing bank_id="user-123" still pins all tool calls to that bank and takes precedence over bank_id_from_config.

Quick Start: Memory Nodes

Add recall and retain nodes to your graph for automatic memory injection before LLM calls and storage after responses.

from hindsight_langgraph import create_recall_node, create_retain_node
from langgraph.graph import StateGraph, MessagesState, START, END

recall = create_recall_node(bank_id="user-123")
retain = create_retain_node(bank_id="user-123")

builder = StateGraph(MessagesState)
builder.add_node("recall", recall)
builder.add_node("agent", agent_node)  # your LLM node
builder.add_node("retain", retain)

builder.add_edge(START, "recall")
builder.add_edge("recall", "agent")
builder.add_edge("agent", "retain")
builder.add_edge("retain", END)

graph = builder.compile()

Dynamic Bank IDs

Use bank_id_from_config to resolve the bank per-request from the graph's config:

recall = create_recall_node(bank_id_from_config="user_id")
retain = create_retain_node(bank_id_from_config="user_id")

# Bank ID resolved at runtime
result = await graph.ainvoke(
    {"messages": [{"role": "user", "content": "hello"}]},
    config={"configurable": {"user_id": "user-456"}},
)

Quick Start: Memory Instructions

Pre-fetch memories and inject them into a system prompt. Works with any LangChain model — no graph needed.

from hindsight_langgraph import memory_instructions
from langchain_openai import ChatOpenAI

get_instructions = memory_instructions(
    bank_id="user-123",
    base_instructions="You are a helpful assistant.",
)

# Each call re-fetches memories, so it stays up to date
instructions = await get_instructions()
response = await ChatOpenAI(model="gpt-4o").ainvoke([
    {"role": "system", "content": instructions},
    {"role": "user", "content": "What do you know about me?"},
])

Configuration

Global config

from hindsight_langgraph import configure

configure(
    api_key="your-api-key",  # or set HINDSIGHT_API_KEY env var
    budget="mid",
    tags=["source:langgraph"],
)

Self-hosted instance

To connect to a self-hosted Hindsight instance instead of Hindsight Cloud:

configure(
    hindsight_api_url="http://localhost:8888",
)

Or pass hindsight_api_url directly to any factory function:

tools = create_hindsight_tools(bank_id="user-123", hindsight_api_url="http://localhost:8888")

Per-call overrides

All factory functions accept client, hindsight_api_url, and api_key to override the global config.

Parameter Description Default
hindsight_api_url Hindsight API URL https://api.hindsight.vectorize.io
api_key API key (or HINDSIGHT_API_KEY env var) None
budget Recall budget: low, mid, high mid
max_tokens Max tokens for recall results 4096
tags Tags applied to retain operations None
recall_tags Tags to filter recall results None
recall_tags_match Tag matching: any, all, any_strict, all_strict any

Requirements

  • Python 3.10+
  • langchain-core >= 0.3.0
  • hindsight-client >= 0.4.0
  • langgraph >= 0.3.0 (only for nodes pattern — install with pip install hindsight-langgraph[langgraph])

Documentation

Metadata

Release files for hindsight-langgraph 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hindsight-langgraph 0.3.1
File Size Uploaded
hindsight_langgraph-0.3.1.tar.gz 179.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hindsight-langgraph 0.3.1
File Interpreter ABI Platform
hindsight_langgraph-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 192.7 kB

Release files / hindsight_langgraph-0.3.1.tar.gz

Download URL hindsight_langgraph-0.3.1.tar.gz
Size 179.0 kB
Tags Source
SHA-256 checksum
How to use checksums
935d1ae0c53e8b87a4969e064fc1276b513f8264a28d96c877f034abe92600c3
BLAKE2b-256 checksum
How to use checksums
2ca6f29f417b94f72d4ad2f69e0851b28fe9969047204761e6bff73b0a8998ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release files / hindsight_langgraph-0.3.1-py3-none-any.whl

Download URL hindsight_langgraph-0.3.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcd76f967aff410be48f9e98bfbcc2fa1c391e402fe1177d14e2002790071a1a
BLAKE2b-256 checksum
How to use checksums
c14c4bf5f119f5a5d0f135f5355dcb2ab1a18f7b5f1019b7e8c1115f0ec1e71a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page