Skip to content

Commit df2b688

Browse files
authored
community-use-case The Stock Analysis Agent Based on 🦉OWL Framework (#442)
2 parents 1f85090 + 89d1d99 commit df2b688

File tree

15 files changed

+1751
-0
lines changed

15 files changed

+1751
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#===========================================
2+
# MODEL & API
3+
# (See https://docs.camel-ai.org/key_modules/models.html#)
4+
#===========================================
5+
# DeepSeek API (https://platform.deepseek.com/api_keys)
6+
DEEPSEEK_API_KEY='Your_Key'
7+
DEEPSEEK_API_BASE_URL="https://api.deepseek.com/v1"
8+
9+
# ZHIPU API (https://bigmodel.cn/usercenter/proj-mgmt/apikeys)
10+
ZHIPUAI_API_KEY='Your_Key'
11+
ZHIPUAI_API_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"
12+
13+
# SEC-API (https://sec-api.io/profile)
14+
SEC_API_API_KEY='Your_Key'
15+
16+
# AgentOps API (https://app.agentops.ai/settings/billing)
17+
AGENTOPS_API_KEY= 'Your_Key'
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# Ruff stuff:
171+
.ruff_cache/
172+
173+
# PyPI configuration file
174+
.pypirc
175+
176+
.directory
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# 📈 Stock Analysis Agent
2+
3+
简体中文 | [English](README.md)
4+
5+
<p>
6+
<p align="center">
7+
<img height=160 src="http://cdn.oyster-iot.cloud/stock-analysis.png">
8+
</p>
9+
<p align="center">
10+
<b face="雅黑">基于🦉OWL框架的股票分析的智能体</b>
11+
<p>
12+
</p>
13+
<p align="center">
14+
<img alt="Python" src="https://img.shields.io/badge/Python-3.10%2B-blue"/>
15+
<img alt="DeepSeek" src="https://img.shields.io/badge/DeepSeek-V3-blue"/>
16+
<img alt="Camelai" src="https://img.shields.io/badge/Camelai-0.2.35-yellowgreen"/>
17+
<img alt="OLW" src="https://img.shields.io/badge/OWL-0.0.1+-yellow"/>
18+
<img alt="license" src="https://img.shields.io/badge/license-MIT-lightgrey"/>
19+
</p>
20+
21+
## 📖 功能介绍
22+
23+
基于 🦉OWL 框架的股票分析的智能体,通过对股票的分析,为用户提供股票的分析报告,包括股票的基本信息、股票的技术指标、股票的风险指标、股票的投资建议等。
24+
25+
<p align="center">
26+
<img height=300 src="http://cdn.oyster-iot.cloud/20250330173653.png"><br>
27+
<b face="雅黑">Stock Analysis Agent 架构图</b>
28+
<p>
29+
30+
- Stock Analysis Agent: 使用使用 Camel-ai 框架中的 RolePlaying Agent(同 OWL 一样)作为主智能体
31+
- Stock Analysis Tool:使用报告搜索、SEC 工具收集公司基本信息、财务报告等信息
32+
- Search Tool:使用如百度搜索等搜索引擎工具(Camel-ai 框架自带工具)
33+
- SEC Tool:使用 SEC 工具获取公司基本信息、财务报表等信息。**注意:获取的公司财务报表会有几十万字,建议先总结再使用,否则会有高昂的 Token 费用**
34+
- SEC Agent:这里使用了 ChatAgent,通过给定公司股票代码自动调用 SEC Tool 工具获取公司财务报表数据并生成总结报告。这里可以使用免费的 LLM 模型,如智谱的 GLM-4-Flash 模型
35+
- Report Write Tool:使用文件编辑工具,将完整的公司投资分析报告写入文件
36+
37+
## 🚀 快速开始
38+
39+
### 1. 安装 OWL 框架
40+
41+
```bash
42+
# 克隆 GitHub 仓库
43+
git clone https://github.com/camel-ai/owl.git
44+
45+
# 进入项目目录
46+
cd owl
47+
48+
# 如果你还没有安装 uv,请先安装
49+
pip install uv
50+
51+
# 创建虚拟环境并安装依赖
52+
# 我们支持使用 Python 3.10、3.11、3.12
53+
uv venv .venv --python=3.10
54+
55+
# 激活虚拟环境
56+
# 对于 macOS/Linux
57+
source .venv/bin/activate
58+
# 对于 Windows
59+
.venv\Scripts\activate
60+
61+
# 安装 CAMEL 及其所有依赖
62+
uv pip install -e .
63+
64+
# 进入Stock Analysis Agent目录
65+
cd community_usecase/stock-analysis
66+
67+
```
68+
69+
### 2. 安装额外的 SEC 工具
70+
71+
```bash
72+
# 安装 SEC 工具
73+
uv pip install sec-api
74+
```
75+
76+
### 3. 配置环境变量
77+
78+
```bash
79+
# 创建 .env 文件
80+
touch .env
81+
```
82+
83+
添加相关 API keys 到 `.env` 文件 (可以参考 `.env.example` 文件)
84+
85+
```bash
86+
# DeepSeek API (https://platform.deepseek.com/api_keys)
87+
DEEPSEEK_API_KEY='Your_Key'
88+
DEEPSEEK_API_BASE_URL="https://api.deepseek.com/v1"
89+
90+
# ZHIPU API (https://bigmodel.cn/usercenter/proj-mgmt/apikeys)
91+
ZHIPUAI_API_KEY='Your_Key'
92+
ZHIPUAI_API_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"
93+
94+
# SEC-API (https://sec-api.io/profile)
95+
SEC_API_API_KEY='Your_Key'
96+
97+
# AgentOps API (https://app.agentops.ai/settings/billing)
98+
AGENTOPS_API_KEY= 'Your_Key'
99+
```
100+
101+
> [!TIP]
102+
> 项目使用 DeepSeek 作为 Stock Analysis Agent 的主模型,使用智谱的 GLM-4-Flash 作为 SEC Agent 的模型
103+
104+
### 4. 运行 Stock Analysis
105+
106+
- 查看运行参数
107+
108+
```bash
109+
python run.py --h
110+
111+
usage: run.py [-h] [--company COMPANY] [--use-agentops] [--rounds ROUNDS]
112+
113+
Stock Analysis Agent
114+
115+
options:
116+
-h, --help show this help message and exit
117+
--company COMPANY Company name to analyze
118+
--use-agentops Enable AgentOps tracking
119+
--rounds ROUNDS Maximum conversation rounds
120+
```
121+
122+
- 执行公司股票投资分析
123+
124+
```bash
125+
python run.py --company Apple
126+
```
127+
128+
![Result](http://cdn.oyster-iot.cloud/20250330224554.png)
129+
130+
- 查看运行结果
131+
132+
```bash
133+
# ./log 目录
134+
Apple_chat_history.json #记录整个执行过程,包括对话记录和工具调用信息等
135+
# ./output 目录
136+
Apple_analysis_report.md #输出的投资分析报告
137+
```
138+
139+
- 查看运行案例
140+
- Apple
141+
- [Chat History](./example/Apple/Apple_chat_history.json)
142+
- [Report](./example/Apple/Apple_analysis_report.md)
143+
- Google
144+
- [Chat History](./example/Google/Google_chat_history.json)
145+
- [Report](./example/Google/Google_analysis_report.md)
146+
- Alibaba
147+
- [Chat History](./example/Alibaba/Alibaba_chat_history.json)
148+
- [Report](./example/Alibaba/Alibaba_analysis_report.md)
149+
150+
## 🥰 获取帮助
151+
152+
如果您在运行中发现问题,可以尝试以下方法:
153+
154+
1. 查看控制台输出的错误信息
155+
2. 在 GitHub 仓库上提交 issue
156+
157+
## 📂 项目结构
158+
159+
```bash
160+
stock-analysis
161+
├── agent
162+
│ └── sec_agent.py # SEC Agent
163+
├── example
164+
├── log # log directory
165+
├── output # Report output directory
166+
├── prompts.py # Prompt templates
167+
├── run.py # Main file
168+
└── tools
169+
└── sec_tools.py # SEC Tool
170+
```
171+
172+
## 📝 License
173+
174+
本项目基于 CAMEL-AI OWL 框架构建,该框架许可是`Apache License 2.0`
175+
176+
## 🙏 致谢
177+
178+
-该项目基于[CAMEL-AI OWL 框架](https://github.com/camel-ai/owl)构建 -特别感谢 CAMEL-AI 的贡献者
179+
180+
> Finding the Scaling Law of Agents: The First and the Best Multi-Agent Framework.

0 commit comments

Comments
 (0)