create_deep_agent 是 middleware graph builder,不是单一巨大 Agent 类
create_deep_agent 接收 model/tools/system_prompt/middleware/subagents/skills/memory/permissions/backend/interrupt_on/checkpointer/store/cache 等依赖,最后调用 LangChain create_agent 并设置 recursion_limit、metadata 和 agent name。
DeepAgents 把 Agent 看成一张可配置的 LangGraph:模型、文件工具、子 Agent、压缩、记忆和审批都作为中间件节点组合。
自研可借鉴“装配器 + 可插拔 middleware”模式,把功能切片而非把所有逻辑揉成 turn 函数。
268 def create_deep_agent( # noqa: C901, PLR0912, PLR0915 # Complex graph assembly logic with many conditional branches
269 model: str | BaseChatModel | None = None,
270 tools: Sequence[BaseTool | Callable | dict[str, Any]] | None = None,
271 *,
272 system_prompt: str | SystemMessage | None = None,
273 middleware: Sequence[AgentMiddleware[StateT_co, ContextT]] = (),
274 subagents: Sequence[SubAgent | CompiledSubAgent | AsyncSubAgent] | None = None,
275 skills: list[str] | None = None,
276 memory: list[str] | None = None,
277 permissions: list[FilesystemPermission] | None = None,
278 backend: BackendProtocol | None = None,
279 interrupt_on: dict[str, bool | InterruptOnConfig] | None = None,
280 response_format: ResponseFormat[ResponseT] | type[ResponseT] | dict[str, Any] | None = None,
281 state_schema: type[DeepAgentState] | None = None,
282 context_schema: type[ContextT] | None = None,
283 checkpointer: Checkpointer | None = None,
284 store: BaseStore | None = None,
285 debug: bool = False,
286 name: str | None = None,
287 cache: BaseCache | None = None,
288 ) -> CompiledStateGraph[AgentState[ResponseT], ContextT, InputAgentState, OutputAgentState[ResponseT]]: # ty: ignore[invalid-type-arguments] # ty can't verify generic TypedDicts satisfy StateLike bound
289 r"""Create a deep agent.
290
291 By default, this agent has access to the following tools:
292
293 - `ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`: file operations
294 - `execute`: run shell commands
295 - `task`: call subagents
296
297 The `execute` tool allows running shell commands if the backend implements
298 [`SandboxBackendProtocol`][deepagents.backends.protocol.SandboxBackendProtocol].
299 For non-sandbox backends, the `execute` tool will return an error message.
300
查看全部 3 处证据
-
契约
libs/deepagents/deepagents/graph.py:268–300create_deep_agent 参数和内置工具。 -
实现
libs/deepagents/deepagents/graph.py:816–877main middleware stack 组装。 -
实现
libs/deepagents/deepagents/graph.py:922–944create_agent、recursion_limit 和 LangSmith metadata。