deep-agents-memory

作成者: langchain-ai

Pluggable memory and file backends for Deep Agents with ephemeral, persistent, and hybrid routing options. Four backend types: StateBackend (thread-scoped, ephemeral), StoreBackend (cross-session persistent), FilesystemBackend (real disk access for local dev), and CompositeBackend (route different paths to different backends) FilesystemMiddleware provides six file operation tools: ls , read_file , write_file , edit_file , glob , grep CompositeBackend uses longest-prefix matching to route...

npx skills add https://github.com/langchain-ai/langchain-skills --skill deep-agents-memory
Deep Agents use pluggable backends for file operations and memory:

Short-term (StateBackend): Persists within a single thread, lost when thread ends Long-term (StoreBackend): Persists across threads and sessions Hybrid (CompositeBackend): Route different paths to different backends

FilesystemMiddleware provides tools: ls, read_file, write_file, edit_file, glob, grep

Use CaseBackendWhy
Temporary working filesStateBackendDefault, no setup
Local development CLIFilesystemBackendDirect disk access
Cross-session memoryStoreBackendPersists across threads
Hybrid storageCompositeBackendMix ephemeral + persistent
Default StateBackend stores files ephemerally within a thread.
from deepagents import create_deep_agent

agent = create_deep_agent()  # Default: StateBackend
result = agent.invoke({
    "messages": [{"role": "user", "content": "Write notes to /draft.txt"}]
}, config={"configurable": {"thread_id": "thread-1"}})
# /draft.txt is lost when thread ends
Default StateBackend stores files ephemerally within a thread.
import { createDeepAgent } from "deepagents";

const agent = await createDeepAgent();  // Default: StateBackend
const result = await agent.invoke({
  messages: [{ role: "user", content: "Write notes to /draft.txt" }]
}, { configurable: { thread_id: "thread-1" } });
// /draft.txt is lost when thread ends
Configure CompositeBackend to route paths to different storage backends.
from deepagents import create_deep_agent
from deepagents.backends import CompositeBackend, StateBackend, StoreBackend
from langgraph.store.memory import InMemoryStore

store = InMemoryStore()

composite_backend = lambda rt: CompositeBackend(
    default=StateBackend(rt),
    routes={"/memories/": StoreBackend(rt)}
)

agent = create_deep_agent(backend=composite_backend, store=store)

# /draft.txt -> ephemeral (StateBackend)
# /memories/user-prefs.txt -> persistent (StoreBackend)
Configure CompositeBackend to route paths to different storage backends.
import { createDeepAgent, CompositeBackend, StateBackend, StoreBackend } from "deepagents";
import { InMemoryStore } from "@langchain/langgraph";

const store = new InMemoryStore();

const agent = await createDeepAgent({
  backend: (config) => new CompositeBackend(
    new StateBackend(config),
    { "/memories/": new StoreBackend(config) }
  ),
  store
});

// /draft.txt -> ephemeral (StateBackend)
// /memories/user-prefs.txt -> persistent (StoreBackend)
Files in /memories/ persist across threads via StoreBackend routing.
# Using CompositeBackend from previous example
config1 = {"configurable": {"thread_id": "thread-1"}}
agent.invoke({"messages": [{"role": "user", "content": "Save to /memories/style.txt"}]}, config=config1)

config2 = {"configurable": {"thread_id": "thread-2"}}
agent.invoke({"messages": [{"role": "user", "content": "Read /memories/style.txt"}]}, config=config2)
# Thread 2 can read file saved by Thread 1
Files in /memories/ persist across threads via StoreBackend routing.
// Using CompositeBackend from previous example
const config1 = { configurable: { thread_id: "thread-1" } };
await agent.invoke({ messages: [{ role: "user", content: "Save to /memories/style.txt" }] }, config1);

const config2 = { configurable: { thread_id: "thread-2" } };
await agent.invoke({ messages: [{ role: "user", content: "Read /memories/style.txt" }] }, config2);
// Thread 2 can read file saved by Thread 1
Use FilesystemBackend for local development with real disk access and human-in-the-loop.
from deepagents import create_deep_agent
from deepagents.backends import FilesystemBackend
from langgraph.checkpoint.memory import MemorySaver

