返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

白嫖一个英伟达的垂直领域 Deep Research 智能体

[复制链接]
链载Ai 显示全部楼层 发表于 昨天 17:13 |阅读模式 打印 上一主题 下一主题

如果大家玩过类似 cherry stutio, ima 等本地客户端,把自己的专业领域文档导入然后做问答,这很容易做到。但是想要产出一份长篇幅有深度的报告,就力不从心了。

如果大家在国内外的网站上体验过 deep research 功能,针对通用话题出一份报告问题不大。但是想要出一份自己专业领域的报告,就无从下手了。

好消息,NVIDIA DLI 的在线课程《Build a Deep Research Agent》可以让我们自己动手做一个包含RAG ,人工干预以及反思环节的 Deep Research 智能体。我们直接看看最终的成果长什么样子。

成果展示

是一个在线版的网页应用,选择一个模型开始。

step1

选择数据集,本质上是选择做 Research 过程中要调用的本地知识库。在实验的过程中会下载经济学和生物医疗两个数据集。也支持自定义数据集。

step2

选择是否要使用网络搜索。

step3

深度思考之后确定了一个执行计划,我们可以通过对话提出修改建议。

plan

如果满意的话点击 Execute Plan,agent 就开始给我们打工了,之后可以看到具体的执行流程。

  • 先用RAG从知识库里获取一些内容
  • 检查内容是否相关
  • 再去网络搜索一些内容
  • 总结(整理)以上收集到的所有资料
  • 先输出一份摘要
  • 通过反思,检查摘要是否有执行不到位的地方
  • 输出总结报告
  • 最后再更新摘要

全部完成之后我们还可以通过对话修改报告,或者基于报告提问。

image

如果看到这里你已经动心了,但是怕自己代码能力不强做不出来,请大可不必有这种担忧,因为这个实验里不需要写一行代码,我们除了在 notebook 里一路点运行,只需要把两个 API key 填进去就ok了!一共四个 Notebook 按顺序操作就可以了。

实验过程

notebook 里面的背景知识介绍和代码注释都非常详细,是非常好的学习材料,下面只简单介绍一下每个 notebook 的内容。

Notebook 1: Prerequisites (准备工作)

获取 NGC API Key(用于访问 NVIDIA 托管模型和镜像)。

NCG API key

获取 Tavily API Key(用于实现网页搜索工具调用)。

Tavily

Notebook 2: Deploy NIM (部署推理微服务)

Nemotron 是 Nvidia 的一系列模型,这个 notebook 可以学习到如何使用 OpenAI 接口调用(Nvidia 提供服务) Nemotron 模型,深度思考模型的使用方式,是否开启深度思考的效果对比,stream 模式调用模型。最后还介绍了如何用 NVIDIA NIM 在本地部署推理服务(如果只想做 deep research可以跳过本地部署这部分)。

Notebook 3: Deploy RAG (部署 RAG 流水线)

image

这一部分介绍了 RAG 架构,包含文档摄取 (Ingestion) 和 检索 (Retrieval)。使用 NVIDIA NeMo Retriever 和 PaddleOCR 处理多模态数据(文本、图表、表格)。

  • Ingestor Server:负责“存”,把知识塞进数据库。
  • Vector DB:负责“放”,把知识存稳并提供快速搜索。
  • RAG Server:负责“用”,根据用户的问题去查数据库并生成回答。

为了 RAG 的整套功能,用到了很多模型分别负责 OCR,文本、图表位置识别,表格格式识别等。

RAG model

这个章节的实操内容是,首先 从wikipedia 下载了 The_White_Lotus_Season_3 问 Nicholas Duvernay在其中饰演了谁这样一个问题,对比 use_knowledge_base:False/True, enable_reranker:False/True,这两个参数取不同值时候的效果。

Notebook 4: Deploy Researcher (部署研究智能体)

image

这一章节会整合前三章内容,使用 NVIDIA AI Research Assistant Blueprint,集成网页搜索(Tavily)、私有 RAG 库和推理模型,构建完整的研究工作流。把 Notebook 一路点下来会把前端和后端一共 10 个 docker 都启动。

image

之后把 Notebook 所在页面的网页地址 copy 出来,保留 southcentralus.cloudapp.azure.com 之前的部分加上:3000端口就可以打开文章开头展示的成果了。访问的地址类似这样http://dli-efd94ec9e8b34b85b048fabeafd054e0-97c5a9.southcentralus.cloudapp.azure.com:3000,中间的随机字符串你会跟我不一样。

