LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    LangGraph Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph.prebuilttool_nodeInjectedStore
    Class●Since v0.1

    InjectedStore

    Annotation for injecting persistent store into tool arguments.

    This annotation enables tools to access LangGraph's persistent storage system without exposing storage details to the language model. Tools annotated with InjectedStore receive the store instance automatically during execution while remaining invisible to the model's tool-calling interface.

    The store provides persistent, cross-session data storage that tools can use for maintaining context, user preferences, or any other data that needs to persist beyond individual workflow executions.

    Warning

    InjectedStore annotation requires langchain-core >= 0.3.8

    Copy
    InjectedStore()

    Bases

    InjectedToolArg

    Example:

    from typing_extensions import Annotated
    from langgraph.store.memory import InMemoryStore
    from langchain.tools import InjectedStore, ToolNode, tool
    
    @tool
    def save_preference(
        key: str,
        value: str,
        store: Annotated[Any, InjectedStore()]
    ) -> str:
        """Save user preference to persistent storage."""
        store.put(("preferences",), key, value)
        return f"Saved {key} = {value}"
    
    @tool
    def get_preference(
        key: str,
        store: Annotated[Any, InjectedStore()]
    ) -> str:
        """Retrieve user preference from persistent storage."""
        result = store.get(("preferences",), key)
        return result.value if result else "Not found"

    Usage with ToolNode and graph compilation:

    from langgraph.graph import StateGraph
    from langgraph.store.memory import InMemoryStore
    
    store = InMemoryStore()
    tool_node = ToolNode([save_preference, get_preference])
    
    graph = StateGraph(State)
    graph.add_node("tools", tool_node)
    compiled_graph = graph.compile(store=store)  # Store is injected automatically

    Cross-session persistence:

    # First session
    result1 = graph.invoke({"messages": [HumanMessage("Save my favorite color as blue")]})
    
    # Later session - data persists
    result2 = graph.invoke({"messages": [HumanMessage("What's my favorite color?")]})
    • InjectedStore arguments are automatically excluded from tool schemas presented to language models
    • The store instance is automatically injected by ToolNode during execution
    • Tools can access namespaced storage using the store's get/put methods
    • Store injection requires the graph to be compiled with a store instance
    • Multiple tools can share the same store instance for data consistency
    View source on GitHub