中文内容
消费级 AI 虽然提供了强大的能力,但工作场景中的工具往往受困于数据割裂和上下文有限。基于 LangChain 构建的 NVIDIA AI-Q 蓝图是一个开源模板,用于弥合这一差距。LangChain 最近推出了一个基于 NVIDIA AI 构建的企业智能体平台,以支持可扩展、可投入生产的智能体开发。
本教程以 NVIDIA launchable 的形式提供,向开发者展示如何使用 AI-Q 蓝图创建一个在排行榜中名列前茅、并可连接到企业系统的深度研究智能体。该蓝图利用开放模型和前沿 LLM 的优势,并通过 NVIDIA NeMo Agent Toolkit 进行优化,使用 LangSmith 进行监控。其结果是:让智能体搜索应用更快进入生产,同时确保业务数据留在其应在的位置——私有且安全的环境中。
NVIDIA AI-Q 蓝图和 NeMo Agent Toolkit 都属于更广泛的 NVIDIA Agent Toolkit,这是一个用于构建、评估和优化安全、长时间运行的自主智能体的工具、模型和运行时集合。
你将构建的内容:一个深度智能体
你将学习:
- 如何将 NVIDIA AI‑Q 蓝图与 LangChain 一起部署,用于企业搜索场景
- 如何使用 Nemotron 和前沿 LLM 配置浅层与深度研究智能体
- 如何使用 LangSmith 和 NVIDIA 工具监控智能体轨迹与性能
- 如何通过 NeMo Agent Toolkit 工具连接企业内部数据源
设置
- NVIDIA API Key,用于访问 Nemotron 3 等开放模型
- OpenAI API Key,用于访问 GPT-5.2 等前沿模型
- Tavily API Key,用于网页搜索
- 正文:Python
- 正文:Docker Compose
- 可选:LangSmith,用于监控和实验跟踪
如何使用 NVIDIA 和 LangChain 构建长时间运行的数据智能体
安装并运行蓝图
克隆仓库并配置你的 API Key。先复制环境模板。
cp deploy/.env.example deploy/.env
打开 deploy/.env,并填写所需值。
# Required NVIDIA_API_KEY=nvapi-... TAVILY_API_KEY=tvly-... # Optional: enables trace monitoring (covered later in this post) LANGSMITH_API_KEY=lsv2-...
NVIDIA_API_KEY 授权访问 NVIDIA 托管的模型,例如 Nemotron 3 Nano。TAVILY_API_KEY 用于启用网页搜索。
接下来,构建并启动完整技术栈。一次启动多个容器意味着首次构建可能需要几分钟,具体取决于你的互联网连接和硬件规格。
docker compose -f deploy/compose/docker-compose.yaml up --build
这将启动三个服务:
- aiq-research-assistant:运行在 8000 端口的 FastAPI 后端
- postgres:PostgreSQL 16,用于异步任务状态和对话检查点
- frontend:运行在 3000 端口的 Next.js Web UI
当所有服务都报告健康后,打开 http://localhost:3000。下方图 1 展示了 AI-Q Research Assistant 聊天界面,你可以在其中输入研究查询,并实时观察智能体工作。