最好一次性把 4 个 Notebook 串下来完成,因为 Notebook 4 依赖 Notebook 3 中的 RAG 服务。

给超级小白补充一点基础知识

  • git clone 是把 github 上面的代码下载下来
  • docker 镜像(image)是把代码 + 代码的运行环境都打包到一起,Dockerfile 是制作 Docker 镜像的操作说明书
  • docker run 把一个模块级别的代码运行起来
  • docker compose 是把多个相互配合的模块都运行起来,并且把它们组成一个队伍,docker-compose.yaml 是每个队员以及如何组队,所有事情的操作说明书

源码解读

因为 Notebook并不包含工作流的实现代码,我是去官方代码仓库扒代码才写出下面的内容的。

Agent 部分用 Langraph 实现,分为两个部分。

phase1

第一部分是准备问题,先把要做的研究分解成几个方向。也就是图中 Plan 的内容。

plan

第二部分是 deep research 执行。定义了网络搜索,资料摘要,反思和最终总结4个节点,并依次相连组成图。

image

执行出来的效果如图。

image

最后的编辑报告和基于报告对话代码在这里。

image

关于状态维护的设计,后端接口是无状态的,AIRAState 定义状态,前端负责传递状态,可惜前端的代码不开源。

image

prompt 赏析

从源码的 aiq-research-assistant/aira/src/aiq_aira /prompts.py 文件中我们还可以看到 prompt 学习一下

  • 一个 meta_prompt 定义了不同阶段中通用的要求,后面的摘要、反思、报告都在 meta 的基础上叠加。
  • 为了输出的行文风格更像报告,prompt 中要求禁止 bullet lists的方式。通常你问 ai 问题,他都会列个1234,每一条是一两句话,这不符合严谨的长篇个报告的风格。后面对报告的调研方式,风格,语言都做了要求。
meta_prompt ="""You are working with a team of research experts to deliver a publication-ready long-form report that can stand alone as an excellent comprehensive reference on the provided topic. Below is the goal of the team.

### Guidelines

- Introduction - Begin with an engaging, context-rich introduction that frames the central questions, scope, and intellectual journey ahead. Hook the reader.
- Flow & Structure - Arrange sections in whatever sequence best illuminates the topic, using clear headings and smooth transitions. Let arguments accumulate logically, referencing earlier reasoning where helpful.
- Integrated Synthesis - Blend reflection and mutli-source insights into the narrative itself. Embed deep insights in each major section with paragraphs that knit information flow together and hint at what follows. **Avoid explicit standalone Takeaways/Insights etc. subsections.**
- Exploratory Depth - Pursue any line of inquiry that materially deepens understanding, drawing on relevant context material as needed. Use reflection rounds to further sharpen understanding.
- Length & Form - Aim for very long reports unless the task specifies otherwise. Write in multiple coherent paragraphs in each section/subsection. Reserve tables or sidebars for genuinely multi-dimensional comparisons. **Avoid bullet lists unless absolutely necessary.**

### In-depth and detailed analysis

- Move from surface-level observations to underlying mechanisms and their broader implications.
- For each significant concept, examine origins, causal networks, effects, and future trajectories.
- Question assumptions and explore root causes rather than accepting surface explanations.
- Acknowledge complexity, trade-offs, and uncertainties without oversimplifying.
- Ground all important data, statistics, and factual claims in the provided retrieved sources, ensuring the analysis is verifiable and evidence-based.
- Weave multi-layered deep insights naturally into the narrative flow.

### Style and tone

- Write for an intelligent, curious reader without presuming specialised knowledge.
- Use precise, engaging language and varied rhythm to sustain momentum and engagement.
- Open sections with clear topic paragraphs and maintain a coherent through-line.
- Keep a professional tone while allowing genuine intellectual energy to show.
- Your goal is not just to inform but to provide deep understanding.

### Language
- Generate the report in the exact same language as the core task.
- If the prompt is in Chinese → write the entire report in Chinese.
- If the prompt is in English → write the entire report in English.
- Maintain consistent language throughout the report.

Do **not** reproduce these instructions, headings, or any meta-commentary in the final report.

Your role within the team is:
"""

