AI Agent 学习笔记
AI Agent 学习笔记
Planning
任务拆解 + 顺序决策 + 结果再调整。
最常用的是 ReAct 模式:reason + action
Memory
短期记忆:prompt 中携带
长期记忆:向量数据库
Context
在有限 token 内,把“最有用的信息”动态塞进 Prompt
解决办法:
- 滑动窗口
- 总结压缩历史对话
Context VS Memory
| 概念 | 定义 | 特点 | 示例 |
|---|---|---|---|
| 上下文(Context) | 当前任务或对话中的即时信息,用于理解和生成下一步动作 | 短期、临时、仅在当前执行或会话有效 | 对话中最近几轮消息,当前任务状态,环境信息 |
| 记忆(Memory) | Agent 历史交互或知识的长期存储,用于跨任务或跨会话引用 | 长期、可持续、可检索 | 用户偏好、历史操作记录、外部文档存储 |
什么是 AI Agent
利用 LLM 能力,结合 Tools,Memory,Planning ,自动执行复杂任务。
Agent 和 LLM 区别
LLM 只负责内容生成,Agent 可以执行任务
执行流程:
- Thought(思考)
- Action(调用工具)
- Observation(观察结果)
- Loop(循环)
Function Calling 是什么
LLM 输出结构化参数,调用Tools
Agent 为什么需要 Memory
减少幻觉
短期记忆:对话上下文
长期记忆:向量数据库(RAG)
Agent 核心架构
1
2
3
4
5
6
7
8
9
10
11
User Input
↓
Planner(规划)
↓
LLM(决策)
↓
Tool Executor(执行)
↓
Memory(更新)
↓
Loop
如何降低 Agent 幻觉
- RAG,回答引入原文档
- Tool Calling
- 结构化 json schema输出
- 调参数,换模型
- 设计 prompt,增加约束条件
设计一个 Agent 系统
接入层:
- API/Chat UI
Core 层:
- Planner
- Executor
- Memory
Tools 层:
- 外部 api
- Db
存储层:
- 向量数据库
可观测性:
- trace
- log
Agent 如何评估
- benchmark
- 测试用例
- 在线用户反馈
- 模型评估模型
多agent 如何编排
1 、中心化编排
1
2
3
Orchestrator Agent
/ | \
Agent A Agent B Agent C
2 、工作流/DAG 编排
主流框架:LangGraph
1
Start → Agent A → Agent B → Agent C → End
This post is licensed under CC BY 4.0 by the author.
