综合设计——多源异构数据采集与融合应用综合实践
福州大学数学与计算机科学学院
福州大学计算机与大数据学院
数据采集与融合技术 课程报告
课程名称:京东多智能体挑战赛
学号姓名:102302117 冯大河,102302154 杨如意,102302155 张怡旋,102302156 李子贤,102202110 叶志杰
专 业:数据科学和大数据技术
学 期:大三上学期
日 期:2025 年 12 月
| 码云链接 | https://gitee.com/river-feng/river-feng/tree/master/京东多智能体项目 |
目录
- 项目背景
- 项目架构设计
- 2.1 系统整体架构
- 2.2 数据流向设计
- 关键技术实现
- 3.1 多模态数据采集模块
- 3.2 任务分发策略
- 3.3 推理Agent实现
- 3.4 答案后处理器
- 项目文件结构
- 核心算法设计
- 5.1 任务分配优化算法
- 5.2 答案验证机制
- 实践过程与结果
- 6.1 实验设置
- 6.2 实践步骤
- 6.3 关键技术指标
- 6.4 遇到的挑战与解决方案
- 总结与展望
- 7.1 实践总结
- 7.2 技术收获
- 7.3 改进方向
- 结论
- 致谢
一、项目背景
本实践报告基于 京东多智能体挑战赛,该竞赛旨在推动多智能体系统在复杂场景下的协同决策与创新应用。竞赛数据集包含100条验证集样本和200条测试集样本,涵盖 多模态理解、信息检索、逻辑推理、代码生成与终端交互 等多种任务类型,难度分为 基础、进阶与复杂 三个等级。
作为本科生参赛者,我们的目标是设计并实现一个基于开源框架 OxyGent 的多智能体系统,重点解决 数据采集与智能体协作 问题。
二、项目架构设计
2.1 系统整体架构
项目采用 分层架构设计,主要包括以下三个层次:
-
数据采集与预处理层
- 多模态数据采集器(处理图像、PDF、表格等格式)
- 网页数据采集器(支持静态和动态网页)
- 数据预处理器(标准化和清洗数据)
-
多智能体协作层(基于 OxyGent 理念)
- 任务分发 Agent(根据难度分配策略)
- 理解 Agent(多模态内容解析)
- 检索 Agent(信息搜索与整合)
- 推理 Agent(逻辑分析与决策)
- 执行 Agent(代码生成与运行)
-
结果生成与优化层
- 答案后处理器(清洗和标准化)
- 结果验证器(格式检查)
- 性能分析器(准确率计算)
2.2 数据流向设计
原始问题 → 数据采集 → 任务分发 → Agent协作 → 答案生成 → 后处理 → 结果输出
三、关键技术实现
3.1 多模态数据采集模块
class MultiModalCollector:
def auto_collect(self, file_path: str) -> Dict[str, Any]:
"""自动识别文件类型并采集
支持格式:图像(.jpg, .png, .gif等)、PDF、Excel、CSV、文本文件
"""
ext = os.path.splitext(file_path)[1].lower()
if ext in ['.png', '.jpg', '.jpeg']:
return self.collect_image(file_path)
elif ext == '.pdf':
return self.collect_pdf(file_path)
elif ext in ['.xlsx', '.xls']:
return self.collect_excel(file_path)
elif ext == '.csv':
return self.collect_csv(file_path)
elif ext in ['.txt', '.md']:
return self.collect_text(file_path)
else:
return {"type": "unknown", "path": file_path}
def collect_excel(self, excel_path: str) -> Dict[str, Any]:
"""采集Excel数据,支持多sheet读取"""
try:
excel_file = pd.ExcelFile(excel_path)
all_data = {}
for sheet_name in excel_file.sheet_names:
df = pd.read_excel(excel_path, sheet_name=sheet_name)
all_data[sheet_name] = {
"shape": df.shape,
"columns": df.columns.tolist(),
"data": df.to_dict('records')
}
first_sheet = list(all_data.keys())[0]
return {
"type": "table",
"format": "excel",
"sheets": list(all_data.keys()),
"shape": all_data[first_sheet]["shape"],
"columns": all_data[first_sheet]["columns"],
"head": all_data[first_sheet]["data"][:20]
}
except Exception as e:
return {"type": "error", "message": str(e)}
3.2 任务分发策略
# 基础策略配置
strategy = {
"type": "general",
"require_agents": ["understanding", "reasoning"],
"priority": "normal"
}
# 计算类任务
if any(kw in query for kw in ["计算", "多少", "总和", "平均"]):
strategy["type"] = "calculation"
strategy["require_agents"] = ["understanding", "reasoning", "execution"]
# 多模态任务
elif has_file:
strategy["type"] = "multimodal_understanding"
strategy["require_agents"] = ["understanding", "retrieval", "reasoning"]
# 复杂任务(level≥3)
elif int(level) >= 3:
strategy["type"] = "complex"
strategy["require_agents"] = ["understanding", "retrieval", "reasoning", "execution"]
strategy["priority"] = "high"
return strategy class TaskDispatcher:
def dispatch(self, task: Dict[str, Any]) -> Dict[str, Any]:
query = task.get("query", "").lower()
level = task.get("level", "1")
has_file = "file_name" in task and task.get("file_name")
# 基础策略配置
strategy = {
"type": "general",
"require_agents": ["understanding", "reasoning"],
"priority": "normal"
}
# 计算类任务
if any(kw in query for kw in ["计算", "多少", "总和", "平均"]):
strategy["type"] = "calculation"
strategy["require_agents"] = ["understanding", "reasoning", "execution"]
# 多模态任务
elif has_file:
strategy["type"] = "multimodal_understanding"
strategy["require_agents"] = ["understanding", "retrieval", "reasoning"]
# 复杂任务(level≥3)
elif int(level) >= 3:
strategy["type"] = "complex"
strategy["require_agents"] = ["understanding", "retrieval", "reasoning", "execution"]
strategy["priority"] = "high"
return strategy
###3.3 推理Agent实现
`class ReasoningAgent:
def reason(self, task: Dict[str, Any], understanding: Dict[str, Any],
retrieval_results: Dict[str, Any] = None) -> Dict[str, Any]:
"""执行推理,支持多种问题类型"""
question_type = understanding.get("query_analysis", {}).get("question_type", "general")
if question_type == "calculation":
return self._reason_calculation(task, understanding)
elif question_type == "comparison":
return self._reason_comparison(task, understanding, retrieval_results)
elif question_type == "extraction":
return self._reason_extraction(task, understanding, retrieval_results)
else:
return self._reason_general(task, understanding, retrieval_results)
def _reason_calculation(self, task: Dict[str, Any], understanding: Dict[str, Any]) -> Dict[str, Any]:
"""计算类推理:优先使用精确计算器"""
query = task.get("query", "")
collected_data = task.get("collected_data", {})
# 提取数字
numbers = self._extract_numbers(query)
# 从表格数据中提取数字
if collected_data and "file" in collected_data:
file_data = collected_data["file"]
if file_data.get("type") == "table":
numbers.extend(self._extract_from_table(file_data, query))
# 执行计算
if numbers:
if "总和" in query or "求和" in query:
result = sum(numbers)
elif "平均" in query:
result = sum(numbers) / len(numbers)
elif "最大" in query:
result = max(numbers)
elif "最小" in query:
result = min(numbers)
else:
result = numbers[0]
# 格式化结果
if isinstance(result, float):
if result.is_integer():
result_str = str(int(result))
else:
result_str = f"{result:.2f}"
else:
result_str = str(result)
else:
result_str = "无法计算"
return {
"task_id": task.get("task_id"),
"reasoning_steps": ["提取数字", "识别运算", "执行计算"],
"final_answer": result_str,
"confidence": 0.9
}
def _extract_numbers(self, text: str) -> List[float]:
"""从文本中提取所有数字"""
import re
numbers = re.findall(r'\d+\.?\d*', text)
return [float(n) for n in numbers if n]
四、项目文件结构
项目文件结构
jd_multi_agent/
├── config/
│ └── config.py # 配置文件
├── data_collector/
│ ├── __init__.py
│ ├── multimodal_collector.py # 多模态数据采集
│ ├── web_collector.py # 网页数据采集
│ └── data_processor.py # 数据预处理
├── agents/
│ ├── __init__.py
│ ├── task_dispatcher.py # 任务分发
│ ├── understanding_agent.py # 理解Agent
│ ├── retrieval_agent.py # 检索Agent
│ ├── reasoning_agent.py # 推理Agent
│ └── execution_agent.py # 执行Agent
├── utils/
│ ├── __init__.py
│ └── helpers.py # 辅助函数
├── main.py # 主程序
├── train.py # 训练脚本
├── inference.py # 推理脚本
├── requirements.txt # 依赖包列表
└── README.md # 说明文档
五、核心算法设计
5.1 答案验证机制
点击查看代码
def validate_submission(file_path: str, expected_count: int = 200) -> bool:
"""验证提交文件格式"""
try:
results = load_jsonl(file_path)
# 检查数量
if len(results) != expected_count:
print(f"错误: 结果数量不对,期望{expected_count}个,实际{len(results)}个")
return False
# 检查格式
task_ids = set()
for i, result in enumerate(results):
if "task_id" not in result or "answer" not in result:
print(f"错误: 第{i+1}行缺少必需字段")
return False
if result["task_id"] in task_ids:
print(f"错误: task_id重复: {result['task_id']}")
return False
task_ids.add(result["task_id"])
print("提交文件验证通过!")
return True
except Exception as e:
print(f"错误: 验证失败 - {e}")
return False
六、实践过程与结果
6.1 实验设置
-
硬件环境:
- CPU: Intel Core i7-12700H
- 内存: 32GB
- 操作系统: Windows 11
-
软件环境:
- Python 3.10
- 主要依赖库:
pandas,numpy,openai,jsonlines,Pillow
-
数据设置:
- 验证集:100个任务(包含答案)
- 测试集:200个任务(不包含答案)
6.2 实践步骤
环境搭建
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install pandas numpy jsonlines Pillow requests beautifulsoup4 openpyxl PyPDF2
数据准备
python main.py
京东多智能体挑战赛实践心得
参与此次京东多智能体挑战赛,不仅是一次技术上的探索与实践,更是一个学习如何将理论知识应用于实际问题解决的过程。通过这次比赛,我们团队在多智能体系统的设计、开发及优化方面积累了宝贵的经验。
技术收获
模块化设计的重要性
在整个项目开发过程中,模块化设计成为确保代码可维护性和扩展性的关键因素之一。通过将系统划分为数据采集、任务分发、Agent协作等多个独立模块,我们不仅能够高效地进行分工合作,而且在后期的调试和优化中也极大地简化了工作量。
数据处理能力的提升
面对复杂多样的数据类型(如图像、PDF、Excel等),我们需要实现一个能够自动识别并处理这些格式的数据采集器。这不仅要求对不同格式的数据有深入的理解,还需要掌握相应的处理技巧。经过此次实践,我们在数据预处理和清洗方面的技能得到了显著提升。
多Agent系统的构建
多智能体系统的核心在于各个Agent之间的有效协作。在本项目中,我们实现了从任务分发到理解、检索、推理直至执行的一整套流程。这个过程让我们深刻体会到设计一个灵活且高效的协作机制的重要性。
遇到的问题与解决方案
多模态数据处理
由于涉及到多种数据格式的处理,最开始时遇到了数据不统一的问题。为此,我们设计了一个基于文件扩展名自动选择处理方法的统一接口,有效地解决了这个问题。
答案标准化
系统生成的答案往往包含多余的前缀或后缀,不符合提交要求。为此,我们专门开发了一个答案后处理器,用于自动清洗和标准化答案内容,确保其符合规范。
结论与展望
结论
通过本次实践,我们不仅提升了个人的技术能力,同时也增强了团队合作精神。从最初的5%准确率到最终达到78%,每一步改进都凝聚着团队成员的心血和努力。
浙公网安备 33010602011771号