一、软件介绍
文末提供程序和源码下载学习
Agno 开源程序是一个轻量级库,用于构建具有内存、知识、工具和原生多模态支持的推理代理。使用 Agno 构建推理代理、多模态代理、代理团队和代理工作流。
这是一个代理,它通过推理每个步骤来编写财务报告:
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceToolsagent = Agent(model=Claude(id="claude-3-7-sonnet-latest"),tools=[ReasoningTools(add_instructions=True),YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),],instructions=["Use tables to display data","Only output the report, no other text",],markdown=True,
)
agent.print_response("Write a report on NVDA", stream=True, show_full_reasoning=True, stream_intermediate_steps=True)
reasoning_finance_agent.mp4
二、Key features 主要特点
Agno is simple, fast and model-agnostic. Here are the key features:
Agno 简单、快速且与型号无关。以下是主要功能:
- Lightning Fast: Agents instantiate 10,000x faster than LangGraph and use 50x less memory (see performance).
快如闪电 :代理实例化速度比 LangGraph 快 10,000 倍,使用的内存减少 50 倍(参见性能 )。 - Model Agnostic: Use any model, any provider, no lock-in.
模型不可知 :使用任何模型、任何提供商,无锁定。 - Reasoning Agents: Build best in class reasoning agents using Reasoning Models, Reasoning Tools or our custom
CoT+Tool-use
approach.
推理代理 :使用推理模型、推理工具或我们的自定义CoT+工具使用
方法构建一流的推理代理。 - Natively Multi Modal: Built in support for text, image, audio and video.
原生多模态 :内置对文本、图像、音频和视频的支持。 - Multi Agent Teams: Industry leading multi-agent architecture with 3 different modes:
route
,collaborate
andcoordinate
.
多代理团队 :行业领先的多代理架构,具有 3 种不同的模式:路由
、协作
和协调
。 - Long-term Memory: Built in support for long-term memory with our
Storage
andMemory
classes.
Long-term Memory:通过Storage
和Memory
类内置对长期内存的支持。 - Domain Knowledge: Add domain knowledge to your Agents with our
Knowledge
classes. Fully async and highly performant.
领域知识 :通过我们的知识
课程为您的代理添加领域知识。完全异步且高性能。 - Structured Outputs: First class support for structured outputs using native structured outputs or
json_mode
.
结构化输出 :对使用本机结构化输出或json_mode
的结构化输出提供一流的支持。 - Monitoring: Track agent sessions and performance in real-time on agno.com.
监控 :在 agno.com 上实时跟踪代理会话和绩效。
三、Installation 安装
文末提供源码下载
pip install -U agno
What are Agents? 什么是代理?
Agents are intelligent programs that solve problems autonomously.
代理是自主解决问题的智能程序。
Agents have memory, domain knowledge and the ability to use tools (like searching the web, querying a database, making API calls). Unlike traditional programs that follow a predefined execution path, Agents dynamically adapt their approach based on the context and tool results.
代理具有内存、领域知识和使用工具的能力(如搜索 Web、查询数据库、进行 API 调用)。与遵循预定义执行路径的传统程序不同,代理程序会根据上下文和工具结果动态调整其方法。
Instead of a rigid binary definition, let's think of Agents in terms of agency and autonomy.
让我们从代理和自主性的角度来考虑代理,而不是严格的二元定义。
- Level 0: Agents with no tools (basic inference tasks).
0 级 :没有工具的代理(基本推理任务)。 - Level 1: Agents with tools for autonomous task execution.
级别 1:具有自主任务执行工具的代理。 - Level 2: Agents with knowledge, combining memory and reasoning.
第 2 级 :有知识的代理人,结合记忆和推理。 - Level 3: Teams of specialized agents collaborating on complex workflows.
第 3 级 :专业代理团队在复杂的工作流程中进行协作。
Example - Basic Agent 示例 — 基本代理
The simplest Agent is just an inference task, no tools, no memory, no knowledge.
最简单的 Agent 只是一个推理任务,没有工具,没有内存,没有知识。
from agno.agent import Agent
from agno.models.openai import OpenAIChatagent = Agent(model=OpenAIChat(id="gpt-4o"),description="You are an enthusiastic news reporter with a flair for storytelling!",markdown=True
)
agent.print_response("Tell me about a breaking news story from New York.", stream=True)
To run the agent, install dependencies and export your OPENAI_API_KEY
.
要运行代理,请安装依赖项并导出 OPENAI_API_KEY
。
pip install agno openaiexport OPENAI_API_KEY=sk-xxxxpython basic_agent.py
Example - Agent with tools
示例 — 使用工具的代理
This basic agent will obviously make up a story, lets give it a tool to search the web.
这个基本代理显然会编造一个故事,让我们给它一个搜索网络的工具。
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoToolsagent = Agent(model=OpenAIChat(id="gpt-4o"),description="You are an enthusiastic news reporter with a flair for storytelling!",tools=[DuckDuckGoTools()],show_tool_calls=True,markdown=True
)
agent.print_response("Tell me about a breaking news story from New York.", stream=True)
Install dependencies and run the Agent:
安装依赖项并运行 Agent:
pip install duckduckgo-searchpython agent_with_tools.py
Now you should see a much more relevant result.
现在,您应该会看到一个更相关的结果。
View this example in the cookbook在说明书中查看此示例
Example - Agent with knowledge
示例 - 具有知识的代理
Agents can store knowledge in a vector database and use it for RAG or dynamic few-shot learning.
代理可以将知识存储在向量数据库中,并将其用于 RAG 或动态小样本学习。
Agno agents use Agentic RAG by default, which means they will search their knowledge base for the specific information they need to achieve their task.
Agno 代理默认使用 Agentic RAG,这意味着他们将在知识库中搜索完成任务所需的特定信息。
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.embedder.openai import OpenAIEmbedder
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.lancedb import LanceDb, SearchTypeagent = Agent(model=OpenAIChat(id="gpt-4o"),description="You are a Thai cuisine expert!",instructions=["Search your knowledge base for Thai recipes.","If the question is better suited for the web, search the web to fill in gaps.","Prefer the information in your knowledge base over the web results."],knowledge=PDFUrlKnowledgeBase(urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],vector_db=LanceDb(uri="tmp/lancedb",table_name="recipes",search_type=SearchType.hybrid,embedder=OpenAIEmbedder(id="text-embedding-3-small"),),),tools=[DuckDuckGoTools()],show_tool_calls=True,markdown=True
)# Comment out after the knowledge base is loaded
if agent.knowledge is not None:agent.knowledge.load()agent.print_response("How do I make chicken and galangal in coconut milk soup", stream=True)
agent.print_response("What is the history of Thai curry?", stream=True)
Install dependencies and run the Agent:
安装依赖项并运行 Agent:
pip install lancedb tantivy pypdf duckduckgo-searchpython agent_with_knowledge.py
View this example in the cookbook在说明书中查看此示例
Example - Multi Agent Teams
示例 — 多代理团队
Agents work best when they have a singular purpose, a narrow scope and a small number of tools. When the number of tools grows beyond what the language model can handle or the tools belong to different categories, use a team of agents to spread the load.
当代理具有单一目的、狭窄的范围和少量工具时,它们的效果最好。当工具数量超出语言模型可以处理的范围或工具属于不同的类别时,请使用代理团队来分担负载。
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
from agno.team import Teamweb_agent = Agent(name="Web Agent",role="Search the web for information",model=OpenAIChat(id="gpt-4o"),tools=[DuckDuckGoTools()],instructions="Always include sources",show_tool_calls=True,markdown=True,
)finance_agent = Agent(name="Finance Agent",role="Get financial data",model=OpenAIChat(id="gpt-4o"),tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],instructions="Use tables to display data",show_tool_calls=True,markdown=True,
)agent_team = Team(mode="coordinate",members=[web_agent, finance_agent],model=OpenAIChat(id="gpt-4o"),success_criteria="A comprehensive financial news report with clear sections and data-driven insights.",instructions=["Always include sources", "Use tables to display data"],show_tool_calls=True,markdown=True,
)agent_team.print_response("What's the market outlook and financial performance of AI semiconductor companies?", stream=True)
Install dependencies and run the Agent team:
安装依赖项并运行 Agent 团队:
pip install duckduckgo-search yfinancepython agent_team.py
四、Performance 性能
在 Agno,我们痴迷于性能。为什么?因为即使是简单的 AI 工作流也可以产生数千个 Agent 来实现其目标。将其扩展到适度数量的用户,性能成为瓶颈。Agno 旨在为高性能代理系统提供动力:
- Agent instantiation: ~2μs on average (~10,000x faster than LangGraph).
代理实例化:平均 ~2μs(比 LangGraph 快 ~10,000 倍)。 - Memory footprint: ~3.75Kib on average (~50x less memory than LangGraph).
内存占用:平均 ~3.75Kib(内存比 LangGraph 少 ~50 倍)。
Tested on an Apple M4 Mackbook Pro.
在 Apple M4 Mackbook Pro 上测试。
While an Agent's run-time is bottlenecked by inference, we must do everything possible to minimize execution time, reduce memory usage, and parallelize tool calls. These numbers may seem trivial at first, but our experience shows that they add up even at a reasonably small scale.
虽然 Agent 的运行时间受到推理的瓶颈,但我们必须尽一切可能最大限度地减少执行时间、减少内存使用量并并行化工具调用。这些数字乍一看似乎微不足道,但我们的经验表明,即使在相当小的规模上,它们也会加起来。
Instantiation time 实例化时间
Let's measure the time it takes for an Agent with 1 tool to start up. We'll run the evaluation 1000 times to get a baseline measurement.
让我们测量一下 Agent with 1 工具的启动时间。我们将运行评估 1000 次以获得基线测量值。
You should run the evaluation yourself on your own machine, please, do not take these results at face value.
您应该在自己的计算机上自己运行评估,请不要只看表面结果。
# Setup virtual environment
./scripts/perf_setup.sh
source .venvs/perfenv/bin/activate
# OR Install dependencies manually
# pip install openai agno langgraph langchain_openai# Agno
python evals/performance/instantiation_with_tool.py# LangGraph
python evals/performance/other/langgraph_instantiation.py
The following evaluation is run on an Apple M4 Mackbook Pro. It also runs as a Github action on this repo.
以下评估在 Apple M4 Mackbook Pro 上运行。它还作为此存储库上的 Github 作运行。
LangGraph is on the right, let's start it first and give it a head start.
LangGraph 在右侧, 让我们先启动它,并先给它一个良好的开端 。
Agno is on the left, notice how it finishes before LangGraph gets 1/2 way through the runtime measurement, and hasn't even started the memory measurement. That's how fast Agno is.
Agno 在左侧,请注意它是如何在 LangGraph 完成 1/2 运行时测量之前完成的,甚至还没有开始内存测量。这就是 Agno 的速度。
agno_vs_langgraph_perf.mp4
Dividing the average time of a Langgraph Agent by the average time of an Agno Agent:
将 Langgraph Agent 的平均时间除以 Agno Agent 的平均时间:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>0.020526s / 0.000002s ~ 10,263
</code></span></span></span>
In this particular run, Agno Agents startup is roughly 10,000 times faster than Langgraph Agents. The numbers continue to favor Agno as the number of tools grow, and we add memory and knowledge stores.
在这个特定的运行中,Agno Agents 的启动速度大约比 Langgraph Agent 快 10000 倍 。随着工具数量的增加,这些数字继续有利于 Agno,并且我们增加了内存和知识存储。
Memory usage 内存使用情况
To measure memory usage, we use the tracemalloc
library. We first calculate a baseline memory usage by running an empty function, then run the Agent 1000x times and calculate the difference. This gives a (reasonably) isolated measurement of the memory usage of the Agent.
为了测量内存使用情况,我们使用 tracemalloc
库。我们首先通过运行一个空函数来计算基线内存使用量,然后运行 Agent 1000 次并计算差值。这给出了 Agent 的内存使用情况的(合理)隔离测量。
We recommend running the evaluation yourself on your own machine, and digging into the code to see how it works. If we've made a mistake, please let us know.
我们建议您在自己的计算机上自行运行评估,并深入研究代码以了解其工作原理。如果我们犯了错误,请告诉我们。
Dividing the average memory usage of a Langgraph Agent by the average memory usage of an Agno Agent:
将 Langgraph 代理的平均内存使用量除以 Agno 代理的平均内存使用量:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>0.137273/0.002528 ~ 54.3
</code></span></span></span>
Langgraph Agents use ~50x more memory than Agno Agents. In our opinion, memory usage is a much more important metric than instantiation time. As we start running thousands of Agents in production, these numbers directly start affecting the cost of running the Agents.
Langgraph Agent 使用的内存比 Agno Agent 多 ~50 倍 。在我们看来,内存使用情况是一个比实例化时间重要得多的指标。当我们开始在生产环境中运行数千个 Agent 时,这些数字会直接开始影响运行 Agent 的成本。
Conclusion 结论
Agno agents are designed for performance and while we do share some benchmarks against other frameworks, we should be mindful that accuracy and reliability are more important than speed.
Agno 代理专为性能而设计,虽然我们确实与其他框架共享一些基准,但我们应该注意,准确性和可靠性比速度更重要。
We'll be publishing accuracy and reliability benchmarks running on Github actions in the coming weeks. Given that each framework is different and we won't be able to tune their performance like we do with Agno, for future benchmarks we'll only be comparing against ourselves.
我们将在未来几周内发布在 Github 作上运行的准确性和可靠性基准。鉴于每个框架都是不同的,我们无法像使用 Agno 那样调整它们的性能,因此对于未来的基准测试,我们只会与自己进行比较。
Cursor Setup 光标设置
When building Agno agents, using Agno documentation as a source in Cursor is a great way to speed up your development.
在构建 Agno 代理时,使用 Agno 文档作为 Cursor 中的源是加快开发速度的好方法。
- In Cursor, go to the settings or preferences section.
在 Cursor 中,转到 settings (设置) 或 preferences (首选项) 部分。 - Find the section to manage documentation sources.
找到 管理文档源 部分。 - Add
https://docs.agno.com
to the list of documentation URLs.
将https://docs.agno.com
添加到文档 URL 列表中。 - Save the changes. 保存更改。
Now, Cursor will have access to the Agno documentation.
现在,Cursor 将可以访问 Agno 文档。
五、软件下载
夸克网盘分享
本文信息来源于GitHub作者地址https://github.com/agno-agi/agno