AIGC宇宙 AIGC宇宙

Agno框架介绍:用于构建多模态智能体的轻量库

作者:核子可乐
2025-04-14 10:58
译者 | 核子可乐审校 | 重楼在开发代理式AI时,开发者往往需要在速度、灵活性和资源利用率间反复权衡。 本文将向大家介绍Agno——一款用于构建多模态智能体的轻量化框架。 其速度号称比LangGraph快上万倍,内存使用量则仅为1/50。

Agno框架介绍:用于构建多模态智能体的轻量库

译者 | 核子可乐

审校 | 重楼

在开发代理式AI时,开发者往往需要在速度、灵活性和资源利用率间反复权衡。本文将向大家介绍Agno——一款用于构建多模态智能体的轻量化框架。其速度号称比LangGraph快上万倍,内存使用量则仅为1/50。

事实上,Agno与LangGraph在使用体验上也有很大区别。本文将以亲身体会为基础对二者进行比较,具体介绍它们的不同之处、各自亮点与Agno的独特优势。

概述

  • 构建TriSage与Marketing Analyst营销分析师智能体。
  • 如果要求高速、低内存占用、多模态功能以及灵活的模型/工具选项,请选择Agno。
  • 如果偏向基于流程的逻辑或结构化执行路径,或者已经与LangChain生态系统紧密关联,请选择LangGraph。

Agno有何作用?

基于性能和极简主义设计而成的Agno,从本质上讲是一款开源且模型中立的智能体框架,专为多模态任务而打造——即可以原生处理文本、图像、音频和视频。它的独特之处在于便捷快速,在应对大量智能体并面对高内存用量、工具和向量存储复杂度时仍保持良好性能。

核心优势:

  • 超快的实例化速度:Agno中的智能体创建速度平均仅为2微秒,约为LangGraph的1万倍。
  • 轻量化内存占用:Agno智能体平均内存占用量为3.75 KiB,仅相当于LangGraph智能体的1/50。
  • 原生支持多模态:无需调整或插件,Agno可直接与各种媒体类型实现无缝协作。
  • 模型中立:Agno不关心用户使用的是OpenAI、Claude、Gemini抑或是开源大模型,因此避免了特定供应商或运行时锁定的问题。
  • 实时监控:可以通过Agno实时观察智能体会话及性能,使得调试和优化更加流畅。

Agno上手实践:构建TriSage智能体

Agno的使用体验非常高效,启动的智能体队列不仅可以并行运行,还能共享内存、工具和知识库。这些智能体可以专门化并分组为多智能体团队,且内存层支持将会话和状态存储在持久数据库当中。

真正令人印象深刻的,是Agno如何在不牺牲性能的前提下管理复杂性。它可以处理现实世界的智能体编排(如工具链、基于RAG检索或者结构化输出生成),保证不引发性能瓶颈。

如果大家用过LangGraph或者类似框架,就会意识到Agno大大降低了启动延迟与资源消耗。这也成为规模化应用场景下良好性能的实现关键。下面开始构建TriSage智能体。

安装必要库

复制
!pip install -U agno
!pip install duckduckgo-search
!pip install openai
!pip install pycountry

以上为安装必要Python包的shell命令:

  • agno: 用于定义和运行AI智能体的核心框架。
  • duckduckgo-search: 让智能体使用DuckDuckGo搜索网络。
  • openai: 用于同OpenAI模型(如GPT-4或GPT-3.5)交互。

必要导入

复制
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.googlesearch import GoogleSearchTools
from agno.tools.dalle import DalleTools
from agno.team import Team
from textwrap import dedent

API密钥设置

复制
from getpass import getpass
OPENAI_KEY = getpass('Enter Open AI API Key: ')

import os
os.environ['OPENAI_API_KEY'] = OPENAI_KEY
  • getpass(): 输入API密钥的安全方式(不可见)。
  • 将密钥存储在环境内,以便agno框架在调用OpenAI API时进行获取。

web_agent – Searches the Web, writer_agent – Writes the Article, image_agent – Creates Visuals

复制
web_agent = Agent(
 name="Web Agent",
 role="Search the web for information on Eiffel tower",
 model=OpenAIChat(id="o3-mini"),
 tools=[DuckDuckGoTools()],
 instructions="Give historical information",
 show_tool_calls=True,
 markdown=True,
)

writer_agent = Agent(
 name="Writer Agent",
 role="Write comprehensive article on the provided topic",
 model=OpenAIChat(id="o3-mini"),
 tools=[GoogleSearchTools()],
 instructions="Use outlines to write articles",
 show_tool_calls=True,
 markdown=True,
)

image_agent = Agent(
 model=OpenAIChat(id="gpt-4o"),
 tools=[DalleTools()],
 description=dedent("""\
 You are an experienced AI artist with expertise in various artistic styles,
 from photorealism to abstract art. You have a deep understanding of composition,
 color theory, and visual storytelling.\
 """),
 instructions=dedent("""\
 As an AI artist, follow these guidelines:
 1. Analyze the user's request carefully to understand the desired style and mood
 2. Before generating, enhance the prompt with artistic details like lighting, perspective, and atmosphere
 3. Use the `create_image` tool with detailed, well-crafted prompts
 4. Provide a brief explanation of the artistic choices made
 5. If the request is unclear, ask for clarification about style preferences

 Always aim to create visually striking and meaningful images that capture the user's vision!\
 """),
 markdown=True,
 show_tool_calls=True,
)

并入团队

复制
agent_team = Agent(
 team=[web_agent, writer_agent, image_agent],
 model=OpenAIChat(id="gpt-4o"),
 instructions=["Give historical information", "Use outlines to write articles","Generate Image"],
 show_tool_calls=True,
 markdown=True,
)