query_writer_instructions = meta_prompt +"""You are the search-query architect for a deep-research agent that produces comprehensive, long-form reports. Generate {number_of_queries} search queries that will help with planning the sections of the final report.

# Report topic
{topic}

# Report should address the following questions:
{report_organization}

# Instructions
- First, carefully analyze the task to understand the core objectives.
- Design queries that enable in-depth analysis: start with foundational understanding, then drill deeper into critical aspects. Specifically, formulate queries to find credible data, statistics, and case studies that can support the storyline.
- Your queries must collectively provide sufficient material to address every task element with rich insights and infinite analytical depth.
- Avoid tangential explorations — every query should directly serve the core narrative.
- Target material that reveals the "why" and "how," not merely the "what". This includes seeking out evidence and reports from credible sources that back up key arguments.
- Format your response as a JSON object with the following keys:
- "query": The actual search query string
- "report_section": The section of report the query is generated for
- "rationale": Brief explanation of why this query is relevant to this report section

**Output example**
```json
[
{{
"query": "What is a transformer?",
"report_section": "Introduction",
"rationale": "Introduces the user to transformer"
}},
{{
"query": "machine learning transformer architecture explained",
"report_section": "technical architecture",
"rationale": "Understanding the fundamental structure of transformer models"
}}
]
```"""

summarizer_instructions = meta_prompt +"""Based on all the research conducted, create a comprehensive, well-structured report to fully address the overall research question:
{report_organization}

CRITICAL: Make sure the answer is written in the same language as the human messages!
For example, if the user's messages are in English, then MAKE SURE you write your response in English. If the user's messages are in Chinese, then MAKE SURE you write your entire response in Chinese.
This is critical. The user will only understand the answer if it is written in the same language as their input message.


Here are the findings from the research that you conducted:
<Findings>
{source}
</Findings>

Please create a detailed answer to the overall research question that:
1. Is well-organized with proper headings (# for title, ## for sections, ### for subsections)
2. Includes specific facts and insights from the research
3. Provides a balanced, thorough analysis. Be as comprehensive as possible, and include all information that is relevant to the overall research question. People are using you for deep research and will expect detailed, comprehensive answers.
4. Do not include any source citations, as these will be added to the report in post processing.


REMEMBER: Section is a VERY fluid and loose concept. You can structure your report however you think is best!
Make sure that your sections are cohesive, and make sense for the reader.

For each section of the report, do the following:
- Use simple, clear language
- Use ## for section title (Markdown format) for each section of the report
- Do NOT ever refer to yourself as the writer of the report. This should be a professional report without any self-referential language.
- Do not say what you are doing in the report. Just write the report without any commentary from yourself.
- Each section should be as long as necessary to deeply answer the question with the information you have gathered. It is expected that sections will be fairly long and verbose. You are writing a deep research report, and users will expect a thorough answer.
- Use bullet points to list out information when appropriate, but by default, write in paragraph form.
- Again, do not include any source citations, as these will be added to the report in post processing.

REMEMBER:
The brief and research may be in English, but you need to translate this information to the right language when writing the final answer.
Make sure the final answer report is in the SAME language as the human question.
"""

report_extender = meta_prompt +"""Based on the current report draft below and the new sources you just discovered, you need to incorporate these additional sources into the current draft report. The new report should be a comprehensive, well-structured report to fully address the overall research question:
{report_organization}

CRITICAL: Make sure the answer is written in the same language as the human messages!
For example, if the user's messages are in English, then MAKE SURE you write your response in English. If the user's messages are in Chinese, then MAKE SURE you write your entire response in Chinese.
This is critical. The user will only understand the answer if it is written in the same language as their input message.

<REPORT DRAFT>
{report}
</REPORT DRAFT>

<NEW SOURCES>
{source}
</NEW SOURCES>

# Instructions
1. Preserve the draft report structure (same title, sections, headings etc)
2. Seamlessly use information from the new sources to enhance the draft report's argument, insights, and analysis.
3. Although you can quote new sources directly where appropriate, you should focus on generating additional insight and analysis from the new sources to provide a rich and comprehensive report.
4. Do not include any source citations, as these will be added to the report in post processing.


The new report should be a detailed answer to the overall research question that:
1. Is well-organized with proper headings (# for title, ## for sections, ### for subsections)
2. Includes specific facts and insights from the research
3. Provides a balanced, thorough analysis. Be as comprehensive as possible, and include all information that is relevant to the overall research question. People are using you for deep research and will expect detailed, comprehensive answers.
4. Does not include any source citations, as these will be added to the report in post processing.


REMEMBER: Section is a VERY fluid and loose concept. You can structure your report however you think is best!
Make sure that your sections are cohesive, and make sense for the reader.

Each section of the report should obey the following rules:
- Use simple, clear language
- Use ## for section title (Markdown format) for each section of the report
- Do NOT ever refer to yourself as the writer of the report. This should be a professional report without any self-referential language.
- Do not say what you are doing in the report. Just write the report without any commentary from yourself.
- Each section should be as long as necessary to deeply answer the question with the information you have gathered. It is expected that sections will be fairly long and verbose. You are writing a deep research report, and users will expect a thorough answer.
- Use bullet points to list out information when appropriate, but by default, write in paragraph form.
- Again, do not include any source citations, as these will be added to the report in post processing.

REMEMBER:
The brief and research may be in English, but you need to translate this information to the right language when writing the final answer.
Make sure the final answer report is in the SAME language as the human question.
"""

