❤️ 如果你也关注 AI 的发展现状,且对 AI 应用开发感兴趣,我会每日分享大模型与 AI 领域的开源项目和应用,提供运行实例和实用教程,帮助你快速上手AI技术!
🥦 微信公众号|搜一搜:蚝油菜花 🥦
大家好,我是蚝油菜花,今天跟大家分享一下 Agno 这个用于构建多模态智能体的轻量级框架。
🚀 快速阅读
Agno 是一个用于构建多模态智能体的轻量级框架。
- 核心功能:支持文本、图像、音频和视频等多种数据模态,创建智能体的速度比传统框架快 5000 倍。
- 技术原理:基于 Python 实现,无依赖性设计,支持与向量数据库集成,实现高效的检索增强生成(RAG)或动态少样本学习。
Agno 是什么
Agno 是一个用于构建多模态智能体的轻量级框架。它支持多种数据模态(如文本、图像、音频和视频),并且可以快速创建智能体。Agno 提供了内存管理和知识库支持,能够将用户会话和智能体状态存储在数据库中,基于向量数据库实现动态少样本学习。此外,Agno 支持多智能体协作,帮助用户实时跟踪智能体会话和性能。
Agno 的设计目标是简化开发流程,提升性能,并确保灵活性。通过无依赖性架构和纯 Python 实现,开发者可以轻松上手并快速构建高效的智能体应用。
Agno 的主要功能
- 极速智能体创建:创建智能体的速度比传统框架(如 LangGraph)快 5000 倍。
- 模型无关性:支持任何模型和提供商,用户可以根据需要选择不同的模型,无需担心供应商锁定。
- 多模态支持:原生支持文本、图像、音频和视频等多种数据模态。
- 多智能体协作:支持将任务分配给多个专业化的智能体,实现高效的分工和协作。
- 内存管理:将用户会话和智能体状态存储在数据库中,确保数据的持久化和安全性。
- 知识库支持:基于向量数据库实现检索增强生成(RAG)或动态少样本学习,提升智能体的知识检索能力。
- 结构化输出:智能体支持结构化数据格式响应,方便与其他系统集成。
- 实时监控:在 agno.com 上实时跟踪智能体会话和性能,便于管理和优化。
Agno 的技术原理
- 纯 Python 实现:Agno 基于 Python 编写,避免复杂的图结构、链式调用或其他复杂的模式,让代码更加简洁易懂,同时也便于开发者快速上手。
- 无依赖性架构:用无依赖性设计,支持任何模型、任何提供商和任何模态。
- 向量数据库集成:支持与向量数据库集成,利用向量数据库的高效检索能力,实现检索增强生成(RAG)或动态少样本学习。
- 多智能体协作机制:基于任务分配和分工,将复杂任务分解为多个子任务,由不同的专业智能体分别处理。
如何运行 Agno
1. 安装 Agno
pip install -U agno
2. 创建基本智能体
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
3. 创建带有工具的智能体
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)
安装依赖项并运行智能体:
pip install duckduckgo-search
python agent_with_tools.py
4. 创建带有知识库的智能体
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)
安装依赖项并运行智能体:
pip install lancedb tantivy pypdf duckduckgo-search
python agent_with_knowledge.py
5. 创建多智能体协作
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
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 = Agent(
team=[web_agent, finance_agent],
model=OpenAIChat(id="gpt-4o"),
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)
安装依赖项并运行智能体团队:
pip install duckduckgo-search yfinance
python agent_team.py
资源
- GitHub 仓库:https://github.com/agno-agi/agno
- Agno 文档:https://docs.agno.com
❤️ 如果你也关注 AI 的发展现状,且对 AI 应用开发感兴趣,我会每日分享大模型与 AI 领域的开源项目和应用,提供运行实例和实用教程,帮助你快速上手AI技术!
🥦 微信公众号|搜一搜:蚝油菜花 🥦