Skip to main content

概述

本指南演示如何使用深度智能体构建数据分析智能体。数据分析任务通常需要规划、代码执行以及处理脚本、报告和图表等产物——这些都是深度智能体旨在处理的能力。 我们将构建的智能体将:
  1. 接受 CSV 文件进行分析
  2. 执行探索性数据分析并生成可视化
  3. 将结果分享到 Slack 频道
Slack 集成是可选的。可以修改智能体以在本地保存产物或通过其他渠道分享结果。

关键概念

本教程涵盖:
  • 用于沙箱化代码执行的后端
  • 用于外部集成的自定义工具

设置

安装

安装核心依赖:
pip

可选依赖

本教程中我们将使用:
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:

设置后端

深度智能体使用后端在沙箱化环境中执行代码。 设置详情请参见可用提供商
Verify the sandbox is ready:

上传示例数据

创建并上传示例销售数据到后端:

实现自定义工具

数据分析任务可能会生成产物,如报告或图表。 下面这个简单的工具使用 backend.download_files 下载它们,然后使用 Slack SDK 上传。 我们也可以让智能体列出相关文件路径而不是上传,这样相关人员可以根据需要单独获取。
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.

运行智能体

让我们实例化一个智能体:
We include: Let’s now invoke our agent.
View the full LangSmith trace for this execution.

结果

智能体成功分析了数据,并将包含可视化的全面报告分享到了 Slack:
Sales analysis results in Slack

Agent-generated analysis report and visualization dashboard delivered to 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.

下一步

现在你已经构建了数据分析智能体,探索以下资源来扩展其能力:
  • 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
  • CLI: Try the Deep Agents CLI 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