Hands-On Guide to LangChain and DeepAgents
This JavaScript/Node.js tutorial uses LangChain 1.6, LangGraph 1.7, and DeepAgents 1.16 to build agents from createAgent and Middleware through state management, tool-call context, retries, permissions, observability, virtual file systems, and sub-agents. Examples also cover Middleware testing, concurrent state updates, structured-output validation, framework selection, and code organization for operational systems. The guide notes that its examples use [email protected], @langchain/[email protected], and [email protected], and recommends checking updated API types after upgrades because the frameworks are evolving.
The tutorial provides a practical architecture for moving beyond simple tool-calling demonstrations toward agent systems with clear state, permissions, observability, testing, and recovery boundaries.
基于 LangChain 1.6、LangGraph 1.7 与 DeepAgents 1.16 的 JavaScript / Node.js 实战
写在前面:为什么“会写 Agent”和“能交付 Agent”是两回事
如果用一个聊天模型加几个工具,做一个“查天气”“查时间”的 Demo,很多框架都能在十几行代码里完成。
但复杂 Agent 很快就会遇到另一组问题:
- 模型该在什么时候停下来?
- 工具调用失败以后,要不要重试?
- 多轮工具调用产生的消息怎样正确拼回上下文?
- 对话太长、工具返回内容太大,上下文窗口装不下怎么办?
- 任务需要先规划,再分步骤执行,执行状态放在哪里?
- 哪些文件可以读、哪些文件只能写、哪些操作必须拒绝?
- 主 Agent 如何把独立任务交给子 Agent,并避免污染主上下文?
- 线上如何观测模型调用次数、工具耗时、失败原因和中断恢复?
这些问题如果全部从零实现,会消耗大量时间在状态管理、循环路由、持久化、上下文压缩和权限边界上。