Skip to main content

Overview

This guide demonstrates how to build a data analysis agent using a deep agent. Data analysis tasks typically require planning, code execution, and working with artifacts such as scripts, reports, and plots—capabilities that deep agents are designed to handle. The agent we’ll build will:
  1. Accept a CSV file for analysis
  2. Perform exploratory data analysis and generate visualizations
  3. Share results to a Slack channel
The Slack integration is optional. The agent can be modified to save artifacts locally or share results through other channels.

Key concepts

This tutorial covers:
  • Backends for sandboxed code execution
  • Custom tools for external integrations

Setup

Installation

Install the core dependencies:
pip

Optional dependencies

For this tutorial, we’ll use:
pip
These services are optional, though a sandboxed environment is highly recommended for any production use. You can alternatively use the local shell backend (with important security considerations) or download artifacts directly from the backend.

LangSmith

Many of the applications you build with LangChain will contain multiple steps with multiple invocations of LLM calls. As these applications get more complex, it becomes crucial to be able to inspect what exactly is going on inside your chain or agent. The best way to do this is with LangSmith. After you sign up at the link above, make sure to set your environment variables to start logging traces:
Or, set them in Python:

Set up the backend

Deep Agents use backends to execute code in sandboxed environments. The examples below use a LangSmith sandbox. For other providers, see available providers.

Upload sample data

Create and upload sample sales data to the backend:

Implement custom tools

Data analysis tasks might produce artifacts, like reports or plots. The following simple tool downloads them with backend.download_files and then uploads them using the Slack SDK. We could also ask our agent to list the relevant file paths instead of uploading them, so interested parties can obtain them separately as needed.
It is generally good practice to avoid adding credentials and other secrets to the sandbox. Here we manage the Slack token outside the sandbox in a tool.

Run the agent

Let’s instantiate an agent:
We include: Let’s now invoke our agent.
View the full LangSmith trace for this execution.

Results

The agent successfully analyzes the data and shares a comprehensive report with visualizations to Slack:
Sales analysis results in Slack
You can download artifacts directly from the backend without using external tools:
See provider guides for how to clean up the sandbox once finished.

Next steps

Now that you’ve built a data analysis agent, explore these resources to extend its capabilities:
  • Backends: Learn about the Deep Agents backend system
  • Sandboxes: Review backends for sandboxed code execution, including security considerations and advanced configurations
  • Customization: Discover how to customize your agent with different models, tools, prompts, and planning strategies
  • Code: Try Deep Agents Code as a terminal coding agent to assist with data analysis and other agentic tasks locally
  • Skills: Equip your agent with reusable skills for common workflows
  • Human-in-the-loop: Add interactive approval steps for critical operations in your data analysis workflow