在 Deep Agents Code 中,自定义 agent 主要有两种方式:
  • Memory:跨 sessions 持久存在的 AGENTS.md files 和 auto-saved memories。使用 memory 保存通用 coding style、preferences 和已学习的 conventions。
  • Skills:可复用、按需启用的 capabilities,agent 只会在相关时发现并读取。使用 skills 保存 task-specific context,例如 workflows、best practices 和 reference docs。
实践中,skills 和 memory 位于一条连续谱上。关于何时使用它们,请参阅 Skills, memory, and tools 使用 /remember 显式提示 agent 基于当前 conversation 更新其 memory 和 skills。
使用 SDK 构建 custom agent?有关 programmatic memory backends,请参阅 Memory

Memory

Automatic memory

使用 agent 时,它会通过 memory-first protocol 自动将信息作为 markdown files 存储在 ~/.deepagents/<agent_name>/memories/ 中:
  1. Research:开始 tasks 前搜索 memory 中的相关 context
  2. Response:执行期间不确定时检查 memory
  3. Learning:自动保存新信息,供 future sessions 使用
Agent 会按 topic 组织 memories,并使用描述性 filenames:
~/.deepagents/backend-dev/memories/
├── api-conventions.md
├── database-schema.md
└── deployment-process.md
当你教 agent conventions 时:
dcode --agent backend-dev
> Our API uses snake_case and includes created_at/updated_at timestamps
它会记住这些内容,供 future sessions 使用:
> Create a /users endpoint
# Applies conventions without prompting

AGENTS.md files

AGENTS.md files 提供持久 context,并始终在 session start 时加载:
  • Global~/.deepagents/<agent_name>/AGENTS.md,每个 session 都会加载。
  • Project:任意 git project root 中的 .deepagents/AGENTS.md,当 Deep Agents Code 从该 project 内运行时加载。
两个 files 都会在 startup 时追加到 system prompt 中。

Memory 工作方式

当回答 project-specific questions,或你引用过去的 work 或 patterns 时,agent 也可能读取其 memory files。 当你提供有关 agent 应如何行为的信息、对其工作的反馈,或要求它记住某些内容时,agent 会更新 AGENTS.md。 如果 agent 从你的 interactions 中识别出 patterns 或 preferences,也会更新其 memory。 若要在 additional memory files 中添加更结构化的 project knowledge,请将它们添加到 .deepagents/,并在 AGENTS.md file 中引用它们。 你必须在 AGENTS.md file 中引用 additional files,agent 才会知道它们。 这些 additional files 不会在 startup 时读取,但 agent 可在需要时引用和更新它们。

何时使用 global 或 project AGENTS.md

将 global AGENTS.md~/.deepagents/agent/AGENTS.md)用于:
  • 你的 personality、style 和 universal coding preferences
  • 通用 tone 和 communication style
  • Universal coding preferences(formatting、type hints 等)
  • 适用于各处的 tool usage patterns
  • 不随 project 改变的 workflows 和 methodologies
将 project AGENTS.md(project root 中的 .deepagents/AGENTS.md)用于:
  • Project-specific context 和 conventions
  • Project architecture 和 design patterns
  • 此 codebase 专用 coding conventions
  • Testing strategies 和 deployment processes
  • Team guidelines 和 project structure

Skills

Skills 会将 domain expertise(例如 workflows、best practices、scripts 和 reference docs)打包进可复用 directories,agent 只会在相关时发现并读取。 Deep agent skills 遵循 Agent Skills specification。关于 skills 如何工作以及如何编写有效 skills,请参阅 Skills 启动时,Deep Agents Code 会从每个 SKILL.md file 的 frontmatter 读取 name 和 description。当 task 匹配 skill description 时,agent 会读取 skill file 并遵循其中 instructions。Discovery 会在 /reload 时再次运行。

添加 skill

1

创建 skill

# User skill (stored in ~/.deepagents/<agent_name>/skills/)
dcode skills create test-skill

# Project skill (stored in .deepagents/skills/)
dcode skills create test-skill --project
这会生成:
skills/
└── test-skill
    └── SKILL.md
2

编辑 SKILL.md

打开生成的 SKILL.md,编辑该 file 以包含你的 instructions。
3

添加可选 resources

可以选择向 test-skill folder 添加 additional scripts 或其他 resources。更多信息请参阅 What are skills
你也可以将 existing skills 直接复制到 agent folder:
mkdir -p ~/.deepagents/<agent_name>/skills
cp -r examples/skills/web-research ~/.deepagents/<agent_name>/skills/

安装 community skills

你可以使用 Vercel 的 Skills CLI 等 tools,在你的 environment 中安装 community Agent Skills,并让 deep agents 可以使用它们:
# Install a skill globally
npx skills add vercel-labs/agent-skills --skill web-design-guidelines -a deepagents -g -y

# List installed skills
npx skills ls -a deepagents -g
Global installs(-g)会将 skills symlink 到 ~/.deepagents/agent/skills/,即 default agent 的 user-level skills directory。Project-level installs(省略 -g)会将 skills 放入相对于当前 directory 的 .deepagents/skills/,让在该 project 中运行的任何 agent 都能使用,无论 agent name 是什么。
Global installs 仅面向 default agent directory。如果你使用 custom-named agent,请使用 project-level installs,或手动将 skill symlink 到 ~/.deepagents/{your-agent}/skills/

Skill discovery

启动时会从以下 directories 加载 skills:
~/.deepagents/<agent_name>/skills/
~/.agents/skills/
.deepagents/skills/
.agents/skills/
~/.claude/skills/          (experimental)
.claude/skills/            (experimental)
当存在重复 skill names 时,后续更高优先级 directories 会覆盖更早的 directories(请参阅 App data)。 对于 project-specific skills(位于 .deepagents/skills/.agents/skills/ 下),project root 通过包含 .git folder 来识别。

在 session 中调用 skill

在 interactive session 中,使用 /skill:<name> slash command 直接运行 skill:
/skill:code-review
/skill:code-review review the auth module
Skill 的 SKILL.md instructions 会与传入的任何 arguments 一起注入 prompt。

使用 skill 启动

--skill flag 会在启动时立即调用 skill,适用于 interactive(TUI)或 non-interactive(headless)mode:
# Open the TUI and immediately run a skill
dcode --skill code-review

# Pass a request to the skill with -m
dcode --skill code-review -m 'review the auth module'

# Pipe content into a skill
cat diff.txt | dcode --skill code-review

# Pipe content and add a request
cat diff.txt | dcode --skill code-review -m 'focus on security'

# Run a skill headlessly
dcode --skill code-review -n 'review this patch'

# Quiet mode (only agent output on stdout)
dcode --skill code-review -n 'review this patch' -q
--skill--quiet--no-stream 一起使用时,需要 -n(non-interactive mode)。

列出 skills

# List all user skills
dcode skills list

# List project skills
dcode skills list --project

# Get detailed info about a specific skill
dcode skills info test-skill
dcode skills info test-skill --project