agent = create_deep_agent(
    backend=FilesystemBackend(root_dir=".", virtual_mode=True),  # Restrict access
    interrupt_on={"write_file": True, "edit_file": True},
    checkpointer=MemorySaver()
)

# Agent can read/write actual files on disk
Use FilesystemBackend for local development with real disk access and human-in-the-loop.
import { createDeepAgent, FilesystemBackend } from "deepagents";
import { MemorySaver } from "@langchain/langgraph";

const agent = await createDeepAgent({
  backend: new FilesystemBackend({ rootDir: ".", virtualMode: true }),
  interruptOn: { write_file: true, edit_file: true },
  checkpointer: new MemorySaver()
});

Security: Never use FilesystemBackend in web servers - use StateBackend or sandbox instead.

Access the store directly in custom tools for long-term memory operations.
from langchain.tools import tool, ToolRuntime
from langchain.agents import create_agent
from langgraph.store.memory import InMemoryStore

@tool
def get_user_preference(key: str, runtime: ToolRuntime) -> str:
    """Get a user preference from long-term storage."""
    store = runtime.store
    result = store.get(("user_prefs",), key)
    return str(result.value) if result else "Not found"

@tool
def save_user_preference(key: str, value: str, runtime: ToolRuntime) -> str:
    """Save a user preference to long-term storage."""
    store = runtime.store
    store.put(("user_prefs",), key, {"value": value})
    return f"Saved {key}={value}"

store = InMemoryStore()

agent = create_agent(
    model="gpt-4.1",
    tools=[get_user_preference, save_user_preference],
    store=store
)
### What Agents CAN Configure
  • Backend type and configuration
  • Routing rules for CompositeBackend
  • Root directory for FilesystemBackend
  • Human-in-the-loop for file operations

What Agents CANNOT Configure

  • Tool names (ls, read_file, write_file, edit_file, glob, grep)
  • Access files outside virtual_mode restrictions
  • Cross-thread file access without proper backend setup
StoreBackend requires a store instance.
# WRONG
agent = create_deep_agent(backend=lambda rt: StoreBackend(rt))

# CORRECT
agent = create_deep_agent(backend=lambda rt: StoreBackend(rt), store=InMemoryStore())
StoreBackend requires a store instance.
// WRONG
const agent = await createDeepAgent({ backend: (c) => new StoreBackend(c) });

// CORRECT
const agent = await createDeepAgent({ backend: (c) => new StoreBackend(c), store: new InMemoryStore() });
StateBackend files are thread-scoped - use same thread_id or StoreBackend for cross-thread access.
# WRONG: thread-2 can't read file from thread-1
agent.invoke({"messages": [...]}, config={"configurable": {"thread_id": "thread-1"}})  # Write
agent.invoke({"messages": [...]}, config={"configurable": {"thread_id": "thread-2"}})  # File not found!
StateBackend files are thread-scoped - use same thread_id or StoreBackend for cross-thread access.
// WRONG: thread-2 can't read file from thread-1
await agent.invoke({ messages: [...] }, { configurable: { thread_id: "thread-1" } });  // Write
await agent.invoke({ messages: [...] }, { configurable: { thread_id: "thread-2" } });  // File not found!
Path must match CompositeBackend route prefix for persistence.
# With routes={"/memories/": StoreBackend(rt)}:
agent.invoke(...)  # /prefs.txt -> ephemeral (no match)
agent.invoke(...)  # /memories/prefs.txt -> persistent (matches route)
Path must match CompositeBackend route prefix for persistence.
// With routes: { "/memories/": StoreBackend }:
await agent.invoke(...);  // /prefs.txt -> ephemeral (no match)
await agent.invoke(...);  // /memories/prefs.txt -> persistent (matches route)
Use PostgresStore for production (InMemoryStore lost on restart).
# WRONG                              # CORRECT
store = InMemoryStore()              store = PostgresStore(connection_string="postgresql://...")
Use PostgresStore for production (InMemoryStore lost on restart).
// WRONG                                    // CORRECT
const store = new InMemoryStore();          const store = new PostgresStore({ connectionString: "..." });
Enable virtual_mode=True to restrict path access (prevents ../ and ~/ escapes).
backend = FilesystemBackend(root_dir="/project", virtual_mode=True)  # Secure
CompositeBackend matches longest prefix first.
routes = {"/mem/": StoreBackend(rt), "/mem/temp/": StateBackend(rt)}
# /mem/file.txt -> StoreBackend, /mem/temp/file.txt -> StateBackend (longer match)