自定义 AI-Q:工作流、追踪和模型配置
打开 configs/config_web_docker.yml。这个单一文件控制 LLM、工具、智能体和工作流配置。
llms 部分声明命名模型。注意 enable_thinking 标志——它用于开启或关闭 Nemotron 的链式思维推理。下面的示例声明了三个承担不同角色的 LLM:
llms:
nemotron_llm_non_thinking:
_type: nim
model_name: nvidia/nemotron-3-super-120b-a12b
temperature: 0.7
max_tokens: 8192
chat_template_kwargs:
enable_thinking: false
nemotron_llm:
_type: nim
model_name: nvidia/nemotron-3-super-120b-a12b
temperature: 1.0
max_tokens: 100000
chat_template_kwargs:
enable_thinking: true
gpt-5-2:
_type: openai
model_name: 'gpt-5.2'
nemotron_llm_non_thinking 处理快速响应场景,在这些场景中,链式思维会增加延迟而无明显收益。nemotron_llm 启用 thinking 模式,并为需要多步推理的智能体提供 100K 上下文窗口。gpt-5.2 添加一个用于编排的前沿模型。
该蓝图同时包含浅层和深度研究智能体。以下配置展示了两者:
functions:
shallow_research_agent:
_type: shallow_research_agent
llm: nemotron_llm
tools:
- web_search_tool
max_llm_turns: 10
max_tool_calls: 5
deep_research_agent:
_type: deep_research_agent
orchestrator_llm: gpt-5
planner_llm: nemotron_llm
researcher_llm: nemotron_llm
max_loops: 2
tools:
- advanced_web_search_tool
浅层研究智能体运行一个有边界的工具调用循环——最多 10 轮 LLM 交互和 5 次工具调用——然后返回带引用的简明答案。像“什么是 CUDA?”这样的简单问题可在数秒内解决。深度研究智能体使用 LangChain deep agent,配有待办事项列表、文件系统和子智能体,用于生成有引用支持的长篇报告。
若要将所有推理保持在本地部署环境中,请将 orchestrator_llm 改为指向自托管模型。
监控轨迹
要监控 AI‑Q 智能体,请启用 LangSmith tracing,使每个查询都生成完整的执行轨迹,包括 LangChain 工具调用和模型使用情况。将你的 LANGSMITH_API_KEY 添加到 deploy/.env,并将 telemetry 部分添加到配置文件:
general:
telemetry:
tracing:
langsmith:
_type: langsmith
project: aiq-gtc-demo
api_key: ${LANGSMITH_API_KEY}
每个查询都会生成一条捕获完整执行路径的轨迹。

