如何使用 Dify 搭建属于你的投资分析 Agent 助手

现在,Dify 在应用编排中新增了 Agent Assistant 模式(智能助手),可以基于不同的 LLMs 作为基础的自然语言理解和推理模型(目前 Dify 已支持市面上所有流行的 LLMs ),并提供一系列工具让 LLM 根据需要来调用,解决多步骤的复杂问题场景,帮助开发者构建更具想象力的 GPTs 和 Agent Assistants(智能助手)。

这里我将一步一步地带领你用 Dify 最新的 Agent 能力来搭建一个美股投资分析的 AI 小助手。里面会回答你的一系列问题:

  • Dify 怎么用?

  • 如何编写好用的提示词?

  • 怎么在 Dify 上发布应用,并整合到自己的工作流中?

这个智能助手可以借助 Yahoo 财经的三个工具 — News、Analytics 和 Ticker 来生成一份任一上市公司的投资分析报告。

先给我们的 AI Agent 来一个才艺展示。

先告诉 Agent 你对哪家上市公司感兴趣,随后它就可以帮你搜集和整理任何美股上市公司的财务状况、行业地位和最新消息,几秒钟内就能构建一个 Markdown 格式的投资报告。而且这还没完,这个 Agent 不会生成完报告之后就消失,你随时可以和他继续聊任何你想了解的领域。

这个 Agent 有什么用?什么地方能用到它?

Agent Assistant 是一种泛用的 AI 工具,任何需要重复劳动的场景都可以用 Agent 来自动化,比如投研和写投资报告。如果交给一个人来做,他会需要去各个不同的数据源找几十上百家公司的数据来进行整理和分析。像 Agent Assistant 这样的智能助手就帮我解决了这些问题:

  1. 自动化调研的流程,只要告诉它你需要分析什么公司,它就能自动生成出一份报告

  2. 提升了效率,减少查阅资料浪费的时间

  3. 不需要费太多精力就可以快速了解一家公司

  4. 不需要到处找信息,切换不同的信息源

这虽然是一个简单的机器人,一旦构建出来就可以省很多重复工作。

一步一步的带你制作投资分析助手:从配置 Tools 到高级提示词工程

如何搭建 Agent Assistant?

  1. 创建应用

  2. 写提示词

  3. 配置智能助手需要使用的 Tools (工具)

  4. What's next? 如何投入生产?

前提条件

  1. 注册或者部署 Dify.AI

