Deep Agents Code(dcode)是基于 Deep Agents SDK 构建的 open source coding agent。 它可与任何 large language model 配合使用,并支持在 session 中途切换 providers 或 models。 Persistent memory 会在 conversations 之间保留 context,customizable skills 会塑造其行为,approval controls 会管控 code execution。

快速开始

安装并启动

curl -LsSf https://langch.in/dcode | bash

添加 provider credentials

Deep Agents Code 可与任何 tool-calling LLM 配合使用。Models 通过 providers 访问:OpenAI、Anthropic 和 Google 默认随包提供,其他 providers(Ollama、Groq、xAI 等)按需安装。使用 /auth command 设置 API keys。完整列表和 credential details 请参阅 Providers
Web search 使用 Tavily,并需要 TAVILY_API_KEY。请参阅 Enable web search

给 agent 一个 task

Create a Python script that prints "Hello, World!"
Agent 会解释 query,并在修改 files 前用 diffs 提出 changes 供你 approval。如有需要,它可以运行 shell commands 测试 code、检查 documentation,或搜索 web 获取 up-to-date information。

启用 tracing(可选)

若要在 LangSmith 中记录 agent operations、tool calls 和 decisions,请将以下内容添加到 ~/.deepagents/.env,或在 shell 中 export variables:
~/.deepagents/.env
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=lsv2_...
LANGSMITH_PROJECT=optional-project-name  # Specify a project name or default to "deepagents-code"
更多 details 和 usage 请参阅 Trace with LangSmith
Deep Agents Code 尚不正式支持 Windows。Windows users 可以尝试在 Windows Subsystem for Linux (WSL) 下运行。

Capabilities

Deep Agents Code 具有以下 built-in capabilities:
  • File operations:读取、写入和编辑 disk 上的 files。
  • Shell execution:执行 commands 以运行 tests、build projects、管理 dependencies,并与 version control 交互。
  • Remote sandboxes:远程运行 agent tools,而不是在 local machine 上运行。
  • Web search:搜索 web 以获取 up-to-date information 和 documentation。需要 Tavily API key
  • Task planning and tracking:将 complex tasks 拆分为离散 steps 并跟踪 progress。
  • Subagents:将 work 委派给 task-specific subagents。
  • Memory storage and retrieval:跨 sessions 存储和检索 information,使 agents 能记住 project conventions 和 learned patterns。
  • Context compaction & offloading:summarize 较早的 conversation messages,并将 originals offload 到 storage。
  • Human-in-the-loop:对 sensitive tool operations 要求 human approval。
  • Skills:用 custom expertise 和 instructions 扩展 agent capabilities。
  • MCP tools:从 Model Context Protocol servers 加载 external tools。
  • Tracing:在 LangSmith 中 trace agent operations,用于 observability 和 debugging。

Built-in tools

