ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Add Memory + Routing to a LangChain Agent
Tutorial

How to Add Memory + Routing to a LangChain Agent

An r/LangChain post called LangChain agents amnesic. Walk-through: LangGraph state + Scavio MCP named tools to fix routing and memory.

Get Free API KeyAPI Docs

An r/LangChain post described production LangChain agents as amnesic. The fix has two parts: cross-turn state (LangGraph) and unambiguous tool routing (clearly named MCP tools). This walks both.

Prerequisites

  • LangChain 0.3+
  • LangGraph
  • Scavio API key + langchain-scavio
  • Postgres or SQLite for checkpoint storage

Walkthrough

Step 1: Install LangGraph and the Scavio tool

Both ship as standard PyPI packages.

Bash
pip install langgraph langchain-scavio langchain-anthropic

Step 2: Define the state shape

Track conversation history + tool-call decisions.

Python
from typing import TypedDict, List
from langgraph.graph import StateGraph, END

class AgentState(TypedDict):
    messages: List
    last_tool: str
    decisions: List[str]

Step 3: Wire Scavio's named tools

Each tool has a clear semantic name; the LLM routes by name.

Python
from langchain_scavio import ScavioSearchTool, ScavioRedditTool, ScavioYoutubeTool
tools = [
    ScavioSearchTool(name='web_search'),
    ScavioRedditTool(name='reddit_search'),
    ScavioYoutubeTool(name='youtube_search'),
]

Step 4: Add a checkpointer for cross-turn memory

SQLite for dev, Postgres for prod.

Python
from langgraph.checkpoint.sqlite import SqliteSaver
checkpointer = SqliteSaver.from_conn_string(':memory:')  # or 'agent.db'
graph = builder.compile(checkpointer=checkpointer)

Step 5: Invoke with a thread_id for persistent memory

Each thread_id is a separate conversation memory.

Python
config = {'configurable': {'thread_id': 'user-42'}}
result = graph.invoke({'messages': [HumanMessage('Find top AI agent threads')]}, config=config)

Python Example

Python
# The state survives across turns; the agent recalls prior tool calls and decisions.

JavaScript Example

JavaScript
// LangGraph is Python-first. JS-side, use LangChain.js with manual state in a KV store.

Expected Output

JSON
Agent that remembers prior turns and routes correctly because tools have semantic names (web_search, reddit_search, youtube_search) instead of generic 'search_v1'.

Related Tutorials

  • How to Build an MCP Routing Layer for Multi-Server Agents

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

LangChain 0.3+. LangGraph. Scavio API key + langchain-scavio. Postgres or SQLite for checkpoint storage. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Tools for Agent Memory and Routing in 2026

Read more
Solution

Agent Memory + Routing Stack

Read more
Use Case

Production Agent Memory + Routing Architecture

Read more
Glossary

Agent Routing Layer

Read more
Solution

Agent Memory with Search Grounding

Read more
Use Case

LangGraph Agent with Memory and Search

Read more

Start Building

An r/LangChain post called LangChain agents amnesic. Walk-through: LangGraph state + Scavio MCP named tools to fix routing and memory.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy