惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
博客园 - 聂微东
Y
Y Combinator Blog
罗磊的独立博客
博客园_首页
小众软件
小众软件
有赞技术团队
有赞技术团队
爱范儿
爱范儿
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏

Stories by HARSHA J S on Medium

Mastering LangChain 1.2: Part 13 — Agentic RAG: Why Your AI Needs to Decide When to Google Mastering LangChain 1.2: Part 11 — Custom Middleware Hooks: Orchestrating the AI Lifecycle Mastering LangChain 1.2: Part 10 — Human-in-the-Loop: Adding an “Approval” Button to Your AI Agents Mastering LangChain 1.2: Part 9 — Structured Outputs: Turning Messy Chat into Clean Data Mastering LangChain 1.2: Mastering LangChain 1.2: Mastering LangChain 1.2: Part 6 — Dynamic Tool Security: The “Triple-Lock” Guardrail Mastering LangChain 1.2: Part 5 — Dynamic Model Routing: Escalating to Senior AI in Emergencies Mastering LangChain 1.2: Part 4 — Scaling with Middleware and Smart Summarization
Mastering LangChain 1.2: Part 12 — The Elephant’s Memory:...
HARSHA J S · 2026-03-29 · via Stories by HARSHA J S on Medium

HARSHA J S

In Part 12, we will be focusing on Long-Term Memory and Persistent Knowledge.

Press enter or click to view image in full size

In Part 4, we discussed Short-Term Memory (how an agent remembers the current conversation). But what happens when the conversation ends? In most AI setups, the agent “re-boots” and forgets everything it learned during the previous session.

In a professional DevOps environment, this is unacceptable. If an engineer marks a server as “Broken” on Monday, the AI shouldn’t try to deploy to that same server on Tuesday just because it’s a new chat thread.

Today, we are moving beyond chat history and into Long-Term Memory using LangChain 1.2’s BaseStore.

1. The Architecture of Persistence

Unlike chat history (which is a list of messages), Long-Term Memory is a Key-Value Store. Think of it as a hierarchical filing cabinet where the AI can:

  • Put: Save a JSON document under a specific namespace (e.g., "incidents") and a key (e.g., "web-server-1").
  • Get: Retrieve that information by name, even weeks later.
  • Search: Look across different namespaces to find relevant patterns.

In LangChain 1.2, this is handled by the store object, which is accessible inside your tools via the runtime context.

2. Defining “Memory-Aware” Tools

To use this memory, we need to create tools that can talk to the store. Notice how we use Annotated[Any, InjectedToolArg] to hide the "internal plumbing" from the AI model while still giving our Python code the power to save data.

@tool
def mark_server_broken(server_name: str, reason: str, runtime: Annotated[Any, InjectedToolArg]):
"""Saves a permanent note that a server is broken."""
# Access the shared memory store
my_store = runtime.store
user = runtime.context.user_id

# Save the data permanently
data = {"status": "BROKEN", "reason": reason, "reported_by": user}
my_store.put(("incidents",), server_name, data)

return f"✅ MEMORY SAVED: Marked {server_name} as BROKEN."

3. The Deployment Gatekeeper

Now for the magic. We create a second tool for deployments. Before this tool executes any action, it queries the long-term memory to see if there is an active incident report for that server.

@tool
def deploy_application(server_name: str, runtime: Annotated[Any, InjectedToolArg]):
"""Tries to deploy. Refuses if the server is marked 'BROKEN' in memory."""
my_store = runtime.store

# Check the persistent memory
record = my_store.get(("incidents",), server_name)

if record:
info = record.value
return f"🚫 BLOCKING DEPLOYMENT! Memory says {server_name} is BROKEN. Reason: {info['reason']}"

return f"🚀 SUCCESS: Deploying to {server_name}..."

4. Seeing the “Elephant Memory” in Action

Day 1: The Incident

  • Alice (Senior SRE): “Mark web-prod-1 as broken. It has a disk failure.”
  • Agent: Calls
  • mark_server_broken. The data is saved to the persistent InMemoryStore.

Day 2: The Junior’s Attempt (New Session)

  • Bob (Junior): “Deploy the new app to web-prod-1.”
  • Agent: The chat history is empty. The agent has “never talked” to Bob before.
  • The Result: The agent calls
  • deploy_application. The tool checks the store, finds Alice’s record from yesterday, and refuses to deploy.

Conclusion: Knowledge as a Service

By moving beyond simple chat history and implementing a persistent Store, we transform our agents from “Chatbots” into Enterprise Knowledge Bases.

Our AI doesn’t just process text; it maintains a living, breathing record of our infrastructure’s state. It learns from Alice on Monday and uses that knowledge to protect Bob on Tuesday. This level of cross-session intelligence is the hallmark of a truly advanced AI agent.

💬 What do you think?
Drop your thoughts, questions, or suggestions in the comments below!

Check out my YouTube channel for more exciting content! [YouTube Channel Link — Harsha Selvi]

Disclaimer: This text has been rephrased using AI tools, and some parts are derived from various sources to provide a comprehensive overview.

#AI #LangChain #DevOps #DataEngineering #Python #AIEngineering #Automation #KnowledgeManagement #ModernDevelopment