Agent 附带以下无需配置即可使用的 built-in tools:
ToolDescriptionHuman-in-the-Loop
ls列出 files 和 directories-
read_file读取 file 内容;为 images、audio、video 和 PDFs 返回 multimodal blocks-
write_file创建或覆盖 fileRequired1
edit_file对现有 files 进行 targeted editsRequired1
glob查找匹配 pattern 的 files-
grep跨 files 搜索 text patterns-
execute在本地或 remote sandbox 中执行 shell commandsRequired1
web_search使用 Tavily 搜索 web(请参阅 Enable web searchRequired1
fetch_urlFetch web pages 并转换为 markdownRequired1
task将 work 委派给 subagents 并行执行3Required1
ask_user向 user 提出 free-form 或 multiple-choice questions-
compact_conversationSummarize 较早 messages、将 originals offload 到 backend storage,并在 context 中用 summary 替换它们Mixed2
write_todos为 complex work 创建并管理 task lists-
1:Potentially destructive operations 在执行前需要 user approval。若要绕过 human approval,可切换 auto-approve(shift+tab)或用以下 option 启动:
dcode --auto-approve
# shorter alias:
dcode -y
Non-interactive mode 默认禁用 shell。用 -S/--shell-allow-list(或 DEEPAGENTS_CODE_SHELL_ALLOW_LIST)allowlist commands。使用 recommended 可启用 read-only safe defaults,或使用 all 允许任何 command。请参阅 Non-interactive mode and piping
2:当 token usage 超过 model-aware threshold 时,Deep Agents Code 会在后台自动 offload conversation。Offloading 会通过 LLM summarize 较早 messages,并将 originals eject 到 storage(/conversation_history/{thread_id}.md),在 context 中用 summary 替换它们。如有需要,agent 仍可从 offloaded file 检索完整 history。compact_conversation tool 允许 agent(或你)按需触发 offloading。当它作为 tool 调用时,默认需要 user approval。3:当通过 config.toml 中的 [async_subagents] section 配置 async subagents(请参阅 Async subagents)时,会提供 additional tools:start_async_taskupdate_async_taskcancel_async_task(都受 approval gate 控制),以及 check_async_tasklist_async_tasks

Command reference

# Use a specific agent configuration
dcode --agent mybot

# Use a specific model (provider:model format or auto-detect)
dcode --model anthropic:claude-opus-4-7
dcode --model gpt-5.5

# Auto-approve tool usage (skip human-in-the-loop prompts)
dcode -y

# list directory contents, then summarize directory as first prompt—the command runs first, then the prompt is submitted
# the prompt does NOT have access to the command output
dcode --startup-cmd "ls -la" -m "Summarize what's in this directory"

# Non-interactive with startup command: show git status before the task runs
# the task does NOT have access to the command output
dcode --startup-cmd "git diff --stat" -n "Review these changes"
OptionDescription
-a, --agent NAME使用带独立 memory 的 named agent。覆盖 config.toml 中的 [agents].recent。Default:agent(如果设置了 [agents].recent,则使用最近使用过的 agent)
-M, --model MODEL使用特定 model(provider:model
--model-params JSON作为 JSON string 传给 model 的 extra kwargs(例如 '{"temperature": 0.7}'
--default-model [MODEL]设置 default model
--clear-default-model清除 default model
-r, --resume [ID]Resume session:-r 表示最近 session,-r <ID> 表示特定 thread
-m, --message TEXTSession 启动时自动提交的 initial prompt(interactive mode)
--skill NAME启动时调用 skill
--startup-cmd CMD启动时、first prompt 前运行的 shell command。Output 会在 transcript 中渲染供你参考,但不会添加到 agent message history。若要将 command output 交给 agent,请改为通过 stdin pipe 传入(例如 git diff | dcode -n "Review these changes")。Non-zero exits 和 timeouts 会 warning 但不会 abort;non-interactive mode 应用 60s timeout。
-n, --non-interactive TEXTNon-interactively 运行单个 task 并退出。除非设置 --shell-allow-list,否则 shell 被禁用
--max-turns N在 non-interactive mode 中限制 agentic turns。超过时以 code 124 退出。需要 -n 或 piped stdin。请参阅 Cap turn count with --max-turns
--timeout SECONDSNon-interactive mode 的 hard wall-clock timeout。超过时以 code 124 退出。需要 -n 或 piped stdin。请参阅 Cap wall-clock time with --timeout
-q, --quiet适合 piping 的 clean output,只有 agent response 会进入 stdout。需要 -n 或 piped stdin
--no-streamBuffer full response,并一次性写入 stdout,而不是 streaming。需要 -n 或 piped stdin
--stdin显式从 stdin 读取 input,而不是 auto-detection。当 stdin 不可用或为 TTY 时清晰报错
-y, --auto-approve无提示 auto-approve 所有 tool calls(禁用 human-in-the-loop)。Interactive session 中可用 Shift+Tab 切换
-S, --shell-allow-list LISTComma-separated shell commands,用于 auto-approve;'recommended' 表示 safe defaults,'all' 表示允许任何 command。适用于 -n 和 interactive modes
--json从 management subcommands(agentsthreadsskillsupdate)发出 machine-readable JSON。Output envelope:{"schema_version": 1, "command": "...", "data": ...}
--sandbox TYPE用于 code execution 的 remote sandbox:none(default)、langsmithagentcoremodaldaytonarunloop。LangSmith 已包含;AgentCore/Modal/Daytona/Runloop 需要 extras
--sandbox-id ID复用现有 sandbox(跳过 creation 和 cleanup)
--sandbox-snapshot-name NAME要使用或创建的 sandbox snapshot name(仅 LangSmith)
--sandbox-setup PATHSandbox 创建后要在其中运行的 setup script path
--mcp-config PATH添加 explicit MCP config 作为 highest-precedence source(与 auto-discovered configs merge)
--no-mcp禁用所有 MCP tool loading
--trust-project-mcpTrust 带 stdio servers 的 project-level MCP configs(跳过 approval prompt)
--interpreter在 main agent 上启用 JS interpreter(js_eval)middleware。仅 local mode;需要 quickjs optional extra
--interpreter-tools VALUEjs_eval 的 PTC allowlist:safeall 或 comma-separated tool names。Default:无 PTC(pure REPL)
--profile-override JSON将 model profile fields 作为 JSON string 覆盖(例如 '{"max_input_tokens": 4096}')。Merge 到 config file profile overrides 之上
--acp作为 ACP server 通过 stdio 运行,而不是启动 interactive UI
--update检查并安装 updates,然后退出
--auto-updateToggle automatic updates on or off,然后退出
-v, --version显示 version
-h, --help显示 help
CommandDescription
dcode helpShow help
dcode agents listList all agents (alias: ls)
dcode agents reset --agent NAMEClear agent memory and reset to default. Supports --dry-run
dcode agents reset --agent NAME --target SOURCECopy memory from another agent
dcode updateCheck for and install Deep Agents Code updates
dcode skills list [--project]List all skills (alias: ls)
dcode skills create NAME [--project]Create a new skill with template SKILL.md. Idempotent—re-creating an existing skill prints an informational message instead of an error
dcode skills info NAME [--project]Show detailed information about a skill
dcode skills delete NAME [--project] [-f]Delete a skill and its contents. Supports --dry-run
dcode threads list [--agent NAME] [--limit N]List sessions (alias: ls). Default limit: 20. -n is a short flag for --limit. Additional flags: --sort {created,updated}, --branch TEXT (filter by git branch), --cwd [PATH] (filter by working directory; bare flag uses current directory), -v/--verbose (show all columns including branch, created time, and initial prompt), -r/--relative (relative timestamps)
dcode threads delete IDDelete a session. Supports --dry-run
dcode mcp login NAME [--mcp-config PATH]Run the OAuth login flow for an MCP server marked auth: "oauth". See MCP tools
dcode mcp configShow MCP config discovery paths
所有 management subcommands 都支持 --json 以输出 machine-readable output。详情请参阅 command-line optionsDestructive commands(agents resetskills deletethreads delete)支持 --dry-run,可在不做更改的情况下 preview 将发生什么。在 JSON mode 中,--dry-run 会返回相同 envelope,并带有 dry_run: true field。

Configuration

完整 reference,包括 config.toml schema、provider parameters、profile overrides 和 hook configuration,请参阅 Configuration Deep Agents Code 将所有 configuration 存储在 ~/.deepagents/ 下。在该 directory 中,每个 agent 都有自己的 subdirectory(default:agent):
PathPurpose
~/.deepagents/config.tomlModel 和 agent defaults、provider settings、constructor params、profile overrides、themes、update settings
~/.deepagents/.envGlobal API keys 和 secrets。请参阅 configuration
~/.deepagents/hooks.jsonLifecycle event hooks(session start/end、task complete 等)
~/.deepagents/<agent_name>/Per-agent memory、skills 和 conversation threads
.deepagents/(project root)Project-specific memory 和 skills,在 git repo 内运行时加载

Interactive mode

像在 chat interface 中一样自然输入。 Agent 会使用其 built-in tools、skills 和 memory 来帮助你完成 tasks。
在 Deep Agents Code session 中使用这些 commands:
  • /model:切换 models 或打开 interactive model selector。
  • /agents:在不重新启动的情况下 hot-swap pre-configured agents。详情请参阅 Command reference
  • /auth:管理 model providers 已存储的 API keys。详情请参阅 Provider credentials
  • /remember [context]:Review conversation 并更新 memory 和 skills。可选传入 additional context
  • /skill:<name> [args]:按 name 直接调用 skill。Skill 的 SKILL.md instructions 会与提供的 arguments 一起注入 prompt
  • /skill-creator [task]:用于创建有效 agent skills 的 guide
  • /offload(alias /compact):通过将 messages offload 到 storage,并用 summary placeholder 替代,释放 context window space。如有需要,agent 可从 offloaded file 检索完整 history
  • /tokens:显示当前 context window token usage breakdown
  • /clear:清除 conversation history 并开始新 thread
  • /copy:将最新 assistant message 复制到 clipboard
  • /threads:浏览并 resume 之前的 conversation threads
  • /mcp [login <server> | reconnect]:显示 active MCP servers 和 tools。login <server> 会为 server 运行 OAuth flow;reconnect 加载 deferred logins
  • /notifications:配置 startup warning preferences
  • /reload:重新读取 .env files、刷新 configuration,并在不重启的情况下重新发现 skills。Conversation state 会保留。Override behavior 请参阅 DEEPAGENTS_CODE_ prefix
  • /theme:打开 interactive theme selector 以切换 color themes。可使用 built-in themes,以及任何 user-defined themes
  • /update:Inline 检查并安装 Deep Agents Code updates。检测 install method(uv、Homebrew、pip),并运行相应 upgrade command
  • /auto-update:Toggle automatic updates on or off
  • /trace:在 LangSmith 中打开当前 thread(需要 LANGSMITH_API_KEY
  • /editor:在 external editor($VISUAL / $EDITOR)中打开当前 prompt。请参阅 External editor
  • /changelog:在 browser 中打开 Deep Agents Code changelog
  • /docs:在 browser 中打开 documentation
  • /feedback:打开 GitHub issues page 以提交 bug report 或 feature request
  • /version:显示已安装的 deepagents-code 和 SDK versions
  • /help:显示 help 和 available commands
  • /quit:退出 application
输入 ! 进入 shell mode,然后输入 command。
git status
npm test
ls -la
General
ShortcutAction
EnterSubmit prompt
Shift+Enter, Ctrl+J, Alt+Enter, or Ctrl+EnterInsert newline
@filenameAuto-complete files and inject content
Shift+Tab or Ctrl+TToggle auto-approve
Ctrl+XOpen prompt in external editor
Ctrl+NReview pending notifications
Ctrl+OExpand/collapse the most recent tool output
EscapeInterrupt current operation
Ctrl+CInterrupt or quit
Ctrl+DExit
Prompt 中的 text editingChat input 使用标准 readline-style bindings:
ShortcutAction
Ctrl+A or HomeMove cursor to start of line
Ctrl+E or EndMove cursor to end of line
Ctrl+UDelete from cursor to start of line
Ctrl+KDelete from cursor to end of line
Ctrl+W or Ctrl+BackspaceDelete word to the left
Ctrl+Left / Ctrl+RightMove cursor one word left/right
macOS Cmd+Left / Cmd+Right / Cmd+DeleteTerminal emulators 会在 Cmd-modified keys 到达运行中的 application 之前拦截它们,因此 Deep Agents Code 永远不会直接收到这些按键。相反,terminal 会将它们转换为上面的 readline shortcuts。
  • Ghostty: 开箱可用。Cmd+LeftCmd+RightCmd+Delete 默认会转换为 Ctrl+ACtrl+ECtrl+U
  • iTerm2: 默认未绑定。请在 Settings → Profiles → Keys → Key Mappings 下将以下内容添加为 Send Text with vim special chars
    • Cmd+Left\x01 (Ctrl+A)
    • Cmd+Right\x05 (Ctrl+E)
    • Cmd+Delete\x15 (Ctrl+U)
  • Terminal.app: 没有用于此 remap 的 native UI。请直接使用基于 Ctrl 的 shortcuts。
Word-wise motion(Option+Left / Option+Right)以相同方式处理:terminals 发送 Esc+b / Esc+f,Deep Agents Code 将其解释为 word-left/right。

Non-interactive mode 和 piping

使用 -n 可在不启动 interactive UI 的情况下运行单个 task:
dcode -n "Write a Python script that prints hello world"
每个 non-interactive run 都会启动 fresh thread,conversation history 不会在 invocations 之间延续。File-based state(memory、skills、configuration)会持久保留。 你也可以通过 stdin pipe input。Pipe input 时,Deep Agents Code 会自动以 non-interactively 方式运行:
echo "Explain this code" | dcode
cat error.log | dcode -n "What's causing this error?"
git diff | dcode -n "Review these changes"
git diff | dcode --skill code-review -n 'summarize changes'
当 piped input 与 -n-m 组合使用时,piped content 会先出现,然后才是你传给 flag 的 text。
最大 piped input size 为 10 MiB。
Non-interactive mode 默认禁用 shell execution。使用 -S/--shell-allow-list 启用特定 commands(例如 -S "pytest,git,make"),使用 recommended 启用 safe defaults,或使用 all 允许任何 command。
CI/CD pipelines 中 long-running 或 misbehaving agents 可能无限 loop。--max-turns N 让 operators 无需接触 SDK internals 即可设置 hard upper bound:
dcode -n "fix the failing tests" --max-turns 10
N 必须是 positive integer,并会覆盖用于限制 runaway loops 的 internal safety default。超过 budget 时以 code 124(与 GNU timeout 匹配)退出,因此 CI 可以区分 budget hit 和 generic failure。需要 -n 或 piped stdin;否则以 code 2 退出。若要使用 time-based limit 替代(或补充)turn-count limit,请参阅 Cap wall-clock time with --timeout
--timeout SECONDS 会对 non-interactive run 强制执行 hard wall-clock limit。它用 time-based budget 补充 --max-turns(turn count),先命中的 limit 会 cancel agent。
# Fail fast in CI if the task takes more than 2 minutes
dcode -n "run the test suite and summarise failures" --timeout 120

# Combine with --max-turns—whichever limit is hit first stops the agent
dcode -n "refactor auth module" --timeout 300 --max-turns 20
到期时 agent 会被 cancel,process 以 code 124 退出,与 --max-turns 使用相同 code,因此 CI 可以统一处理两种 budget hits。需要 -n 或 piped stdin;否则以 code 2 退出。
使用 -q 获得适合 pipe 到其他 commands 的 clean output,使用 --no-stream 在写入 stdout 前 buffer full response(而不是 streaming):
dcode -n "Generate a .gitignore for Python" -q > .gitignore
dcode -n "List dependencies" -q --no-stream | sort
在 non-interactive mode 中,agent 会被指示做出合理假设并自主推进,而不是提出 clarifying questions。它还会优先使用 non-interactive command variants(例如 npm init -yapt-get install -y)。
# Allow specific commands (validated against the list)
dcode -n "Run the tests and fix failures" -S "pytest,git,make"

# Use the curated safe-command list
dcode -n "Build the project" -S recommended

# Allow any shell command
dcode -n "Fix the build" -S all
谨慎使用。-S all(或 --shell-allow-list all)允许 agent 在没有 human confirmation 的情况下执行任意 shell commands。

使用 LangSmith trace

启用 LangSmith tracing,即可在 LangSmith project 中查看 agent operations、tool calls 和 decisions。 将 tracing keys 添加到 ~/.deepagents/.env,即可在每个 session 中启用 tracing,而无需 per-shell exports:
~/.deepagents/.env
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=lsv2_...
LANGSMITH_PROJECT=optional-project-name  # Specify a project name or default to "deepagents-code"
若要为特定 project 覆盖,请将相同 keys 添加到 project directory 中的 .env。完整 loading order 请参阅 environment variables 如果你愿意,也可以将这些设置为 shell environment variables。Shell exports 始终优先于 .env values,因此这是 temporary overrides 或 testing 的好选择:
export LANGSMITH_TRACING=false
当从 LangChain application 以编程方式调用 Deep Agents Code(例如作为 non-interactive mode 中的 subprocess)时,你的 app 和 Deep Agents Code 都会生成 LangSmith traces。默认情况下,这些 traces 都会进入同一个 project。若要将 Deep Agents Code traces 发送到 dedicated project,请设置 DEEPAGENTS_CODE_LANGSMITH_PROJECT
~/.deepagents/.env
DEEPAGENTS_CODE_LANGSMITH_PROJECT=my-deep-agent-execution
然后为 parent application traces 配置 LANGSMITH_PROJECT
~/.deepagents/.env
LANGSMITH_PROJECT=my-app-traces
这会保持 app-level observability 清爽,同时仍然在独立 project 中捕获 agent internal execution。你也可以使用 DEEPAGENTS_CODE_ prefix 将 LangSmith credentials 的作用域限定到 Deep Agents Code(例如 DEEPAGENTS_CODE_LANGSMITH_API_KEY)。
配置后,Deep Agents Code 会显示带 LangSmith project link 的 status line。在支持的 terminals 中,点击 link 可直接打开。你也可以使用 /trace 打印 URL 并在 browser 中打开。
 LangSmith tracing: 'my-project'
建议你同时设置 LangSmith Engine,它会监控 traces、检测 issues,并提出 fixes。