浅层研究示例查询:
What is the deepest place on earth?
深度研究示例查询:
Analyze the current 2026 scientific consensus on the deepest points on Earth, comparing the Challenger Deep in the Mariana Trench to terrestrial extremes such as the Veryovkina Cave and the Kola Superdeep Borehole. Include the latest bathymetric and geodetic measurements, an assessment of measurement uncertainties (including gravity and pressure sensor corrections), and a summary of recent deep-sea expeditions from 2020–2026 that have updated our understanding of the Hadal zone's topography and biological life.
展开轨迹以检查每个节点。对网页搜索的工具调用对调试尤其有用——你可以确切看到智能体发送了什么查询以及返回了哪些结果。除了单条轨迹,还可以使用 LangSmith 跟踪一段时间内的延迟、token 使用量和错误率,并为性能回退设置警报。
优化深度智能体
要针对你的领域调优深度研究智能体,首先检查它如何组装子智能体。深度研究智能体使用 LangChain deepagents 库中的 create_deep_agent 工厂。
from deepagents import create_deep_agent
return create_deep_agent(
model=self.llm_provider.get(LLMRole.ORCHESTRATOR),
system_prompt=orchestrator_prompt,
tools=self.tools,
subagents=self.subagents,
middleware=custom_middleware,
skills=self.skills,
).with_config({"recursion_limit": 1000})
该工厂将编排器 LLM、工具和两个子智能体连接在一起。
self.subagents = [
{
"name": "planner-agent",
"system_prompt": render_prompt_template(
self._prompts["planner"], tools=self.tools_info,
),
"tools": self.tools,
"model": self.llm_provider.get(LLMRole.PLANNER),
},
{
"name": "researcher-agent",
"system_prompt": render_prompt_template(
self._prompts["researcher"], tools=self.tools_info,
),
"tools": self.tools,
"model": self.llm_provider.get(LLMRole.RESEARCHER),
},
]
上下文管理是深度智能体工作方式的核心。规划智能体会生成一个 JSON 研究计划。研究智能体只接收该计划——不接收编排器的 thinking tokens 或规划器的内部推理。通过只传递结构化载荷,我们减少了 token 膨胀,并防止“迷失在中间”现象,即 LLM 忘记埋在巨大上下文窗口深处的关键指令。这种隔离让每个子智能体保持专注。以下示例展示了一个关于检索增强生成(RAG)与长上下文方法对比查询的规划器输出:
{
"report_title": "RAG vs Long-Context Models for Enterprise Search",
"report_toc": [
{
"id": "1",
"title": "Architectural Foundations",
"subsections": [
{"id": "1.1", "title": "Retrieval-Augmented Generation Pipeline"},
{"id": "1.2", "title": "Long-Context Transformer Architectures"}
]
},
{
"id": "2",
"title": "Performance and Accuracy Trade-offs",
"subsections": [
{"id": "2.1", "title": "Factual Accuracy and Hallucination Rates"},
{"id": "2.2", "title": "Latency and Throughput Benchmarks"}
]
}
],
"queries": [
{
"id": "q1",
"query": "RAG retrieval-augmented generation architecture components ...",
"target_sections": ["Architectural Foundations"],
"rationale": "Establishes baseline understanding of RAG pipelines"
}
]
}
该架构经过调优,在 Deep Research Bench 和 Deep Research Bench II 上均表现良好。
要为你的领域自定义智能体,请编辑 src/aiq_aira/agents/deep_researcher/prompts/ 中的提示模板。例如,打开 planner.j2,并指示规划器将大纲保持在三个部分或更少,以生成更聚焦的报告。你也可以添加额外的调试日志来检查中间状态(例如 /planner_output.md),以查看提示变更如何影响子智能体之间传递的上下文。
添加数据源
该蓝图将每个工具都实现为一个 NeMo Agent Toolkit 函数。要连接新的企业数据源,请实现一个 NeMo Agent Toolkit 函数,并在配置中引用它。
步骤 1:实现 NeMo Agent Toolkit 函数
以下示例连接到一个内部知识库 API:
# sources/internal_kb/src/register.py
from pydantic import Field, SecretStr
from nat.builder.builder import Builder
from nat.builder.function_info import FunctionInfo
from nat.cli.register_workflow import register_function
from nat.data_models.function import FunctionBaseConfig
class InternalKBConfig(FunctionBaseConfig, name="internal_kb"):
"""Search tool for the internal knowledge base."""
api_url: str = Field(description="Knowledge base API endpoint")
api_key: SecretStr = Field(description="Authentication key")
max_results: int = Field(default=5)
@register_function(config_type=InternalKBConfig)
async def internal_kb(config: InternalKBConfig, builder: Builder):
async def search(query: str) -> str:
"""Search the internal knowledge base for relevant documents."""
results = await call_kb_api(config.api_url, query, config.max_results)
return format_results(results)
yield FunctionInfo.from_fn(search, description=search.__doc__)
NeMo Agent Toolkit 会在启动时验证配置字段,因此错误配置会快速失败。智能体将使用该函数的 docstring 来决定何时调用该工具。
步骤 2:在配置中引用该工具
在 functions 下声明新工具,然后将其添加到每个智能体的 tools 列表中:
functions:
internal_kb_tool:
_type: internal_kb
api_url: "https://kb.internal.company.com/api/v1"
api_key: ${INTERNAL_KB_API_KEY}
max_results: 10
shallow_research_agent:
_type: shallow_research_agent
llm: nemotron_llm
tools:
- web_search_tool
- internal_kb_tool
deep_research_agent:
_type: deep_research_agent
orchestrator_llm: gpt-5
planner_llm: nemotron_llm
researcher_llm: nemotron_llm
tools:
- advanced_web_search_tool
- internal_kb_tool
你不需要更改任何智能体代码。智能体会自动发现新工具的名称和描述,LLM 会在查询匹配时调用它。可以使用相同模式接入你自己的企业系统,或利用 MCP(Model Context Protocol)让你的智能体访问现有工具。这可确保你的研究技术栈保持私有,并与对组织最重要的数据深度集成。
进一步探索
通过扩展并基于 NVIDIA AI-Q 蓝图进行构建,开发者能够把一流的 LangChain 深度智能体架构带入企业。若要进一步探索,请查看:
- 用于添加更多数据源的蓝图自定义指南
- 用于在 AI Factory 上部署的 Helm chart
- 用于开展评估驱动开发的蓝图评估指南
- LangSmith,用于在生产中监控系统并防止性能漂移
NVIDIA AI-Q Blueprint 正由整个生态系统中的合作伙伴集成,包括:Aible、Amdocs、Cloudera、Cohesity、Dell、Distyl、H2O.ai、HPE、IBM、JFrog、LangChain、ServiceNow 和 VAST。
标签






















