等级如下:
-
等级 1:具备工具和指令的智能体
-
等级 2:具备知识和记忆的智能体
-
等级 3:具备长期记忆和推理能力的智能体
-
等级 4:多智能体团队
-
等级 5:智能体系统
接下来,我们开始深入探讨。
等级 1:具备工具和指令的智能体
这是基础设置 —— 一个遵循指令并在循环中调用工具的大语言模型(LLM)。当人们说 “智能体不过是大语言模型加上工具使用” 时,他们指的就是这个等级,这也说明了他们此时的探索深度有限。
指令告诉智能体该做什么,工具使其能够采取行动 —— 获取数据、调用 API 或触发工作流。它虽然简单,但已足够强大到能自动化完成一些任务。
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
agno_assist = Agent(
name="Agno AGI",
model=OpenAIChat(id="gpt-4.1"),
description=dedent("""\
You are "Agno AGI, an autonomous AI Agent that can build agents using the Agno
framework. Your goal is to help developers understand and use Agno by providing
explanations, working code examples, and optional visual and audio explanations
of key concepts."""),
instructions="Search the web for information about Agno.",
tools=[DuckDuckGoTools()],
add_datetime_to_instructions=True,
markdown=True,
)
agno_assist.print_response("What is Agno?", stream=True)
等级 2:具备知识和记忆的智能体
大多数任务需要模型本身不具备的信息。你无法将所有内容都塞进上下文里,因此智能体需要一种在运行时获取知识的方式 —— 这就是智能体检索增强生成(RAG)或动态少样本提示发挥作用的地方。
搜索应采用混合方式(全文搜索 + 语义搜索),同时重排序也必不可少。混合搜索与重排序结合,是智能体检索场景下最佳的即插即用设置。
而存储赋予了智能体记忆能力。大语言模型默认是无状态的,存储过往行动、消息和观察结果能让智能体拥有状态 ,也就是能够参考到目前为止发生的事情,并做出更优决策。
... imports
# You can also use https://docs.agno.com/llms-full.txt for the full documentation
knowledge_base = UrlKnowledge(
urls=["https://docs.agno.com/introduction.md"],
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="agno_docs",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
reranker=CohereReranker(model="rerank-multilingual-v3.0"),
),
)
storage = SqliteStorage(table_name="agent_sessions", db_file="tmp/agent.db")
agno_assist = Agent(
name="Agno AGI",
model=OpenAIChat(id="gpt-4.1"),
description=...,
instructions=...,
tools=[PythonTools(), DuckDuckGoTools()],
add_datetime_to_instructions=True,
# 当向智能体提供'knowledge'时,智能体检索增强生成(RAG)功能默认启用
knowledge=knowledge_base,
# 将智能体会话存储在SQLite数据库中
storage=storage,
# 将聊天历史添加到消息中
add_history_to_messages=True,
# 历史运行次数
num_history_runs=3,
markdown=True,
)
if __name__ == "__main__":
# 加载知识库,首次运行后注释
# agno_assist.knowledge.load(recreate=True)
agno_assist.print_response("What is Agno?", stream=True)
等级 3:具备长期记忆与推理能力的智能体
记忆能力使智能体能够跨会话回忆细节(如用户偏好、过往操作或失败尝试)并随时间不断进化,从而实现个性化与连贯性。这一领域目前仍处于早期探索阶段,但最令人兴奋的是自学习能力:智能体基于历史经验优化自身行为。
而推理能力则更进一步:它帮助智能体拆解复杂问题、做出更优决策,并更可靠地执行多步骤指令。这不仅关乎理解能力,更在于提升每一步骤的成功率。任何严谨的智能体开发者都必须掌握何时以及如何应用推理能力。
... imports
knowledge_base = ...
memory = Memory(
# 使用任何模型创建记忆
model=OpenAIChat(id="gpt-4.1"),
db=SqliteMemoryDb(table_name="user_memories", db_file="tmp/agent.db"),
delete_memories=True,
clear_memories=True,
)
storage = ...
agno_assist = Agent(
name="Agno AGI",
model=Claude(id="claude-3-7-sonnet-latest"),
# 用户记忆标识
user_id="ava",
description=...,
instructions=...,
# 赋予智能体推理能力
tools=[PythonTools(), DuckDuckGoTools(), ReasoningTools(add_instructions=True)],
...
# 将记忆存储在SQLite数据库中
memory=memory,
# 允许智能体自主管理记忆
enable_agentic_memory=True,
)
if __name__ == "__main__":
# 首次运行后可注释掉,智能体将记住对话
agno_assist.print_response("Always start your messages with 'hi ava'", stream=True)
agno_assist.print_response("What is Agno?", stream=True)
等级 4:多智能体团队
智能体在专注特定领域时最为高效 —— 通过精简工具集(理想情况不超过 10 个工具)专精于单一领域。为应对更复杂或广泛的任务,可以将多个智能体组合成团队,每个智能体处理问题的一部分,共同完成更宏大的目标。
但这种情况存在一个关键挑战:若缺乏强大的推理能力,团队“领导者”在处理哪怕细微任务时都会崩溃。根据观察,目前自主多智能体系统的可靠性仍不理想,成功率不足 50%,这远远不够。
尽管如此,某些架构设计仍可简化协作难度。例如,Agno 框架支持三种执行模式(协调、路由和协作),并内置记忆与上下文管理功能。虽然仍需精心设计,但这些基础组件使构建严谨的多智能体系统成为可能。
... imports
web_agent = Agent(
name="Web Search Agent",
role="Handle web search requests",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[DuckDuckGoTools()],
instructions="Always include sources",
)
finance_agent = Agent(
name="Finance Agent",
role="Handle financial data requests",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[YFinanceTools()],
instructions=[
"You are a financial data specialist. Provide concise and accurate data.",
"Use tables to display stock prices, fundamentals (P/E, Market Cap)",
],
)
team_leader = Team(
name="Reasoning Finance Team Leader",
mode="coordinate",
model=Claude(id="claude-3-7-sonnet-latest"),
members=[web_agent, finance_agent],
tools=[ReasoningTools(add_instructions=True)],
instructions=[
"Use tables to display data",
"Only output the final answer, no other text.",
],
show_members_responses=True,
enable_agentic_context=True,
add_datetime_to_instructions=True,
success_criteria="The team has successfully completed the task.",
)
if __name__ == "__main__":
team_leader.print_response(
"""\
Analyze the impact of recent US tariffs on market performance across
these key sectors:
- Steel & Aluminum: (X, NUE, AA)
- Technology Hardware: (AAPL, DELL, HPQ)
For each sector:
1. Compare stock performance before and after tariff implementation
2. Identify supply chain disruptions and cost impact percentages
3. Analyze companies' strategic responses (reshoring, price adjustments, supplier
diversification)""",
stream=True,
stream_intermediate_steps=True,
show_full_reasoning=True,
)
等级 5:智能体系统
此时智能体已从工具升级为基础设施。智能体系统是完整的 API—— 这类系统接收用户请求后,会启动异步工作流,并在结果生成时通过实时流式返回。
理论上听起来简洁,但实际实现极其困难。这需要在请求进入时持久化状态、启动后台任务、跟踪进度,并在输出生成时进行流式传输。WebSocket 可以提供帮助,但扩展和维护起来非常棘手。大多数团队都低估了后端在此层面的复杂性。
这正是将智能体转化为真正产品的关键。在这一阶段构建的不再是功能,而是一个系统。
从演示失败到实际成功:智能体设计的核心经验
构建 AI 智能体并非追逐热点或堆叠功能,而是要夯实基础。从基础工具使用到完全异步的智能体系统,每个层级只有在底层架构稳健时,才能真正释放潜力。
多数失败并非因为未采用最新框架,而是忽视了基本原则:清晰的边界定义、可靠的推理能力、高效的记忆机制,以及明确何时让人类接管。