← 返回总览

Agno (Phidata)

🔬 DEEP
🧩 Agent Frameworks Python ⭐ 18k+ | GitHub → | 更新于 2026-05-17 18:39
LightweightMulti-ModalFast文化知识系统Agentic Memory

🏗️ 核心架构

前身为 Phidata,轻量高性能 Agent 框架。核心设计理念:一切可配置、一切可插拔。Agent 类是唯一入口,通过组合模式组装 Memory、Knowledge、Tools 等能力。

代码组织从单一 agno/agent/agent.py(1735 行)拆分出专门模块:

agno/agent/
  ├── agent.py        → Agent 主类(1700+ 行)
  ├── _messages.py    → 系统/用户消息构建
  ├── _utils.py       → 辅助函数
  └── _init.py        → Manager 初始化

📝 提示词工程(源码级分析)

Agno 拥有所有框架中最复杂的系统提示词构建管线——get_system_message() 函数超过 200 行,按 17 个有序步骤组装:

System Prompt 组装流程

1. description        → Agent 描述
2. role               → <your_role>{role}</your_role>
3. instructions       → <instructions> 或纯列表
4. additional_information → markdown / datetime / location / name
5. _tool_instructions → 工具使用指引
6. resolve_in_context → {variable} 模板替换
7. expected_output    → <expected_output>
8. additional_context → 自定义上下文
9. skills             → Skill 系统提示片段
10. memories          → <memories_from_previous_interactions>
    + enable_agentic_memory → update_user_memory 工具指引
11. cultural_knowledge → <cultural_knowledge> 文化知识
    + enable_agentic_culture → create_or_update_cultural_knowledge 工具指引
12. session_summary   → <summary_of_previous_interactions>
13. learnings         → 学习结果注入
14. search_knowledge  → RAG 搜索指令
15. model system msg  → 模型特定提示
16. JSON output prompt → 结构化输出指引
17. session_state     → <session_state> 完整状态

变量模板系统

format_message_with_state_variables(){var_name} 替换为 session_state / dependencies / metadata / user_id,使用 Python string.Template.safe_substitute() 避免缺失变量报错。

Cultural Knowledge(独有特性)

<cultural_knowledge>
---
Name: {name}
Summary: {summary}
Content: {content}
</cultural_knowledge>

文化知识系统实现跨 Agent/跨 Session 的共享经验——类似于组织知识库,但由 Agent 自主贡献和更新。

Agentic Memory 提示词

<updating_user_memories>
- You have access to the `update_user_memory` tool
- If the user's message includes information that should be
  captured as a memory, use the `update_user_memory` tool
- Memories should include details that could personalize
  ongoing interactions with the user.
</updating_user_memories>

♻️ 主循环

Agent.run()
  → get_system_message()      → 构建 17 步系统提示词
  → get_user_message()        → 构建用户消息(含知识检索)
  → model.response()          → LLM 调用
  → (tool_calls → execute → LLM call)*  → 工具循环
  → response
  → (save memories / update learnings)

🔧 工具系统

🧠 记忆系统

🆕 独特特性

🔑 核心类

AgentAgentMemoryToolkitKnowledgeBaseSessionCultureManagerMemoryManagerSkill

📂 关键文件

💡 洞察:Agno 的 17 步系统提示词管线是双刃剑——功能最全面但也是所有框架中最不透明的。Cultural Knowledge 是创新亮点,但提示词膨胀风险高(memories + cultural_knowledge + session_summary + learnings + search_knowledge 可能同时注入)。相比之下,Google ADK 的 Processor Pipeline 更干净,PydanticAI 的装饰器模式更简洁。
自动研究系统生成 · 源码级深度分析 · 2026-05-17 18:39