微信扫码
添加专属顾问
我要投稿
港大数据智能实验室开源的DeepCode,用多智能体架构突破代码生成瓶颈,在PaperBench基准上超越人类专家表现。核心内容: 1. 7个专业智能体的分工协作架构设计 2. ParallelLLM并行处理机制的技术实现 3. 在学术论文到工程代码转化中的实际应用效果
代码仓库: https://github.com/HKUDS/DeepCode
PyPI 安装: pip install deepcode-hku
学术论文到工程代码的转化一直是研究落地的"最后一公里"难题。研究人员花费大量时间实现算法而非专注科研,产品团队在概念验证阶段陷入漫长等待。港大数据智能实验室开源的 DeepCode 试图用多智能体架构彻底解决这个问题——它不仅在 OpenAI 的 PaperBench 基准上超越人类专家(75.9% vs 72.4%),更重要的是,它提供了一套工程化的、可复现的解决方案。
DeepCode 构建了 7 个专业智能体,通过中央编排引擎实现复杂任务的分解与协作:
系统的核心亮点是 ParallelLLM 机制,让 ConceptAnalysisAgent 和 AlgorithmAnalysisAgent 并行分析同一篇论文,再由 CodePlannerAgent 整合输出:
# workflows/agent_orchestration_engine.py
concept_analysis_agent = Agent(
    name="ConceptAnalysisAgent",
    instruction=prompts["concept_analysis"],
    server_names=agent_config["concept_analysis"],
)
algorithm_analysis_agent = Agent(
    name="AlgorithmAnalysisAgent",
    instruction=prompts["algorithm_analysis"],
    server_names=agent_config["algorithm_analysis"],
)
code_planner_agent = Agent(
    name="CodePlannerAgent",
    instruction=prompts["code_planning"],
    server_names=agent_config["code_planner"],
)
# 扇出/扇入架构:并行分析 → 统一整合
code_aggregator_agent = ParallelLLM(
    fan_in_agent=code_planner_agent,
    fan_out_agents=[concept_analysis_agent, algorithm_analysis_agent],
    llm_factory=get_preferred_llm_class(),
)
这种设计兼顾了效率(并行处理)和质量(多视角分析),每个 Agent 专注于自己的领域,最终由 Planner 综合决策。
编排引擎管理 8 个处理阶段:研究分析 → 资源处理 → 工作空间构建 → 代码规划 → 参考智能分析 → 仓库获取 → 代码库索引 → 代码实现。
关键设计是自适应配置:根据文档大小和复杂度动态调整 Agent 配置。例如,大型论文触发文档分段机制,小文档则直接处理;用户可通过 enable_indexing 参数在"全功能模式"和"快速模式"间切换。
DeepCode 的内存管理采用了一种激进且巧妙的策略——基于 write_file 触发的内存优化:核心逻辑体现在 
ConciseMemoryAgent 中:
# workflows/agents/memory_agent_concise.py
def create_concise_messages(self, system_prompt, messages, files_implemented):
    """每次 write_file 后,清空历史,只保留关键信息"""
    ifnot self.last_write_file_detected:
        return messages  # 首次写文件前,保持完整历史
    
    concise_messages = []
    
    # 1. 保留初始计划消息
    initial_plan_message = {
        "role": "user",
        "content": f"""**Code Reproduction Plan:**
{self.initial_plan}
**Previously Implemented Files:**
{implemented_files_list}
**Current Status:** {files_implemented} files implemented"""
    }
    concise_messages.append(initial_plan_message)
    
    # 2. 添加知识库(最新实现文件的摘要)
    knowledge_base_message = {
        "role": "user",
        "content": f"""**Knowledge Base:**
{self._read_code_knowledge_base()}
**Development Cycle:**
1. Call read_code_mem() to understand dependencies
2. Use write_file() to implement new component
3. Execute tests if needed"""
    }
    concise_messages.append(knowledge_base_message)
    
    # 3. 添加当前轮次的工具结果(仅关键工具)
    if self.current_round_tool_results:
        concise_messages.append({
            "role": "user",
            "content": f"**Current Tool Results:**\n{tool_results}"
        })
    
    return concise_messages
这种设计实现了 70-90% 的上下文压缩率,每个新文件的实现都有一个干净的起点,避免了上下文膨胀导致的 token 溢出。
CodeRAG 通过 code-reference-indexer MCP 服务器实现代码的语义索引和智能检索:
# workflows/agents/code_implementation_agent.py
asyncdef _handle_read_file_with_memory_optimization(self, tool_call):
    """拦截 read_file 调用,优先使用摘要缓存"""
    file_path = tool_call["input"].get("file_path")
    
    # 1. 先尝试从内存读取摘要
    mem_result = await self.mcp_client.call_tool(
        "read_code_mem",
        {"file_path": file_path}
    )
    
    if"successfully"in mem_result.lower():
        # 摘要存在,直接返回(节省 token)
        return {"tool_id": tool_call["id"], "result": mem_result}
    
    # 2. 摘要不存在,执行原始文件读取
    original_result = await self.mcp_client.call_tool(
        "read_file", 
        tool_call["input"]
    )
    return {"tool_id": tool_call["id"], "result": original_result}
CodeRAG 的价值在于按需加载:只在需要时读取完整文件,大部分情况下通过摘要即可理解代码结构和依赖关系。
DeepCode 系统性地实现了业界提出的四种上下文工程方法:
| 
Offload | 
read_code_mem | 
|
| 
Retrieve | 
search_reference_code | 
|
| 
Reduce | 
||
| 
Isolate | 
这四种方法的协同效果:
在 OpenAI 的 PaperBench 基准测试上,DeepCode 创造了多项新纪录:
这些数据背后的关键不是模型能力(大家都用 Claude 3.5 Sonnet 或 GPT-4),而是架构设计:
DeepCode 的设计体现了明确的工程权衡:
优势:
劣势:
系统通过两种运行模式平衡速度和质量:
DeepCode 的价值不仅在于"能把论文变成代码",更在于它提供了一套可复现的多智能体架构范式:
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-11-04
百灵大模型 Ling 和 Ring 系列首发支持 SGLang-JAX 推理引擎
2025-11-04
首个国产开源AI原生后端,不再写后端,AI就是全栈工程师。
2025-11-04
AI Infra:POINTS-Reader,腾讯开源的文档解析和OCR工具
2025-11-03
震惊,Github开源,真正让程序员效率提升 90%的AI辅助工具来啦!!!
2025-11-03
Dify迎来最强开源对手!这个本地Agent内置微调+超细权限控制~
2025-11-03
我们大胆做了个决定,大会所有音乐bgm由AI生成,这部分预算可以省了!|Jinqiu Scan
2025-11-03
LongCat-Flash-Omni 正式发布并开源:开启全模态实时交互时代
2025-11-03
科大讯飞“王炸”开源!企业级智能体平台 Astron Agent:原生集成 RPA,Apache 2.0 商业友好!
            2025-08-20
2025-09-07
2025-08-20
2025-08-26
2025-08-22
2025-09-06
2025-10-20
2025-08-22
2025-09-08
2025-08-12
2025-11-03
2025-10-29
2025-10-28
2025-10-13
2025-09-29
2025-09-17
2025-09-09
2025-09-08