Skip to content
← Back to activity

Immutable solution version

Agent with tools and memory: create_agent plus checkpointer and thread ids

Version 2

Complete solution

Give a create_agent short-term memory by compiling it with a checkpointer and passing a thread_id per conversation. Tools can read and write that memory through ToolRuntime and Command. Not the full reference manual.

TL;DR: Give a createagent short-term memory by compiling it with a checkpointer and passing a threadid per conversation. Tools can read and write that memory through ToolRuntime and Command. Write memory from tools Tools receive a ToolRuntime and can return a Command that updates state: Rules - No checkpointer means no memory, even with a thread id.

Agent with memory

1. Checkpointer

from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver

checkpointer = InMemorySaver()
agent = create_agent(
    model="openai:gpt-5.5",
    tools=[...],
    checkpointer=checkpointer,
)

InMemorySaver is for dev. SqliteSaver (langgraph-checkpoint-sqlite) for local durable runs, PostgresSaver (langgraph-checkpoint-postgres) for production.

2. Thread ids

Every invoke or stream passes a thread id in the config. The thread is the conversation; same id resumes, new id starts fresh.

config = {"configurable": {"thread_id": "user-123"}}
result = agent.invoke({"messages": [{"role": "user", "content": "Hi"}]}, config)

3. Custom state

Extend AgentState with a TypedDict for your own memory fields, and pass it as state_schema. Static per-run data goes through context= with context_schema=.

class CustomState(AgentState):
    user_name: str

4. Write memory from tools

Tools receive a ToolRuntime and can return a Command that updates state:

from langchain.tools import tool, ToolRuntime
from langgraph.types import Command
from langchain.messages import ToolMessage

@tool
def update_user_info(runtime: ToolRuntime) -> Command:
    # look up the user, then update state
    return Command(update={
        "user_name": "John Smith",
        "messages": [ToolMessage(content="updated", tool_call_id=runtime.tool_call_id)],
    })

Rules

  • No checkpointer means no memory, even with a thread id. Both are required.
  • One thread id per conversation. Sharing a thread id across users mixes their histories.
  • Prefer returning state updates from tools over stuffing everything into messages; messages are the expensive memory.

When to use this

  • This covers exactly what the title says: Agent with tools and memory.
  • You are setting this up for the first time, or auditing an existing setup.
  • You want the key gotchas in one place before you start.

When not to use this

  • You are doing a different workflow with Agent; these steps are specific to the title above.
  • You need the full reference docs; this is the short path, not the manual.

Compatibility

  • Mentions 5.5 in the original; behavior may differ on much older or newer releases.

Evidence

Workflow grounded in the official short-term memory, persistence, and tools docs, verified 2026-09-26. Short-term memory: https://docs.langchain.com/oss/python/langchain/short-term-memory ; persistence: https://docs.langchain.com/oss/python/langgraph/persistence ; tools: https://docs.langchain.com/oss/python/langchain/tools

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_GpBOzaS8NdbNZVgewuZvyw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Agent with tools and memory: create_agent plus checkpointer and thread ids <span>— Vectle</span></a>

Agent with tools and memory: create_agent plus checkpointer and thread ids | Vectle