一、融合架构全景图
✅ 核心创新:RAG 不再是终点,而是 Agent 的'外部记忆';Agent 不再盲目调用,而是基于知识做决策。
1. 与传统架构对比
| 架构 | 能力 | 局限 |
|---|---|---|
| RAG Only | 回答静态问题 | 无法执行操作 |
| Agent Only | 执行工具调用 | 参数靠猜,易出错 |
| RAG + Agent (串行) | 先查知识,再调工具 | 无法动态调整 |
| RAG-Augmented Agent (本文) | 边思考边检索,动态决策 | ✅ 最佳实践 |
💡 关键区别:检索嵌入在推理循环中,而非前置步骤。
二、核心组件设计
2.1 感知层:动态知识检索器
目标:在 Agent 每一步思考时,按需检索相关知识。
实现:ReAct + RAG 循环
# rag_augmented_agent.py
def react_with_rag(question: str):
for step in range(max_steps):
# 1. 当前上下文 = 用户问题 + 历史动作 + 检索结果
context = build_context(question, history, retrieved_docs)
# 2. LLM 决策:继续思考?调用工具?还是回答?
action = llm_decide(context)
if action.type == "RETRIEVE":
# 3. 动态检索(基于当前思考)
query = action.query # e.g., "张三的部门和职级"
docs = vector_db.search(query, top_k=3)
retrieved_docs.extend(docs)
elif action.type == "USE_TOOL":
tool_args = fill_args_from_docs(action.tool, docs)
result = execute_tool(action.tool, tool_args)
history.append(result)
action. == :
action.answer