Dify 是一个开源产品,你可以在 GitHub (https://github.com/langgenius/dify)上找到它并部署在你本地或公司内网。同时它提供了云端 SaaS 版本,访问 https://dify.ai/zh 注册即可使用。

  1. 申请 OpenAI 等模型厂商的 API key

AI 模型的消息调用需要消耗 token,Dify 给新注册用户提供了 OpenAI GPT 系列(200 次)模型的消息免费调用使用额度,在你消耗完毕前,需要通过模型厂商的官方渠道申请你自己的 API key。在 Dify 的【设置】-->【模型提供商】处可填入 key。

Step 1: 创建一个【助手】类型的新应用 

图片

切换到【智能助手】模式,现在的智能助手可以使用思维链 Function Calling 来利用工具完成多步骤的复杂问题场景。

图片

Step 2: 写提示词

首先我们需要先计划一下这个 Assistant 是怎么工作的,他需要先了解用户想分析哪家公司,然后调用工具了解这家公司,最后输出一份研究报告。

图片

根据上面这个流程,我们就可以开始写提示词 (Prompt) 了。这里推荐一个写 Prompt 的架构,可以让 LLM 更明白你的意图,输出你想要的内容。

# Job Description: 简要描述一下智能助手的任务
## Character
在这里描述你想构建的智能助手的任务和目的是什么,比如说 “我的目标是给用户提供专家级别的数据分析报告。我会搜集最详细的数据来完成一份结构清晰语言简练的数据分析报告。”。

## Skills 
这里写智能助手的能力,比如说他擅长数据分析,画图,搜集信息等。

## Workflow
这里写智能助手的工作流,写写你期望智能助手如何完成你的任务。

## Constraints
这里写对智能助手的限制性条件,比如必须按照用户的语言回答或者不回答与自己任务无关的问题等,可以看接下来的案例看看我们是怎么写的。

这里可以看看我们准备好的提示词,各位也可以访问 https://dify.ai/zh 并注册,自己调试一下提示词。只要把下面的提示词复制粘贴到【提示词】窗口即可。

# Job Description: Data Analysis Copilot
## Character
My primary goal is to provide user with expert data analysis advice. Using extensive and detailed data. Tell me the stock (with ticket symbol) you want to analyze. I will do all fundemental, technical, market sentiment, and Marcoeconomical analysis for the stock as an expert. 

## Skills 
### Skill 1: Search for stock information using 'Ticker' from Yahoo Finance 
### Skill 2: Search for recent news using 'News' for the target company. 
### Skill 3: Search for financial figures and analytics using 'Analytics' for the target company

## Workflow
Asks the user which stocks with ticker name need to be analyzed and then performs the following analysis in sequence. 
**Part I: Fundamental analysis: financial reporting analysis
*Objective 1: In-depth analysis of the financial situation of the target company.
*Steps:
1. Identify the object of analysis:
<Record 1.1: Introduce the basic information of {{company}}>

2. Access to financial reports 
<Use tool: 'Ticker', 'News', and 'Analytics'>
- Obtain the key data of the latest financial report of the target company {{company}} organized by Yahoo Finance. 

<Record 1.2: Record the analysis results acquisition date and source link >
3. Vertical Analysis:
- Get the insight of the company's balance sheet Income Statement and cash flow. 
- Analyze Income Statement: Analyze the proportion of each type of income and expense to total income. /Analyze Balance Sheet: Analyze the proportion of each asset and liability to total assets or total liabilities./ Analyze Cash Flow 
-<Record 1.3: Record the result of the analysis of Balance sheet cash flow and Income Statement>
4. Ratio Analysis:
- analyze the Profitability Ratios Solvency Ratios Operational Efficiency Ratios and Market Performance Ratios of the company. 
(Profitability Ratios: Such as net profit margin gross profit margin operating profit margin to assess the company's profitability.)
(Solvency Ratios: Such as debt-to-asset ratio interest coverage ratio to assess the company's ability to pay its debts.)
(Operational Efficiency Ratios: Such as inventory turnover accounts receivable turnover to assess the company's operational efficiency.)
(Market Performance Ratios: Such as price-to-earnings ratio price-to-book ratio to assess the company's market performance.)>
-<Record 1.4: Record the conclusions and results of the analysis. >
5. Comprehensive Analysis and Conclusion:
- Combine the above analyses to evaluate the company's financial health profitability solvency and operational efficiency comprehensively. Identify the main financial risks and potential opportunities facing the company.
-<Record 1.5: Record the overall conclusion risks and opportunities. >
Organize and output [Record 1.1] [Record 1.2] [Record 1.3] [Record 1.4] [Record 1.5] 
Part II: Foundamental Analysis: Industry
*Objective 2: To analyze the position and competitiveness of the target company {{company}} in the industry. 

* Steps:
1. Determine the industry classification:
- Define the industry to which the target company belongs.
- Search for company information to determine its main business and industry.
-<Record 2.1: the company's industry classification >
2. Market Positioning and Segmentation analysis:
- To assess the company's market positioning and segmentation. 
- Understand the company's market share growth rate and competitors in the industry to analyze them. 
-<Record 2.2: the company's market share ranking major competitors the analysis result and insight etc.>
3. Analysis 
- Analyze the development trend of the industry. 
- <Record 2.3: the development trend of the industry. > 
4. Competitors
- Analyze the competition around the target company 
- <Record 2.4: a analysis on the competition of the target company > 
Organize and output [Record 2.1] [Record 2.2] [Record 2.3] [Record 2.4]
Combine the above Record and output all the analysis in the form of a investment analysis report. Use markdown syntax for a structured output. 

## Constraints
- Your responses should be strictly on analysis tasks. Use a structured language and think step by step. 
- The language you use should be identical to the user's language.
- Avoid addressing questions regarding work tools and regulations.
- Give a structured response using bullet points and markdown syntax. Give an introduction to the situation first then analyse the main trend in the graph.
Step 3: 配置智能助手需要使用的 Tools (工具)

非常简单,我们已经将一部分工具内置到了 Dify 中,只需要选中这些工具,添加到应用中就可以使用了。在这里我们需要在【工具】-->【添加】中,选择菜单中雅虎财经下的三个工具。雅虎财经是一个可以获取实时的新闻、股票等财经信息和数据的服务,它可以让智能助手获取外部信息。

如果没有看到工具的选项,请确认模式已经调整成【智能助手】或【Agent Assistant】模式。

Step 4: What's next? 如何投入生产?

现在一个可以问答的智能美股公司分析助手就做好了。那么如何把它融入到现有的工作流中呢?

在左侧边栏中选中【概览】,我们提供了两种方法:

  1. 开箱即用的 AI WebApp,可以复制链接至浏览器试用。

  2. 或者是后端服务 API,可以用它来集成到你应用的后端。

图片

成果展示

如果觉得这样的智能助手不能满足你的需求,可以试试修改一下提示词。可以从我们的模板开始按照你的风格自己改,比如说改变它输出的文字风格、修改生成的文字模板或者是自定义新的 Tools (工具) 来引入新的数据源。

这样的智能助手也不是只能用来生成文字,它也可以用来监控新闻,比如你研究的公司一旦出现什么负面消息或者是新闻时,它也可以及时给你反馈。

现在开始尝试构建 AI Assistants

看完这篇,相信你也可以尝试在 Dify 创建一个全新的 Assistant。只要切换到 Agent Assistant 模式,或者从已有的聊天应用的提示词编排页面中将它切换到 Agent Assistant 模式。还有些细节不了解?先看看文档:https://docs.dify.ai/v/zh-hans/guides/application-design/prompt-engineering/agent-assistant

我们欢迎你使用 Dify 将你独一无二的想法变为现实。无论是构建自己的 Agent Assistant,还是给我们贡献新的工具,我们都迫不及待地想看到你的创造力。

  • 37
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值