deep-agents-memory

Các backend bộ nhớ và tệp có thể cắm cho Deep Agents với các tùy chọn định tuyến tạm thời, bền vững và kết hợp. Bốn loại backend: StateBackend (theo luồng, tạm thời), StoreBackend (bền vững xuyên phiên), FilesystemBackend (truy cập đĩa thực cho phát triển cục bộ) và CompositeBackend (định tuyến các đường dẫn khác nhau đến các backend khác nhau). FilesystemMiddleware cung cấp sáu công cụ thao tác tệp: ls, read_file, write_file, edit_file, glob, grep. CompositeBackend sử dụng so khớp tiền tố dài nhất để định tuyến...

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)

Thêm skills từ langchain-ai

langgraph-docs
langchain-ai
Truy cập tài liệu LangGraph để xây dựng tác nhân có trạng thái và quy trình làm việc đa tác nhân. Lấy tài liệu Python chính thức của LangGraph bao gồm máy trạng thái, thiết kế tác nhân dựa trên đồ thị và các mẫu có sự can thiệp của con người. Ưu tiên tài liệu phù hợp theo loại truy vấn: hướng dẫn triển khai cho câu hỏi cách làm, trang khái niệm cho lý thuyết, hướng dẫn cho ví dụ từ đầu đến cuối và tham chiếu API cho chi tiết kỹ thuật. Tự động chọn 2–4 URL tài liệu phù hợp nhất và truy xuất nội dung của chúng để trả lời...
official
langgraph-human-in-the-loop
langchain-ai
Tạm dừng thực thi đồ thị để con người xem xét, phê duyệt hoặc xác thực, sau đó tiếp tục với đầu vào của họ. Yêu cầu ba thành phần: một bộ kiểm tra điểm dừng (InMemorySaver hoặc PostgresSaver), một ID luồng trong cấu hình và tải trọng ngắt có thể tuần tự hóa JSON. interrupt(value) tạm dừng và hiển thị dữ liệu; Command(resume=value) tiếp tục và trả về giá trị đó cho nút đã tạm dừng. Tất cả mã trước interrupt() sẽ thực thi lại khi tiếp tục, vì vậy các tác dụng phụ phải có tính chất đơn giản (sử dụng upsert, không phải insert). Hỗ trợ quy trình phê duyệt,...
official
web-research
langchain-ai
Sử dụng kỹ năng này cho các yêu cầu liên quan đến nghiên cứu web; nó cung cấp một cách tiếp cận có cấu trúc để thực hiện nghiên cứu web toàn diện
official
langchain-oss-primer
langchain-ai
LUÔN BẮT ĐẦU TỪ ĐÂY cho bất kỳ dự án xây dựng agent LangChain, Deep Agents hoặc LangGraph nào. Điểm khởi đầu bắt buộc trước khi chọn các kỹ năng khác hoặc viết bất kỳ…
official
skill-creator
langchain-ai
Hướng dẫn tạo kỹ năng hiệu quả để mở rộng khả năng của tác nhân với kiến thức chuyên môn, quy trình làm việc hoặc tích hợp công cụ. Sử dụng kỹ năng này khi người dùng…
official
social-media
langchain-ai
Soạn thảo bài đăng mạng xã hội theo từng nền tảng với nội dung dựa trên nghiên cứu và hình ảnh đồng hành được tạo tự động. Hỗ trợ bài đăng LinkedIn (1.300 ký tự với giọng văn chuyên nghiệp) và chuỗi Twitter/X (280 ký tự mỗi tweet theo định dạng 1/🧵). Yêu cầu ủy quyền nghiên cứu cho một trợ lý phụ trước khi viết, sau đó đọc lại kết quả để đảm bảo độ chính xác và phù hợp. Tự động tạo hình ảnh mạng xã hội bắt mắt bằng công cụ generate_social_image với bố cục đậm, tương phản cao, tối ưu cho kích thước nhỏ...
official
deep-agents-orchestration
langchain-ai
Điều phối các tác nhân phụ, lập kế hoạch tác vụ đa bước và yêu cầu phê duyệt của con người cho các thao tác nhạy cảm. Ủy quyền công việc cho các tác nhân phụ chuyên biệt thông qua công cụ tác vụ; các tác nhân phụ tùy chỉnh hỗ trợ bộ công cụ và lời nhắc hệ thống riêng biệt, trong khi tác nhân phụ "đa năng" mặc định kế thừa cấu hình của tác nhân chính. Lập kế hoạch và theo dõi các quy trình phức tạp với write_todos, sắp xếp tác vụ qua các trạng thái đang chờ, đang tiến hành và đã hoàn thành; yêu c
official
deep-agents-orchestration
langchain-ai
KHI SỬ DỤNG subagents, lập kế hoạch tác vụ hoặc phê duyệt của con người trong Deep Agents. Bao gồm SubAgentMiddleware, TodoList để lập kế hoạch và các ngắt HITL.
official