How to
Unleashing AI in Finance: Building an AI Investment Analysis Assistant with Dify
Aug 1, 2023
·
Jan 26, 2024
Dify has added an Agent Assistant mode in application orchestration recently in our new update v0.5.0, which can be based on different Large Language Models (LLMs) in the market (Dify currently supports all popular LLMs on the market). It also provides a series of tools to call LLMs as needed, solving complex multi-step problem scenarios and helping developers build more imaginative GPTs and Agent Assistants.
Here, I will lead you step by step to build an AI assistant called the Stock Investment Analysis Copilot using Dify's latest Agent capabilities. It will answer a series of questions for you:
How to use Dify?
How to write useful prompt words?
How to publish applications on Dify and integrate them into your workflow?
This agent can leverage three tools from Yahoo Finance - News, Analytics, and Ticker to generate an investment analysis report for any listed company.
Let's first showcase the capability of our AI Agent.
Start by telling the Agent which listed company you are interested in, and then it can help you gather and organize any listed company's financial condition, industry status, and latest news, building a Markdown format investment report in seconds. And that's not all; this Agent doesn't just disappear after generating the report. You can continue to chat with it about any area you want to explore further.
How and Where to Use This Agent?
Agent is a versatile AI tool that can be used in any scenario that requires repetitive labor, such as investment research and writing investment reports. If left to a person, they would need to find data from various sources for dozens or hundreds of companies to organize and analyze. An intelligent assistant like our Investment Copilot solves these problems by:
Automating the research process; just tell it which company you need to analyze, and it will automatically generate a report.
Increasing efficiency and reducing the time wasted in looking up information.
Allowing quick understanding of a company without much effort.
Eliminating the need to search for information and switch between different sources.
Although it's a simple robot, once built, it can save a lot of repetitive work.
Creating an Investment Analysis Assistant: A Step-by-Step Guide
How to build an Agent Assistant?
Create an application.
Write prompt words.
Configure the Tools (tools) the intelligent assistant needs to use.
What's next? How to put it into production?
Prerequisites
Register or deploy Dify.AI
Dify is an open-source product. You can find it on GitHub and then deploy it locally or on your company's intranet. It also offers a cloud-based SaaS version, accessible at Dify.AI for use upon registration.
Apply for the API key from model providers like OpenAI
AI model message calls consume tokens. Dify provides new registered users with a free usage quota of OpenAI GPT series (200 messages). Before you exhaust this quota, you need to apply for your own API key through the official channels of the model provider. The key can be entered in Dify's [Settings] --> [Model Provider].
Step 1: Create a new Assistant app
First, create a new Assistant app and named it Investment Analysis Report Copilot.
Switch to the Agent Assistant mode, where the current intelligent assistant can use Chain-of-Thought (CoT) and Function Calling (or ReAct for models without function calling capabilities) to utilize tools to solve complex multi-step problem scenarios.
Step 2: Write your Prompts
Before start writing prompts, we need to plan how assistant works. It eneds to understand fully which company the user want to analyse, then use tool to access external data (financial figures and recent development etc. ), and finally output a report.
Here's a recommended architecture for writing prompts that makes your intent clearer to the LLM and produces the content you want.
Here you can see the prompts we've prepared. You can also visit Dify.AI and register to test the prompts yourself. Just copy and paste the following prompt into the Prompt window.
Step 3: Configure the Tools that the agent needs to use
It's very simple. There are some built-in tools in Dify, you just need to select these tools and add them to the application. Here, we need to select the three tools under Yahoo Finance from the menu in Tools --> Add. Yahoo Finance is a service that can obtain real-time news, stocks, and other financial information and data, allowing the intelligent assistant to access external information.
If you don't see the option for tools, please make sure the mode has been switched to Agent Assistant mode.
Step 4: What's next? How to put it into production?
Now, an intelligent Company Analysis Report Copilot capable of Q&A is ready. So how do you integrate it into your existing workflow?
Select Overview from the left sidebar. We offer two methods:
An out-of-the-box AI WebApp, which you can try by copying the link into a browser.
Or a Backend-as-a-Service API, which can be integrated into the backend of your application.
A Showcase of our Copilot!
If you feel that such an agent does not meet your needs, you can try modifying the prompts. Start with our template and modify it according to your style, such as changing the output text style, modifying the generated text template, or customizing new Tools to introduce new data sources.Such assistants are not only for generating text. They can also be used to monitor news, such as providing timely feedback if there is any negative news or new developments regarding the company you are researching.
Start Building AI Assistants Now
Ever thought about creating your own AI Assistant? With Dify, you can start from build a new Assistant, opting for the Agent Assistant mode. Or, take an existing Chat App and switch it to Agent Assistant type right from its prompt setup page. Our docs are a great starting point for your adventure.
We're all for you exploring Dify to turn your one-of-a-kind ideas into reality. Whether you're building your own Agent Assistant or contributing new tools to us, we can't wait to see your creations.
Don’t forget to join our Discord community to share your thoughts and questions. We’re all ears!