agno: 轻量级的多模态智能代理库

GitHubhttps://github.com/agno-agi/agno

更多AI开源软件发现分享好用的AI工具、AI开源软件、AI模型、AI变现 - 小众AI

一个高性能、开源的 Python 库,用于构建多模态智能代理。通过统一大语言模型的 API,并赋予它们记忆、知识、工具和推理等强大功能。该项目速度快、内存占用少,支持文本、图像、音频和视频等多种内容形式,以及多代理、结构化输出,兼容几乎任何模型和服务供应商。

主要功能

  • 快如闪电:代理创建速度比 LangGraph 快 10,000 倍(请参阅性能)。
  • 模型不可知:使用任何模型、任何提供商,无锁定。
  • 多模态:对文本、图像、音频和视频的原生支持。
  • Multi Agent:建立专业代理团队。
  • 内存管理:将代理会话和状态存储在数据库中。
  • 知识商店:使用矢量数据库进行 RAG 或动态小样本学习。
  • 结构化输出:让代理以结构化格式响应。
  • 监控:在 agno.com 上实时跟踪代理会话和绩效。

安装

pip install -U agno

实战演习

场景1: 基本代理

最简单的 Agent 只是一个推理任务,没有工具,没有内存,没有知识。

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)

要运行代理,请安装依赖项并导出您的 .OPENAI_API_KEY​

pip install agno openai

export OPENAI_API_KEY=sk-xxxx

python basic_agent.py

在说明书中查看此示例

场景2: 使用工具的代理

这个基本代理显然会编造一个故事,让我们给它一个搜索网络的工具。

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)

安装依赖项并运行 Agent:

pip install duckduckgo-search

python agent_with_tools.py

现在,您应该会看到一个更相关的结果。

在说明书中查看此示例

场景3:具有知识的代理

代理可以将知识存储在向量数据库中,并将其用于 RAG 或动态小样本学习。

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

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

安装依赖项并运行 Agent:

pip install lancedb tantivy pypdf duckduckgo-search

python agent_with_knowledge.py

在说明书中查看此示例

场景4:多代理团队

当代理具有单一目的、狭窄的范围和少量工具时,它们的效果最好。当工具数量超出语言模型可以处理的范围或工具属于不同的类别时,请使用代理团队来分担负载。

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)

安装依赖项并运行 Agent 团队:

pip install duckduckgo-search yfinance

python agent_team.py
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值