langchain-aiのその他のスキル

langgraph-docs
langchain-ai
LangGraphのドキュメントにアクセスして、ステートフルなエージェントやマルチエージェントワークフローを構築できます。公式のLangGraph Pythonドキュメントを取得し、ステートマシン、グラフベースのエージェント設計、ヒューマンインザループパターンをカバーします。クエリの種類に応じて関連ドキュメントを優先します:ハウツー質問には実装ガイド、理論にはコンセプトページ、エンドツーエンドの例にはチュートリアル、技術詳細にはAPIリファレンスを提供します。自動的に2~4個の最も関連性の高いドキュメントURLを選択し、その内容を取得して回答します。
official
langgraph-human-in-the-loop
langchain-ai
グラフの実行を一時停止し、人間によるレビュー、承認、検証を経て、その入力を反映させて再開します。これには3つのコンポーネントが必要です:チェックポインター(InMemorySaverまたはPostgresSaver)、設定内のスレッドID、そしてJSONシリアライズ可能なインタラプトペイロードです。interrupt(value)は一時停止してデータを表示し、Command(resume=value)は再開してその値を一時停止したノードに返します。interrupt()より前のすべてのコードは再開時に再実行されるため、副作用は冪等である必要があります(insertではなくupsertを使用)。承認ワークフローをサポートします。
official
web-research
langchain-ai
このスキルはウェブリサーチに関連するリクエストに使用します。包括的なウェブリサーチを実施するための構造化されたアプローチを提供します。
official
langchain-oss-primer
langchain-ai
LangChain、Deep Agents、またはLangGraphエージェント構築プロジェクトでは、必ずここから始めてください。他のスキルを選択したり、何かを記述する前に必要な出発点です。
official
skill-creator
langchain-ai
エージェントの機能を専門知識、ワークフロー、ツール連携で拡張する効果的なスキルを作成するためのガイド。このスキルは、ユーザーが…のときに使用します。
official
social-media
langchain-ai
プラットフォーム固有のソーシャルメディア投稿を、調査に基づいたコンテンツと生成された補完画像とともに下書きします。LinkedInの投稿(1,300文字、プロフェッショナルなトーン)とTwitter/Xのスレッド(1ツイートあたり280文字、1/🧵形式)に対応。執筆前にサブエージェントに調査を委任し、その後調査結果を読み、正確性と関連性を確認します。generate_social_imageツールを使用して、小さな画面向けに最適化された大胆でコントラストの高い構図の、目を引くソーシャル画像を自動生成します。
official
deep-agents-memory
langchain-ai
Deep Agents向けのプラグイン可能なメモリおよびファイルバックエンド。エフェメラル、永続、ハイブリッドルーティングオプションを備えています。4種類のバックエンドタイプ:StateBackend(スレッドスコープ、エフェメラル)、StoreBackend(セッションをまたいだ永続)、FilesystemBackend(ローカル開発用の実際のディスクアクセス)、CompositeBackend(異なるパスを異なるバックエンドにルーティング)。FilesystemMiddlewareは6つのファイル操作ツールを提供:ls、read_file、write_file、edit_file、glob、grep。CompositeBackendは最長プレフィックス一致を使用してルーティングします...
official
deep-agents-orchestration
langchain-ai
サブエージェントを調整し、複数ステップのタスクを計画し、機密操作には人間の承認を必要とします。タスクツールを介して専門サブエージェントに作業を委任します。カスタムサブエージェントは独立したツールセットとシステムプロンプトをサポートし、デフォルトの「汎用」サブエージェントはメインエージェント設定を継承します。write_todosを使用して複雑なワークフローを計画・追跡し、保留中、進行中、完了済みの状態でタスクを整理します。呼び出し間での永続性のためにthread_idが必要です。実装...
official