Skip to main content
This guide builds a data analysis agent from first principles using create_agent and deepagents middleware. Rather than starting with create_deep_agent, we assemble the harness one piece at a time: so you can see exactly what each component adds and swap in only what your use case needs. The agent we’ll build:
  1. Accepts a CSV file for analysis
  2. Writes and executes Python code in an isolated sandbox
  3. Delegates visualization work to a specialized subagent
  4. Loads data analysis patterns from a skills file

Setup

Enable LangSmith tracing to inspect every step:

Step 1: The minimal agent

A model, a loop. Nothing else yet.
This runs, but the agent has no filesystem and no way to execute code. The next steps add those.

Step 2: Add a sandbox backend

LangSmithSandbox gives the agent an isolated environment with a filesystem and an execute tool for running shell commands. The agent can install packages, write scripts, and run them: without touching the host.
FilesystemMiddleware adds read_file, write_file, edit_file, glob, and grep. Because LangSmithSandbox implements the sandbox protocol, it also adds execute: the agent can now run shell commands. Upload a CSV and invoke:

Step 3: Add context management

For longer analysis sessions the context window fills. SummarizationMiddleware compresses history automatically so the agent keeps working without hitting token limits.

Step 4: Add skills

Skills give the agent on-demand domain knowledge via progressive disclosure: loaded only when the current task calls for it. Create a skill file in your skills directory:

Step 5: Add a visualization subagent

Some tasks benefit from isolation. A visualization subagent runs in its own context window, keeping chart generation separate from the main analysis: and enabling parallel execution.
The main agent handles analysis and planning; it delegates chart generation to the visualizer subagent via the task tool.

What you built

This is the same foundation as create_deep_agent: assembled manually so you control exactly what’s included. The possibilities don’t end here: see Prebuilt middleware for the full list of composable capabilities, and the create_agent reference for all configuration options. For a pre-assembled version, see create_deep_agent and Customize Deep Agents. For the full data analysis example using create_deep_agent, see Data analysis.