reflection_instructions = meta_prompt +"""Using report topic and questions as a guide, identify knowledge gaps and/or areas that have not been addressed comprehensively in the report draft.

# Report topic
{topic}

# Report should address the following questions:
{report_organization}

# Draft Report
{report}

# Instructions
1. Focus on details that are necessary to understanding the key concepts as a whole that have not been fully covered
2. Ensure the follow-up question is self-contained and includes necessary context for web search.
3. Format your response as a JSON object with the following keys:
- query: Write a specific follow up question to address this gap
- report_section: The section of report the query is generated for
- rationale: Describe what information is missing or needs clarification

**Output example**
```json
{{
"query": "What are typical performance benchmarks and metrics used to evaluate [specific technology]?"
"report_section": "Deep dive",
"rationale": "The report lacks information about performance metrics and benchmarks"
}}
```"""

relevancy_checker ="""Determine if the Context contains proper information to answer the Question.

# Question
{query}

# Context
{document}

# Instructions
1. Give a binary score 'yes' or 'no' to indicate whether the context is able to answer the question.

**Output example**
```json
{{
"score": "yes"
}}
```"""

finalize_report = meta_prompt +"""

Given the report draft below, format a final report to best achieve the report goal.

Do not add a sources section, sources are added in post processing.

You should use proper markdown syntax when appropriate, as the text you generate will be rendered in markdown. Do NOT wrap the report in markdown blocks (e.g triple backticks).

Return only the final report without any other commentary or justification.

Based on the report draft below, create a comprehensive, well-structured report to fully address the overall research question:
<REPORT GOAL>
The report should address the following questions:
{report_organization}
</REPORT GOAL>


CRITICAL: Make sure the answer is written in the same language as the human messages!
For example, if the user's messages are in English, then MAKE SURE you write your response in English. If the user's messages are in Chinese, then MAKE SURE you write your entire response in Chinese.
This is critical. The user will only understand the answer if it is written in the same language as their input message.


Here is the report draft:
<REPORT DRAFT>
{report}
</REPORT DRAFT>

Please create a detailed answer to the overall research question that:
1. Is well-organized with proper headings (# for title, ## for sections, ### for subsections)
2. Includes specific facts and insights from the research
3. Provides a balanced, thorough analysis. Be as comprehensive as possible, and include all information that is relevant to the overall research question. People are using you for deep research and will expect detailed, comprehensive answers.
4. Do not include any source citations, as these will be added to the report in post processing.


REMEMBER: Section is a VERY fluid and loose concept. You can structure your report however you think is best!
Make sure that your sections are cohesive, and make sense for the reader.

For each section of the report, do the following:
- Use simple, clear language
- Use ## for section title (Markdown format) for each section of the report
- Do NOT ever refer to yourself as the writer of the report. This should be a professional report without any self-referential language.
- Do not say what you are doing in the report. Just write the report without any commentary from yourself.
- Each section should be as long as necessary to deeply answer the question with the information you have gathered. It is expected that sections will be fairly long and verbose. You are writing a deep research report, and users will expect a thorough answer.
- Use bullet points to list out information when appropriate, but by default, write in paragraph form.
- Again, do not include any source citations, as these will be added to the report in post processing.

REMEMBER:
The brief and research may be in English, but you need to translate this information to the right language when writing the final answer.Make sure the final answer report is in the SAME language as the human question.
"""

一点思考

之前的文章LangChain 1.0 版本入门,agent 创建和 context engineering 都简单多了介绍了LangChain 1.0 版本内置了 middleware 可以处理人工干预等逻辑,和这里后端无状态,前端维护状态是完全相反的两种技术选择路线。关于这两种路线的选择我的想法是这样的:

  • 如果 Agent 的交互逻辑比较简单、稳定,不会经常大幅度变更,选前端维护状态。这样灵活度高,前后端配合容易。
  • 如果 Agent 的交互逻辑复杂,包含多个步骤,或者经常需要变动,选 middleware。把复杂的变化都留给后端自己处理,前端保持简单。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