Skip to main content

Overview

This guide demonstrates how to build a content writing agent from scratch using Deep Agents. The agent you build will:
  1. Load voice and workflow rules from AGENTS.md and skill folders
  2. Delegate web research to a specialized subagent with web_search
  3. Draft blog or social content following the loaded skill
  4. Generate cover or social images with Gemini and save files under the project directory
The code in this tutorial wires in image generation tools and a filesystem backend so the agent can read and write posts, research notes, and images under the project directory. For the full runnable project, see the content-builder-agent example.

Key concepts

This tutorial covers:

Prerequisites

API keys:
  • Anthropic (Claude) or other provider API key
  • Google (Gemini) for image generation with gemini-2.5-flash-image
  • Tavily for web search (free tier)
  • LangSmith for tracing (optional)
Python 3.11 or later.

Setup

1

Create project directory

2

Install dependencies

Pin deepagents to a supported range in your own project (for example >=0.3.5,<0.4.0) to match the upstream example.
3

Set API keys

Add configuration files

The example keeps behavior in three kinds of files: memory, skills, and subagent definitions.
1

Add AGENTS.md

Create AGENTS.md in the project root. When you later create the agent and specify this file as part of the memory parameter, it gets loaded this into the system prompt so brand voice and research expectations apply to every run.
To make this agent comply with your own tone, pillars, and formatting rules, update the text in AGENTS.md.
2

Add subagents.yaml

Create a file called subagents.yaml. Then add the following txt which describes a researcher subagent with a Tavily-backed web_search tool, a Haiku model id, and instructions to save findings to paths you specify when delegating from the main agent:
The file gets passed as an argument later when creating the deep agent.
3

Add skills

Create a skills/ directory. Each skill is a folder containing a SKILL.md file with YAML frontmatter (name, description) and instructions for the skill.Create skills/blog-post/SKILL.md and copy the following text into it which contains information on crating long-form posts, optimizing content for SEO, and generating cover images.
Next, create skills/social-media/SKILL.md and copy the following text into it which contains information on drafting social media posts and generating accompanying imagery:
They instruct the agent to call the researcher subagent first, write markdown under blogs/, linkedin/, or tweets/, and call generate_cover or generate_social_image for images.When you later create the agent and specify the skills folder(s), then the frontmatter of the SKILLS.md files from those skill folders get loaded this into the system prompt so the agent can use the skill when a task task matches a skill description.

Build the script

Create content_writer.py in the project root. The following sections belong in one file, in order.
1

Add tools

The researcher subagent uses Tavily search. Blog and social workflows use Gemini image generation. When creating the agent later, the load_subagents function reads subagents.yaml and resolves tool names to these decorated functions.
2

Create the agent

When creating the deep agent with create_deep_agent, pass memory paths, the skills directory, image tools, subagents from YAML, and a FilesystemBackend rooted at the example directory so paths like ./AGENTS.md and ./skills/ resolve correctly.
3

Add an entry point

Invoke the agent with a user message to verify the agent is working:

Run the agent

The filesystem backend can read, write, and delete files under root_dir. Run only in a dedicated directory and review generated content before publishing.
From the project directory you can invoke the agent without passing an argument or by passing the prompt as an argument:
With LANGSMITH_API_KEY set, you can inspect runs in LangSmith.

Output

On success, generated artifacts are written under a system temporary directory (on macOS and Linux, typically under /tmp/), not next to your project files.
Paths follow the skill instructions in SKILL.md.

Full code

Browse the complete content-builder-agent example on GitHub, including the Rich-based streaming UI.

Next steps

  • Edit AGENTS.md to change brand voice and research requirements
  • Add skills under skills/<name>/SKILL.md for new content types
  • Add subagents in subagents.yaml and register tools in load_subagents
  • Read Subagents, Skills, and Customization for deeper configuration