Agno - 轻量级智能体构建库


一、关于 Agno

Agno 是一个轻量级库,用于构建具备记忆、知识、工具和推理能力的智能体(Agents)。

开发者可以使用 Agno 构建推理智能体、多模态智能体、智能体团队和工作流。Agno 还提供美观的聊天界面,以及监控和评估智能体性能的工具。

以下是一个研究股票并撰写报告的智能体示例,展示了逐步推理过程:

from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools

agent = 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)

https://github.com/user-attachments/assets/bbb99955-9848-49a9-9732-3e19d77b2ff8


相关链接资源


关键特性 & 为什么选择 Agno

Agno 简单、快速且模型无关。主要特性包括:

  • 模型无关:提供统一接口支持23+模型提供商,无锁定
  • 极速响应:智能体平均实例化时间仅**2μs**(比LangGraph快10,000倍),内存占用仅**3.75Kib**(比LangGraph少50倍)
  • 原生推理支持:通过推理模型、ReasoningTools或自定义CoT+Tool-use方法构建"思考型"智能体
  • 多模态原生支持:支持文本、图像、音频和视频的输入输出
  • 先进多智能体架构:提供行业领先的三种协作模式:routecollaboratecoordinate
  • 长期记忆与会话存储:通过StorageMemory类实现状态保持
  • 20+向量数据库支持:为智能体添加领域知识,全异步高性能
  • 结构化输出:原生支持结构化输出和json_mode
  • 实时监控:通过agno.com监控会话和性能

二、安装

pip install -U agno

三、基本使用(快速开始)


1、什么是智能体?

智能体是自主运行的AI程序:

  • 大脑:用于推理和响应的模型
  • 身体:与现实世界交互的工具
  • 行为:由指令定义,模型越强,指令跟随越好

智能体还具备:

  • 推理:在响应前"思考",分析行动结果
  • 知识:存储在向量数据库中的领域信息(Agentic RAG)
  • 存储:保存会话历史和状态
  • 记忆:存储和回忆过往交互信息

2、推理智能体示例

保存为reasoning_agent.py

from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools

agent = Agent(
    model=Claude(id="claude-3-7-sonnet-latest"),     tools=[
        ReasoningTools(add_instructions=True, add_few_shot=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, )


运行环境配置:

uv venv --python 3.12
source .venv/bin/activate

uv pip install agno anthropic yfinance

export ANTHROPIC_API_KEY=sk-ant-api03-xxxx

python reasoning_agent.py

3、基础智能体示例

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = 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)

4、带工具的智能体

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools

agent = 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)

5、带知识的智能体

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, SearchType

agent = 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
)

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)

6、多智能体团队

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 Team

web_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)

四、性能表现

Agno 专为高性能设计:

  • 实例化时间:平均~2μs(比LangGraph快10,000倍)
  • 内存占用:平均~3.75Kib(比LangGraph少50倍)

测试环境:Apple M4 MacBook Pro


性能测试方法

# 设置环境
./scripts/perf_setup.sh
source .venvs/perfenv/bin/activate

# Agno测试
python evals/performance/instantiation_with_tool.py

# LangGraph测试
python evals/performance/other/langgraph_instantiation.py

测试结果对比:
https://github.com/user-attachments/assets/ba466d45-75dd-45ac-917b-0a56c5742e23


遥测说明

Agno会记录模型使用情况以优化更新,可通过设置AGNO_TELEMETRY=false禁用。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EAI工程笔记

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值