运行整体

复制
agent_team.print_response("Write an article on Eiffel towar and generate image", stream=True)

输出结果

Agno框架介绍:用于构建多模态智能体的轻量库

继续输出

Agno框架介绍:用于构建多模态智能体的轻量库

继续输出

Agno框架介绍:用于构建多模态智能体的轻量库

复制
I have created a realistic image of the Eiffel Tower. The image captures the
 tower's full height and design, ┃
┃ beautifully highlighted by the late afternoon sun. You can view it by
 clicking here.

图像输出

Agno框架介绍:用于构建多模态智能体的轻量库

上手Agno:构建营销分析师智能体

此智能体是一套使用Agno的团队系统,将通过DuckDuckGo获取实时信息的Web智能体与通过雅虎金融获取数据的金融智能体结合起来。其由OpenAI模型提供支持,使用表格、markdown及来源支持内容提供市场洞察与AI企业绩效,借此保证结果明确、有深度且公开透明。

复制
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="o3-mini"),
 tools=[DuckDuckGoTools()],
 instructinotallow="Always include sources",
 show_tool_calls=True,
 markdown=True,
)

finance_agent = Agent(
 name="Finance Agent",
 role="Get financial data",
 model=OpenAIChat(id="o3-mini"),
 tools=[YFinanceTools(stock_price=True, analyst_recommendatinotallow=True, company_info=True)],
 instructinotallow="Use tables to display data",
 show_tool_calls=True,
 markdown=True,
)

agent_team = Agent(
 team=[web_agent, finance_agent],
 model=OpenAIChat(id="gpt-4o"),
 instructinotallow=["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 top AI companies of the world?", stream=True)

输出结果

Agno框架介绍:用于构建多模态智能体的轻量库

Agno与LangGraph:性能对决

下面我们来看Agno官方文档中列出的性能细节:

指标

Agno

LangGraph

差异

智能体实例化用时

~2μs

~20ms

快~1万倍

每智能体内存用量

~3.75 KiB

~137 KiB

仅为~1/50

  • 此性能测试采用Python版tracemalloc内存分析,硬件平台为苹果M4 MacBook Pro笔记本电脑。
  • Agno测量了1000次运行的平均实例化用时及内存用量,隔离了智能体代码以保证结果准确。

这样的性能优势代表的不只是数字差异,更是可扩展性的新希望。在现实智能体部署中,用户往往需要同时启动成千上万个智能体,因此每毫秒、每KB都很重要。

虽然LangGraph对于某些流应用来说功能强大且结构更加完善,但除非经过深度优化,否则在这类高负载场景下往往性能不佳。

所以说……Agno比LangGraph更好?

不一定,具体视应用需求而定:

  • 如果处理基于流传输的智能体逻辑(例如具有高级控制的分步有向图),则LangGraph可能会提供更具表现力的结构。
  • 如果需要超快、低内存的多模态智能体执行效果,而且环境的并发或动态程度较高,那么Agno将会遥遥领先。

Agno显然更倾向于速度和系统层级的效率,而LangGraph则偏重结构化编排与可靠性。不过Agno开发团队也非常重视准确性与可靠性,而且目前正在为此投入时间和精力。

总结

从实践角度来看,Agno已经为生产级工作负载做好了准备,尤其是对大规模构建智能体系统的团队而言。它的实时性能监控、对结构化输出的支持以及插入内存+向量知识的能力,使其成为能够快速构建强大应用程序的出色平台。

但LangGraph的江湖地位也没有动摇——它的优势在于清晰且面向流程的控制逻辑。不过如果大家遇到了扩展障碍,或者需要运行成千上万个智能体又不致挤爆基础设施,那么Agno无疑更值得考虑。

原文标题:Agno Framework: A Lightweight Library for Building Multimodal Agents,作者:Pankaj Singh

相关资讯

现场Live震撼!OmAgent框架强势开源!行业应用已全面开花

第一个提出自动驾驶并进行研发的公司是 Google,巧的是,它发布的 Transformer 模型也为今天的大模型发展奠定了基础。自动驾驶已经完成从概念到现实的华丽转变,彻底重塑了传统驾车方式,而大模型行业正在经历的,恰如自动驾驶技术发展的传奇征程 ——最顶尖的研发团队竞相投身其中、不断加速抢跑的技术产品创新,以及持续被推向极致的用户体验。在大模型赛道中,有一家企业始终以领先的身位,推动着行业边界向前拓展。为什么是联汇科技?当行业刚开始关注大模型,他们已经锚定多模态大模型,并高分取得了工信部大模型检测的 001 号
7/6/2024 11:02:00 AM
机器之心

内存革命!LangGraph 0.3.19如何实现Python内存使用效率的飞跃?

在构建复杂 AI 应用或大规模分布式系统时,内存管理始终是开发者面临的痛点。 尤其在 Python 生态中,动态类型和垃圾回收机制虽然灵活,但对内存的高效利用提出了更高要求。 近日,LangGraph 团队宣布推出 0.3.19 版本,通过一系列内存优化技术,将 Python 应用的内存占用降低 40% 以上,并支持长期记忆存储,彻底解决了复杂场景下的性能瓶颈。
4/1/2025 12:33:03 AM
智Echo

LangGraph:如何用“图思维”轻松管理多Agent协作?

引言当AI任务变得复杂时,我们需要更好的“调度员”。 随着智能应用场景的深化,单一 Agent 在处理复杂任务(如电商智能客服、金融数据分析流水线)时显现出明显局限性。 传统链式调用框架(如 LangChain)依赖开发者手动编排流程,在面对任务分支、动态决策和资源复用等场景时,往往陷入维护成本高、扩展性差的困境。
4/1/2025 8:48:34 AM
张张