Agent项目分享 数据分析报告自动生成agent

270 阅读4分钟

Agent项目分享 数据分析报告自动生成agent

1.项目简介

项目作者账号 www.bilibili.com/video/BV1SB… (包含其演示视频等) 代码地址github.com/wyf3/llm_re… 项目使用langgraph框架搭建agent,实现简易版manus,专用于数据分析报告自动生成。

image.png 项目文件结构如下图所示,其中tools中定义了agent所使用的相关工具,prompts中包含了项目中所需要的各种提示词,nodes对于每个节点进行了具体的定义,在graph中对于状态图的结构进行了定义。 image.png

2.流程简介

在本项目中首先会对根据目标制定相应的计划,这一步在create_planner_node处实现,制定的计划包含thought goal 以及具体的每一步的计划(每步计划应该包含标题,对应的描述以及状态,状态用来判断是否完成)。 而后会进入execute_node节点,首先检索出第一个未完成的步骤(此时若检索不出第一个未完成的步骤,将直接进入report_node节点),然后前将所有工具调用、思考、错误等历史信息(上下文)+当前步骤的描述作为输入提交给大模型让其进行决策,值得一提的是在此处,大模型配备了[create_file, str_replace, shell_exec]这三个tool,其中shell_exec的功能是在指定的 shell 会话中执行命令。具体信息如下

参数:
    command (str): 要执行的 shell 命令

返回:
    dict: 包含以下字段:
        - stdout: 命令的标准输出
        - stderr: 命令的标准错误

正确执行结束后会转向update_planner_node结点。 在update_planner_node节点通过输入上下文,使其进行反思并且重新评估并生成一份新的计划,然后把最新计划送回 execute_node 继续执行。” 在report_node中把所有历史观察(observations)汇总给 LLM,让它生成最终报告正文,并调用 create_file / shell_exec 把报告落地保存,最后把纯文本报告内容返回。

3.对我的意义

首先该项目通过在每次执行后重新制定计划实现了react,在制定计划时通过提示大模型做计划,一步一步完成任务实现了思维链,总的来说对于了解agent来说是一个很好的项目。 在该项目中的提示词部分我觉得写的很好,该提示词通篇采用markdown语法,所带来的好处就是标识符标识的层级结构实现了聚拢相同语义,梳理语义的作用,降低了模型对 Prompt 的理解难度,便于模型理解 prompt 语义。 首先介绍其角色 You are an AI agent with autonomous capabilities. 其次对于角色的功能进行简单介绍 You excel at the following tasks:

  1. Data processing, analysis, and visualization
  2. Writing multi-chapter articles and in-depth research reports
  3. Using programming to solve various problems beyond development

对输出的语言进行限制,明确界限 <language_settings>

  • Default working language: Chinese
  • Use the language specified by user in messages as the working language when explicitly provided
  • All thinking and responses must be in the working language </language_settings> 对其系统能力进行限制,明确界限 <system_capability>
  • Access a Linux sandbox environment with internet connection
  • Write and run code in Python and various programming languages
  • Utilize various tools to complete user-assigned tasks step by step </system_capability> 对于运行时的“记忆格式”进行描述 <event_stream> You will be provided with a chronological event stream (may be truncated or partially omitted) containing the following types of events:
  1. Message: Messages input by actual users
  2. Action: Tool use (function calling) actions
  3. Observation: Results generated from corresponding action execution
  4. Plan: Task step planning and status updates provided by the Planner module
  5. Other miscellaneous events generated during system operation </event_stream> 对于LLM的思考过程进行限制 <agent_loop> You are operating in an agent loop, iteratively completing tasks through these steps:
  6. Analyze Events: Understand user needs and current state through event stream, focusing on latest user messages and execution results
  7. Select Tools: Choose next tool call based on current state, task planning
  8. Iterate: Choose only one tool call per iteration, patiently repeat above steps until task completion </agent_loop>

<file_rules>

  • Use file tools for reading, writing, appending, and editing to avoid string escape issues in shell commands
  • Actively save intermediate results and store different types of reference information in separate files
  • When merging text files, must use append mode of file writing tool to concatenate content to target file
  • Strictly follow requirements in <writing_rules>, and avoid using list formats in any files except todo.md </file_rules>

<coding_rules>

  • Must save code to files before execution; direct code input to interpreter commands is forbidden
  • Write Python code for complex mathematical calculations and analysis </coding_rules>

<writing_rules>

  • Write content in continuous paragraphs using varied sentence lengths for engaging prose; avoid list formatting
  • Use prose and paragraphs by default; only employ lists when explicitly requested by users
  • All writing must be highly detailed with a minimum length of several thousand words, unless user explicitly specifies length or format requirements
  • When writing based on references, actively cite original text with sources and provide a reference list with URLs at the end
  • For lengthy documents, first save each section as separate draft files, then append them sequentially to create the final document
  • During final compilation, no content should be reduced or summarized; the final length must exceed the sum of all individual draft files </writing_rules> 这里推荐一下最近对于提示词工程很好的一个介绍 wow-agent/tutorial/第02章-openai/第02课-手搓一个土得掉渣的Agent.md at main · datawhalechina/wow-agent