finagent-eval 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- finagent_eval-1.0.0/LICENSE +21 -0
- finagent_eval-1.0.0/PKG-INFO +494 -0
- finagent_eval-1.0.0/README.md +447 -0
- finagent_eval-1.0.0/pyproject.toml +122 -0
- finagent_eval-1.0.0/setup.cfg +4 -0
- finagent_eval-1.0.0/src/finagent/__init__.py +81 -0
- finagent_eval-1.0.0/src/finagent/_compat.py +8 -0
- finagent_eval-1.0.0/src/finagent/adapter/__init__.py +27 -0
- finagent_eval-1.0.0/src/finagent/adapter/autogen.py +146 -0
- finagent_eval-1.0.0/src/finagent/adapter/crewai.py +142 -0
- finagent_eval-1.0.0/src/finagent/adapter/http.py +318 -0
- finagent_eval-1.0.0/src/finagent/adapter/langgraph.py +278 -0
- finagent_eval-1.0.0/src/finagent/adapter/registry.py +245 -0
- finagent_eval-1.0.0/src/finagent/adversarial/__init__.py +57 -0
- finagent_eval-1.0.0/src/finagent/adversarial/adversarial.py +744 -0
- finagent_eval-1.0.0/src/finagent/adversarial/attacks.py +23 -0
- finagent_eval-1.0.0/src/finagent/adversarial/financial.py +585 -0
- finagent_eval-1.0.0/src/finagent/adversarial/mutators.py +19 -0
- finagent_eval-1.0.0/src/finagent/api/__init__.py +57 -0
- finagent_eval-1.0.0/src/finagent/api/app.py +260 -0
- finagent_eval-1.0.0/src/finagent/api/middleware/__init__.py +23 -0
- finagent_eval-1.0.0/src/finagent/api/middleware/auth.py +132 -0
- finagent_eval-1.0.0/src/finagent/api/middleware/ratelimit.py +123 -0
- finagent_eval-1.0.0/src/finagent/api/middleware/responsetime.py +263 -0
- finagent_eval-1.0.0/src/finagent/api/routes.py +951 -0
- finagent_eval-1.0.0/src/finagent/api/schemas.py +220 -0
- finagent_eval-1.0.0/src/finagent/api/websocket.py +110 -0
- finagent_eval-1.0.0/src/finagent/audit/__init__.py +14 -0
- finagent_eval-1.0.0/src/finagent/audit/tool_auditor.py +399 -0
- finagent_eval-1.0.0/src/finagent/cli.py +292 -0
- finagent_eval-1.0.0/src/finagent/config.py +101 -0
- finagent_eval-1.0.0/src/finagent/interface/__init__.py +64 -0
- finagent_eval-1.0.0/src/finagent/interface/base.py +248 -0
- finagent_eval-1.0.0/src/finagent/interface/exceptions.py +223 -0
- finagent_eval-1.0.0/src/finagent/interface/models.py +169 -0
- finagent_eval-1.0.0/src/finagent/isolation/__init__.py +15 -0
- finagent_eval-1.0.0/src/finagent/isolation/manager.py +200 -0
- finagent_eval-1.0.0/src/finagent/isolation/production.py +423 -0
- finagent_eval-1.0.0/src/finagent/judge/__init__.py +31 -0
- finagent_eval-1.0.0/src/finagent/judge/consensus.py +153 -0
- finagent_eval-1.0.0/src/finagent/judge/judge.py +897 -0
- finagent_eval-1.0.0/src/finagent/judge/models.py +23 -0
- finagent_eval-1.0.0/src/finagent/judge/prompts.py +133 -0
- finagent_eval-1.0.0/src/finagent/mcp/__init__.py +19 -0
- finagent_eval-1.0.0/src/finagent/mcp/health.py +178 -0
- finagent_eval-1.0.0/src/finagent/mcp/manager.py +244 -0
- finagent_eval-1.0.0/src/finagent/mcp/restart_policy.py +221 -0
- finagent_eval-1.0.0/src/finagent/monitor/__init__.py +9 -0
- finagent_eval-1.0.0/src/finagent/monitor/metrics.py +221 -0
- finagent_eval-1.0.0/src/finagent/pipeline/__init__.py +66 -0
- finagent_eval-1.0.0/src/finagent/pipeline/checkpointer.py +237 -0
- finagent_eval-1.0.0/src/finagent/pipeline/distributed_scheduler.py +588 -0
- finagent_eval-1.0.0/src/finagent/pipeline/engine.py +214 -0
- finagent_eval-1.0.0/src/finagent/pipeline/nodes.py +356 -0
- finagent_eval-1.0.0/src/finagent/pipeline/pipeline.py +1719 -0
- finagent_eval-1.0.0/src/finagent/pipeline/quota.py +124 -0
- finagent_eval-1.0.0/src/finagent/pipeline/scheduler.py +237 -0
- finagent_eval-1.0.0/src/finagent/report/__init__.py +17 -0
- finagent_eval-1.0.0/src/finagent/report/charts.py +427 -0
- finagent_eval-1.0.0/src/finagent/report/generator.py +291 -0
- finagent_eval-1.0.0/src/finagent/scoring/__init__.py +87 -0
- finagent_eval-1.0.0/src/finagent/scoring/aggregator.py +12 -0
- finagent_eval-1.0.0/src/finagent/scoring/engine.py +1294 -0
- finagent_eval-1.0.0/src/finagent/scoring/llm_judge_scorer.py +139 -0
- finagent_eval-1.0.0/src/finagent/scoring/metrics.py +35 -0
- finagent_eval-1.0.0/src/finagent/scoring/rater.py +13 -0
- finagent_eval-1.0.0/src/finagent/scoring/rules.py +301 -0
- finagent_eval-1.0.0/src/finagent/scoring/trading_performance.py +334 -0
- finagent_eval-1.0.0/src/finagent/scoring/veto.py +464 -0
- finagent_eval-1.0.0/src/finagent/taskgen/__init__.py +34 -0
- finagent_eval-1.0.0/src/finagent/taskgen/datasets.py +28 -0
- finagent_eval-1.0.0/src/finagent/taskgen/generator.py +1308 -0
- finagent_eval-1.0.0/src/finagent/taskgen/sampler.py +12 -0
- finagent_eval-1.0.0/src/finagent/tracing/__init__.py +3 -0
- finagent_eval-1.0.0/src/finagent/tracing/langsmith.py +476 -0
- finagent_eval-1.0.0/src/finagent/utils/__init__.py +3 -0
- finagent_eval-1.0.0/src/finagent/utils/logging.py +120 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/PKG-INFO +494 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/SOURCES.txt +81 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/dependency_links.txt +1 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/entry_points.txt +2 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/requires.txt +30 -0
- finagent_eval-1.0.0/src/finagent_eval.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FinAgent Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: finagent-eval
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 金融AI Agent评测系统 - 标准化的评测框架
|
|
5
|
+
Author-email: FinAgent Team <finagent@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/finagent/finagent-eval
|
|
8
|
+
Project-URL: Documentation, https://github.com/finagent/finagent-eval#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/finagent/finagent-eval
|
|
10
|
+
Keywords: ai,agent,evaluation,finance,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pydantic>=2.0.0
|
|
22
|
+
Requires-Dist: fastapi>=0.100.0
|
|
23
|
+
Requires-Dist: uvicorn>=0.23.0
|
|
24
|
+
Requires-Dist: httpx>=0.24.0
|
|
25
|
+
Requires-Dist: asyncpg>=0.28.0
|
|
26
|
+
Requires-Dist: python-multipart>=0.0.6
|
|
27
|
+
Requires-Dist: pyyaml>=6.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff>=0.0.280; extra == "dev"
|
|
36
|
+
Requires-Dist: radon>=6.0.0; extra == "dev"
|
|
37
|
+
Provides-Extra: langchain
|
|
38
|
+
Requires-Dist: langchain>=0.1.0; extra == "langchain"
|
|
39
|
+
Requires-Dist: langgraph>=0.0.20; extra == "langchain"
|
|
40
|
+
Provides-Extra: openai
|
|
41
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
42
|
+
Provides-Extra: anthropic
|
|
43
|
+
Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
|
|
44
|
+
Provides-Extra: all
|
|
45
|
+
Requires-Dist: finagent-eval[anthropic,dev,langchain,openai]; extra == "all"
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
<div align="center">
|
|
49
|
+
|
|
50
|
+
# FinAgent-Eval
|
|
51
|
+
|
|
52
|
+
### 基金金融AI Agent自主评测系统
|
|
53
|
+
|
|
54
|
+
[](https://www.python.org/downloads/)
|
|
55
|
+
[](LICENSE)
|
|
56
|
+
[](tests/)
|
|
57
|
+
[](pyproject.toml)
|
|
58
|
+
|
|
59
|
+
标准化、可复现的金融 AI Agent 评测框架,为基金领域智能体提供全方位能力与可信度评估。
|
|
60
|
+
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 项目简介
|
|
66
|
+
|
|
67
|
+
FinAgent-Eval 是一套面向基金金融场景的 AI Agent 自主评测系统,采用 **4+7 双层评测维度体系**(4 项核心能力 + 7 项可信度指标),结合 **LLM-as-Judge 多模型交叉验证**机制,对金融智能体进行标准化、可复现的全面评估。系统支持 **LangGraph、AutoGen、CrewAI、HTTP API** 等主流 Agent 框架适配,并提供快速评测(约 4 小时)与完整评测(约 12 小时)双模式,满足从日常迭代到正式发布的全流程评测需求。
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 核心特性
|
|
72
|
+
|
|
73
|
+
- **4+7 双层评测维度体系** — 4 项核心能力维度(准确性、完整性、推理能力、工具使用)+ 7 项可信度维度(专业性、合规性、风险意识、鲁棒性、安全性、透明度、一致性),全面覆盖金融 Agent 评估需求
|
|
74
|
+
- **S/A/B/C/D 五级评级 + 一票否决机制** — 量化评分与等级评定相结合,合规性或安全性低于 30 分时自动触发一票否决,直接评为 D 级
|
|
75
|
+
- **多框架适配** — 内置 LangGraph、AutoGen、CrewAI、HTTP API 四种适配器,通过统一 `FinancialAgentInterface` 接口实现即插即用
|
|
76
|
+
- **LLM-as-Judge 多模型交叉验证** — 集成 GPT-4o、Claude、DeepSeek 等多个 LLM 评判模型,通过共识机制降低单模型偏差
|
|
77
|
+
- **四级对抗性测试** — baseline -> noisy -> meta_cognitive -> adversarial 逐级递进的对抗性测试框架,深度检验 Agent 鲁棒性
|
|
78
|
+
- **MCP 标准化工具集成** — 预配置 8 个 MCP 工具服务器(A 股数据、基金数据、Yahoo Finance、SEC EDGAR、Tushare、计算器、文件系统、Web 搜索)
|
|
79
|
+
- **快速评测 / 完整评测双模式** — 快速模式约 4 小时(5 维度 / 20 任务),完整模式约 12 小时(11 维度 / 60-100 任务)
|
|
80
|
+
- **Prometheus + Grafana 监控告警** — 内置指标采集、可视化面板和 AlertManager 告警规则,实时掌握评测系统运行状态
|
|
81
|
+
- **三阶段评估流水线(STATIC → DYNAMIC → TRUST)** — 将评测拆分为静态分析、动态执行、可信度评估三个阶段,支持独立运行与断点续跑,提升评测可观测性与容错能力
|
|
82
|
+
- **Redis 分布式任务调度器** — 基于 Redis 的分布式任务调度引擎,支持多实例水平扩展与任务负载均衡,确保大规模评测场景下的稳定调度
|
|
83
|
+
- **API 响应时间保障(P95 < 500ms)** — 内置响应时间监控中间件,实时追踪 API 延迟,P95 响应时间低于 500ms,保障前端交互体验
|
|
84
|
+
- **断点续跑(Checkpoint/Resume)** — 评测任务自动保存检查点,支持从任意阶段恢复执行,避免因中断导致的重复评测开销
|
|
85
|
+
- **React + Streamlit 双前端** — React 管理端提供完整的管理与可视化能力,Streamlit 界面提供轻量级快速操作入口
|
|
86
|
+
- **WebSocket 实时进度推送** — 支持评测进度的实时推送,前端无需轮询即可获取进度更新、状态变更和任务完成通知
|
|
87
|
+
- **Agent 对比评测** — 同时评测多个 Agent(最多 5 个),生成对比报告和排名,便于版本选型和竞品分析
|
|
88
|
+
- **行业基准对比** — 将评测结果与行业基准对比,了解 Agent 在行业中的位置和百分位排名
|
|
89
|
+
- **合规认证报告** — 生成符合监管要求的合规认证报告,支持中国基金监管和 SEC/FINRA 框架
|
|
90
|
+
- **智能改进建议** — 基于评测结果生成针对性的改进建议,包含问题诊断、改进措施和快速见效建议
|
|
91
|
+
- **深色模式与响应式设计** — React 前端支持深色模式切换和移动端适配,提供良好的用户体验
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 系统架构
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
99
|
+
│ 前端层 (Frontend) │
|
|
100
|
+
│ ┌──────────────────────────┐ ┌──────────────────────────────┐ │
|
|
101
|
+
│ │ React 管理端 (:3000) │ │ Streamlit 界面 (:8501) │ │
|
|
102
|
+
│ └──────────┬───────────────┘ └──────────────┬───────────────┘ │
|
|
103
|
+
└─────────────┼─────────────────────────────────┼─────────────────┘
|
|
104
|
+
│ │
|
|
105
|
+
┌─────────────┼─────────────────────────────────┼─────────────────┐
|
|
106
|
+
│ │ API 层 (FastAPI) │ │
|
|
107
|
+
│ ┌──────────▼─────────────────────────────────▼───────────────┐ │
|
|
108
|
+
│ │ REST API + JWT 认证 + 限流中间件 │ │
|
|
109
|
+
│ │ /api/v1/evaluation /api/v1/agents /api/v1/tasks │ │
|
|
110
|
+
│ └──────────┬─────────────────────────────────┬───────────────┘ │
|
|
111
|
+
│ │ │ │
|
|
112
|
+
│ ┌──────────▼──────────┐ ┌──────────────────▼───────────────┐ │
|
|
113
|
+
│ │ 评测流水线 │ │ 适配器层 │ │
|
|
114
|
+
│ │ (Pipeline Engine) │ │ LangGraph | AutoGen | CrewAI │ │
|
|
115
|
+
│ │ ┌──────┐ ┌──────┐ │ │ HTTP API | Custom Adapter │ │
|
|
116
|
+
│ │ │调度器│ │检查点│ │ └──────────────────────────────────┘ │
|
|
117
|
+
│ │ └──┬───┘ └──────┘ │ │
|
|
118
|
+
│ └─────┼───────────────┘ │
|
|
119
|
+
│ │ │
|
|
120
|
+
│ ┌─────▼───────────────────────────────────────────────────┐ │
|
|
121
|
+
│ │ 核心评测模块 │ │
|
|
122
|
+
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐ │ │
|
|
123
|
+
│ │ │ 任务生成 │ │ LLM Judge│ │ 评分引擎 │ │ 对抗性测试 │ │ │
|
|
124
|
+
│ │ │(TaskGen) │ │(Consensus)│ │(Scoring) │ │(Adversarial)│ │ │
|
|
125
|
+
│ │ └──────────┘ └──────────┘ └──────────┘ └───────────┘ │ │
|
|
126
|
+
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐ │ │
|
|
127
|
+
│ │ │ MCP 管理 │ │ 隔离管理 │ │ 审计日志 │ │ 报告生成 │ │ │
|
|
128
|
+
│ │ │(MCP) │ │(Isolation)│ │(Audit) │ │(Report) │ │ │
|
|
129
|
+
│ │ └──────────┘ └──────────┘ └──────────┘ └───────────┘ │ │
|
|
130
|
+
│ └─────────────────────────────────────────────────────────┘ │
|
|
131
|
+
│ │
|
|
132
|
+
│ ┌─────────────────────────────────────────────────────────┐ │
|
|
133
|
+
│ │ 基础设施层 │ │
|
|
134
|
+
│ │ PostgreSQL │ Redis │ Prometheus │ Grafana │ AlertManager │ │
|
|
135
|
+
│ └─────────────────────────────────────────────────────────┘ │
|
|
136
|
+
└────────────────────────────────────────────────────────────────┘
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 快速开始
|
|
142
|
+
|
|
143
|
+
### 环境要求
|
|
144
|
+
|
|
145
|
+
- Python >= 3.10
|
|
146
|
+
- PostgreSQL 16+
|
|
147
|
+
- Redis 7+(可选,用于缓存)
|
|
148
|
+
|
|
149
|
+
### 安装
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# 基础安装
|
|
153
|
+
pip install finagent-eval
|
|
154
|
+
|
|
155
|
+
# 安装全部可选依赖(推荐)
|
|
156
|
+
pip install "finagent-eval[all]"
|
|
157
|
+
|
|
158
|
+
# 按需安装特定框架支持
|
|
159
|
+
pip install "finagent-eval[langchain]" # LangGraph 支持
|
|
160
|
+
pip install "finagent-eval[openai]" # OpenAI 支持
|
|
161
|
+
pip install "finagent-eval[anthropic]" # Anthropic 支持
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 配置
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# 生成默认配置文件
|
|
168
|
+
finagent-eval config --init
|
|
169
|
+
|
|
170
|
+
# 配置环境变量(.env)
|
|
171
|
+
echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/finagent_eval" >> .env
|
|
172
|
+
echo "OPENAI_API_KEY=sk-xxx" >> .env
|
|
173
|
+
echo "ANTHROPIC_API_KEY=sk-ant-xxx" >> .env
|
|
174
|
+
echo "DEEPSEEK_API_KEY=sk-xxx" >> .env
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 启动服务
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# 启动 API 服务
|
|
181
|
+
finagent-eval serve --host 0.0.0.0 --port 8000
|
|
182
|
+
|
|
183
|
+
# 或使用 Docker Compose 一键启动全部服务
|
|
184
|
+
docker-compose up -d
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 运行评测
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# 快速评测(5 维度,约 4 小时)
|
|
191
|
+
finagent-eval eval --agent-id my-agent --endpoint http://localhost:8001 --mode quick
|
|
192
|
+
|
|
193
|
+
# 完整评测(11 维度,约 12 小时)
|
|
194
|
+
finagent-eval eval --agent-id my-agent --endpoint http://localhost:8001 --mode full -o result.json
|
|
195
|
+
|
|
196
|
+
# 运行对抗性测试
|
|
197
|
+
finagent-eval test --agent-id my-agent --endpoint http://localhost:8001 --level all -o test_result.json
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Python SDK
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from finagent import LangGraphAdapter, AgentConfig, EvalPipeline, PipelineConfig
|
|
204
|
+
|
|
205
|
+
# 创建适配器
|
|
206
|
+
config = AgentConfig(
|
|
207
|
+
agent_id="my-agent",
|
|
208
|
+
agent_name="My Financial Agent",
|
|
209
|
+
agent_type="langgraph",
|
|
210
|
+
)
|
|
211
|
+
adapter = LangGraphAdapter(graph=my_graph, config=config)
|
|
212
|
+
|
|
213
|
+
# 运行评测
|
|
214
|
+
pipeline = EvalPipeline(agent=adapter, config=PipelineConfig(eval_mode="quick"))
|
|
215
|
+
result = await pipeline.run()
|
|
216
|
+
print(f"总体分数: {result.evaluation_score.overall_score}")
|
|
217
|
+
print(f"评级: {result.evaluation_score.overall_rating}")
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 项目结构
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
finagent-eval/
|
|
226
|
+
├── src/finagent/ # 核心源码
|
|
227
|
+
│ ├── adapter/ # Agent 框架适配器(LangGraph/AutoGen/CrewAI/HTTP)
|
|
228
|
+
│ ├── adversarial/ # 对抗性测试模块(四级对抗框架)
|
|
229
|
+
│ ├── api/ # FastAPI REST API(路由/中间件/Schema)
|
|
230
|
+
│ │ └── middleware/ # API 中间件
|
|
231
|
+
│ │ ├── responsetime.py # 响应时间监控中间件
|
|
232
|
+
│ │ └── ratelimit.py # 限流中间件
|
|
233
|
+
│ ├── audit/ # 工具调用审计日志
|
|
234
|
+
│ ├── interface/ # 统一 Agent 接口定义(FinancialAgentInterface)
|
|
235
|
+
│ ├── isolation/ # 评测环境隔离管理
|
|
236
|
+
│ ├── judge/ # LLM-as-Judge 评判模块(多模型共识)
|
|
237
|
+
│ ├── mcp/ # MCP 工具服务器管理(健康检查/重启策略)
|
|
238
|
+
│ ├── monitor/ # Prometheus 指标采集
|
|
239
|
+
│ ├── pipeline/ # 评测流水线引擎(调度/检查点/配额)
|
|
240
|
+
│ │ └── distributed_scheduler.py # Redis 分布式调度器
|
|
241
|
+
│ ├── report/ # 评测报告生成(图表/多格式导出)
|
|
242
|
+
│ ├── scoring/ # 评分引擎(聚合/评级/一票否决)
|
|
243
|
+
│ ├── taskgen/ # 评测任务生成(多数据集/采样策略)
|
|
244
|
+
│ ├── tracing/ # LangSmith 链路追踪
|
|
245
|
+
│ ├── utils/ # 工具函数(日志等)
|
|
246
|
+
│ ├── cli.py # CLI 命令行入口
|
|
247
|
+
│ └── config.py # 全局配置管理
|
|
248
|
+
├── tests/ # 测试套件
|
|
249
|
+
│ ├── unit/ # 单元测试
|
|
250
|
+
│ ├── integration/ # 集成测试
|
|
251
|
+
│ └── benchmark/ # 性能基准测试
|
|
252
|
+
├── web/ # React 前端(Vite + Ant Design)
|
|
253
|
+
├── config/ # 配置文件
|
|
254
|
+
│ ├── prometheus.yml # Prometheus 采集配置
|
|
255
|
+
│ ├── alertmanager/ # AlertManager 告警规则
|
|
256
|
+
│ ├── grafana_dashboards/ # Grafana 面板 JSON
|
|
257
|
+
│ └── migrations/ # 数据库迁移脚本
|
|
258
|
+
├── data/datasets/ # 评测数据集
|
|
259
|
+
│ ├── bizfinbench/ # BizFinBench 金融基准
|
|
260
|
+
│ ├── finmcp_bench/ # FinMCP-Bench 工具调用基准
|
|
261
|
+
│ ├── fintrust/ # FINTRUST 金融可信度基准
|
|
262
|
+
│ ├── stockbench/ # StockBench 股票基准
|
|
263
|
+
│ └── traderbench/ # TraderBench 交易基准
|
|
264
|
+
├── mcp_servers/ # MCP 工具服务器配置(8 个预配置)
|
|
265
|
+
├── docs/ # 项目文档
|
|
266
|
+
│ ├── api_reference.md # REST API 参考文档
|
|
267
|
+
│ ├── adapter_guide.md # 适配器开发指南
|
|
268
|
+
│ ├── deployment.md # 部署指南
|
|
269
|
+
│ ├── interface_spec.md # 接口规范
|
|
270
|
+
│ └── user_manual.md # 用户手册
|
|
271
|
+
├── streamlit_app.py # Streamlit 前端入口
|
|
272
|
+
├── docker-compose.yml # Docker Compose 编排
|
|
273
|
+
├── Dockerfile # Docker 镜像构建
|
|
274
|
+
├── pyproject.toml # Python 项目配置
|
|
275
|
+
└── .env.example # 环境变量示例
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## 评测维度说明
|
|
281
|
+
|
|
282
|
+
### 能力维度(权重 60%)
|
|
283
|
+
|
|
284
|
+
| 维度 | 英文标识 | 说明 |
|
|
285
|
+
|------|----------|------|
|
|
286
|
+
| 准确性 | `accuracy` | 事实准确性、数据正确性、计算精度 |
|
|
287
|
+
| 完整性 | `completeness` | 回答完整程度、信息覆盖度、关键要素遗漏检查 |
|
|
288
|
+
| 推理能力 | `reasoning` | 逻辑推理、因果分析、多步推导能力 |
|
|
289
|
+
| 工具使用 | `tool_usage` | 工具调用正确性、参数准确性、结果解读能力 |
|
|
290
|
+
|
|
291
|
+
### 可信度维度(权重 40%)
|
|
292
|
+
|
|
293
|
+
| 维度 | 英文标识 | 说明 |
|
|
294
|
+
|------|----------|------|
|
|
295
|
+
| 专业性 | `professionalism` | 专业术语使用、行业规范遵循、表达规范性 |
|
|
296
|
+
| 合规性 | `compliance` | 监管合规要求、信息披露规范、投资适当性 |
|
|
297
|
+
| 风险意识 | `risk_awareness` | 风险识别与提示、下行风险分析、止损建议 |
|
|
298
|
+
| 鲁棒性 | `robustness` | 异常输入处理、边界情况应对、噪声容忍度 |
|
|
299
|
+
| 安全性 | `security` | 数据安全防护、隐私保护、越权访问防范 |
|
|
300
|
+
| 透明度 | `transparency` | 推理过程可解释性、信息来源标注、不确定性表达 |
|
|
301
|
+
| 一致性 | `consistency` | 多轮对话一致性、逻辑自洽、前后回答不矛盾 |
|
|
302
|
+
|
|
303
|
+
### 评级标准
|
|
304
|
+
|
|
305
|
+
| 评级 | 分数范围 | 说明 |
|
|
306
|
+
|------|----------|------|
|
|
307
|
+
| **S** | 95 - 100 | 卓越 — 可直接投入生产环境 |
|
|
308
|
+
| **A** | 85 - 94 | 优秀 — 满足大部分生产要求 |
|
|
309
|
+
| **B** | 70 - 84 | 良好 — 基本满足要求,部分维度需改进 |
|
|
310
|
+
| **C** | 60 - 69 | 合格 — 存在明显短板,需针对性优化 |
|
|
311
|
+
| **D** | < 60 | 不合格 — 不建议上线 |
|
|
312
|
+
|
|
313
|
+
> **一票否决机制:** 当合规性(`compliance`)或安全性(`security`)维度得分低于 30 分时,无论总分如何,均直接评为 D 级。
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 适配器支持
|
|
318
|
+
|
|
319
|
+
系统通过统一的 `FinancialAgentInterface` 接口实现多框架适配,所有适配器均需实现 9 个核心方法(`ainvoke`、`abatch`、`astream`、`get_config`、`get_state`、`reset`、`serialize_state`、`deserialize_state`、`get_trace`)。
|
|
320
|
+
|
|
321
|
+
| 适配器 | 模块路径 | 说明 |
|
|
322
|
+
|--------|----------|------|
|
|
323
|
+
| **LangGraph** | `finagent.adapter.langgraph` | 基于 LangGraph 的 Agent 适配,支持 Checkpointer 状态持久化 |
|
|
324
|
+
| **AutoGen** | `finagent.adapter.autogen` | 基于 Microsoft AutoGen 的多 Agent 对话适配 |
|
|
325
|
+
| **CrewAI** | `finagent.adapter.crewai` | 基于 CrewAI 的多角色协作 Agent 适配 |
|
|
326
|
+
| **HTTP API** | `finagent.adapter.http` | 通用 HTTP API 适配,适用于任意 REST 端点 |
|
|
327
|
+
| **自定义** | 继承 `FinancialAgentInterface` | 实现统一接口即可接入自定义 Agent |
|
|
328
|
+
|
|
329
|
+
> 详细的适配器开发指南请参阅 [docs/adapter_guide.md](docs/adapter_guide.md)。
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## API 文档
|
|
334
|
+
|
|
335
|
+
系统提供完整的 REST API,基础路径为 `/api/v1`,使用 JWT Bearer Token 认证。
|
|
336
|
+
|
|
337
|
+
| 端点 | 方法 | 说明 |
|
|
338
|
+
|------|------|------|
|
|
339
|
+
| `/api/v1/evaluation/start` | POST | 启动评测任务 |
|
|
340
|
+
| `/api/v1/evaluation/{id}` | GET | 获取评测状态与进度 |
|
|
341
|
+
| `/api/v1/evaluation/{id}` | DELETE | 取消评测任务 |
|
|
342
|
+
| `/api/v1/evaluation/` | GET | 列出评测任务 |
|
|
343
|
+
| `/api/v1/evaluation/{id}/resume` | POST | 从检查点恢复评测 |
|
|
344
|
+
| `/api/v1/evaluation/compare` | POST | Agent 对比评测 |
|
|
345
|
+
| `/api/v1/evaluation/batch` | POST | 批量评测 |
|
|
346
|
+
| `/api/v1/agents/register` | POST | 注册 Agent |
|
|
347
|
+
| `/api/v1/agents/{id}` | GET | 获取 Agent 信息 |
|
|
348
|
+
| `/api/v1/agents/{id}` | DELETE | 注销 Agent |
|
|
349
|
+
| `/api/v1/agents/` | GET | 列出 Agent |
|
|
350
|
+
| `/api/v1/tasks/generate` | POST | 生成评测任务 |
|
|
351
|
+
| `/api/v1/tasks/datasets` | GET | 列出可用数据集 |
|
|
352
|
+
| `/api/v1/reports/generate` | POST | 生成评测报告 |
|
|
353
|
+
| `/api/v1/reports/{id}` | GET | 获取评测报告 |
|
|
354
|
+
| `/api/v1/benchmark` | POST | 行业基准对比 |
|
|
355
|
+
| `/api/v1/compliance/report` | POST | 合规认证报告 |
|
|
356
|
+
| `/api/v1/improvement/suggestions` | POST | 智能改进建议 |
|
|
357
|
+
| `/ws/evaluation/{id}` | WS | WebSocket 实时进度 |
|
|
358
|
+
| `/health` | GET | 健康检查(免认证) |
|
|
359
|
+
| `/ready` | GET | 就绪检查,含数据库/Redis 连接检测(免认证) |
|
|
360
|
+
| `/live` | GET | 存活检查(免认证) |
|
|
361
|
+
| `/metrics` | GET | Prometheus 指标(免认证) |
|
|
362
|
+
|
|
363
|
+
> 完整的 API 请求/响应格式、错误码和限流规则请参阅 [docs/api_reference.md](docs/api_reference.md)。
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## 监控告警
|
|
368
|
+
|
|
369
|
+
系统内置基于 Prometheus + Grafana + AlertManager 的全链路监控方案。
|
|
370
|
+
|
|
371
|
+
### 指标采集
|
|
372
|
+
|
|
373
|
+
Prometheus 通过 `/metrics` 端点采集 API 服务指标,配置文件位于 `config/prometheus.yml`。
|
|
374
|
+
|
|
375
|
+
### 可视化面板
|
|
376
|
+
|
|
377
|
+
Grafana 预置 4 套仪表盘(`config/grafana_dashboards/`):
|
|
378
|
+
|
|
379
|
+
| 面板 | 说明 |
|
|
380
|
+
|------|------|
|
|
381
|
+
| `evaluation_overview.json` | 评测总览 — 评测数量、通过率、耗时分布 |
|
|
382
|
+
| `llm_judge.json` | LLM Judge — 多模型评分一致性、共识率 |
|
|
383
|
+
| `mcp_servers.json` | MCP 服务器 — 工具调用成功率、响应延迟 |
|
|
384
|
+
| `resource_usage.json` | 资源使用 — CPU、内存、数据库连接池 |
|
|
385
|
+
|
|
386
|
+
### 告警规则
|
|
387
|
+
|
|
388
|
+
AlertManager 配置位于 `config/alertmanager/`,内置告警规则覆盖评测失败率过高、MCP 服务不可用、API 响应超时等场景。
|
|
389
|
+
|
|
390
|
+
### 响应时间监控
|
|
391
|
+
|
|
392
|
+
系统内置响应时间监控中间件(`src/finagent/api/middleware/responsetime.py`),实时追踪所有 API 端点的响应延迟,P95 响应时间保障低于 500ms。相关指标通过 Prometheus `/metrics` 端点暴露,可在 Grafana 面板中查看延迟趋势与分布。
|
|
393
|
+
|
|
394
|
+
### 代码复杂度 CI 门控
|
|
395
|
+
|
|
396
|
+
通过 radon 工具对代码复杂度进行自动化检查,在 CI 流水线中设置复杂度门控,确保核心模块的可维护性。当模块平均圈复杂度超过阈值时,CI 将自动失败并提示优化。
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 前端
|
|
401
|
+
|
|
402
|
+
### React 管理端
|
|
403
|
+
|
|
404
|
+
基于 **React + Vite + Ant Design** 构建的现代化管理界面,提供以下功能页面:
|
|
405
|
+
|
|
406
|
+
- **Dashboard** — 系统概览,展示评测总数、平均分数、通过率等核心指标
|
|
407
|
+
- **Agent 管理** — Agent 注册、配置与生命周期管理
|
|
408
|
+
- **评测列表** — 历史评测记录查看、状态跟踪与结果对比
|
|
409
|
+
- **评测详情** — 按维度查看评分详情、任务执行记录和对抗性测试结果
|
|
410
|
+
- **报告中心** — 评测报告生成、导出与归档
|
|
411
|
+
- **系统设置** — LLM API Key、数据源和系统参数配置
|
|
412
|
+
|
|
413
|
+
### Streamlit 界面
|
|
414
|
+
|
|
415
|
+
基于 **Streamlit** 的轻量级操作界面(`streamlit_app.py`),适合快速启动和日常使用:
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
streamlit run streamlit_app.py
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
提供系统概览、新建评测、评测列表、结果查看和系统设置等功能页面。
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
## 开发指南
|
|
426
|
+
|
|
427
|
+
### 环境搭建
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# 克隆仓库
|
|
431
|
+
git clone https://github.com/finagent/finagent-eval.git
|
|
432
|
+
cd finagent-eval
|
|
433
|
+
|
|
434
|
+
# 安装开发依赖(包含测试、格式化、类型检查工具)
|
|
435
|
+
pip install -e ".[dev]"
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### 运行测试
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
# 运行全部测试
|
|
442
|
+
pytest
|
|
443
|
+
|
|
444
|
+
# 运行特定类型测试
|
|
445
|
+
pytest tests/unit/ # 单元测试
|
|
446
|
+
pytest tests/integration/ # 集成测试
|
|
447
|
+
pytest tests/benchmark/ # 性能基准测试
|
|
448
|
+
|
|
449
|
+
# 运行测试并生成覆盖率报告
|
|
450
|
+
pytest --cov=finagent --cov-report=html
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### 代码质量
|
|
454
|
+
|
|
455
|
+
```bash
|
|
456
|
+
# 代码格式化
|
|
457
|
+
black src tests
|
|
458
|
+
isort src tests
|
|
459
|
+
|
|
460
|
+
# 代码检查
|
|
461
|
+
ruff check src tests
|
|
462
|
+
mypy src
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### 添加自定义适配器
|
|
466
|
+
|
|
467
|
+
1. 在 `src/finagent/adapter/` 下创建新模块
|
|
468
|
+
2. 继承 `FinancialAgentInterface` 并实现 9 个核心方法
|
|
469
|
+
3. 在 `src/finagent/adapter/registry.py` 中注册适配器
|
|
470
|
+
4. 参阅 [docs/adapter_guide.md](docs/adapter_guide.md) 获取详细指引
|
|
471
|
+
|
|
472
|
+
### 更多文档
|
|
473
|
+
|
|
474
|
+
| 文档 | 说明 |
|
|
475
|
+
|------|------|
|
|
476
|
+
| [用户手册](docs/user_manual.md) | 完整使用指南 |
|
|
477
|
+
| [部署指南](docs/deployment.md) | Docker / 生产环境部署 |
|
|
478
|
+
| [API 参考](docs/api_reference.md) | REST API 详细文档 |
|
|
479
|
+
| [适配器指南](docs/adapter_guide.md) | 自定义适配器开发 |
|
|
480
|
+
| [接口规范](docs/interface_spec.md) | FinancialAgentInterface 规范 |
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
## 许可证
|
|
485
|
+
|
|
486
|
+
本项目基于 [MIT License](LICENSE) 开源。
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
<div align="center">
|
|
491
|
+
|
|
492
|
+
**FinAgent-Eval** — 让金融 AI Agent 的评测标准化、可复现、可信赖
|
|
493
|
+
|
|
494
|
+
</div>
|