在開發代理人工智慧時,開發人員經常會發現自己需要在速度、靈活性和資源效率之間權衡利弊。我一直在探索人工智慧代理框架,並接觸到了 Agno(早期是 Phi-data)。Agno 是一個用於構建多模式代理的輕量級框架。他們聲稱自己的速度是 LangGraph 的 1 萬倍,記憶體佔用是 LangGraph 的 1/50。聽起來很吸引人,對嗎?
Agno 和 LangGraph 提供了截然不同的體驗。在親身體驗了 Agno 並將其效能和架構與 LangGraph 進行比較之後,下面將詳細介紹它們之間的區別、各自的亮點以及 Agno 的優勢所在。
- 構建 TriSage 和營銷分析代理
- 如果您需要快速、低記憶體使用率、多模態功能以及使用模型/工具的靈活性,請使用 Agno。
- 如果您喜歡基於流程的邏輯或結構化的執行路徑,或者已經與 LangChain 的生態系統繫結,請使用 LangGraph。
Agno能提供什麼?
Agno 在設計時非常注重效能和簡約性。Agno 的核心是一個開源、模型無關的代理框架,專為多模態任務而構建,這意味著它可以原生處理文字、影像、音訊和影片。它的獨特之處在於,即使在協調大量具有記憶體、工具和向量儲存等附加複雜性的代理時,其引擎蓋下的執行速度也非常輕快。
突出的主要優勢:
- 驚人的例項化速度:Agno 中每個代理的建立時間約為 2μs,比 LangGraph 快約 10000 倍。
- 輕巧的記憶體佔用:Agno 代理平均僅佔用 ~3.75 KiB 記憶體,是 LangGraph 代理的 50 倍。
- 多模態本地支援:無需駭客或外掛–Agno 從底層開始構建,可與各種媒體型別無縫協作。
- 與模型無關:Agno 不關心您使用的是 OpenAI、Claude、Gemini 還是開源 LLM。您不會被鎖定在特定的提供商或執行時中。
- 即時監控:可以透過 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:用於定義和執行人工智慧代理的核心框架。
- 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 – 搜尋網頁,writer_agent – 撰寫文章,image_agent – 建立視覺效果
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)
輸出
持續輸出
持續輸出
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實踐:構建市場分析員代理
Market Analyst Agent 是一個使用 Agno 的基於團隊的系統,結合了透過 DuckDuckGo 獲取即時資訊的 Web Agent 和透過 Yahoo Finance 獲取金融資料的 Finance Agent。該系統由 OpenAI 模型提供支援,使用表格、標記和原始碼支援的內容提供市場洞察和 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()], instructions="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_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 top AI companies of the world?", stream=True)
輸出
Agno vs LangGraph:效能對決
讓我們來看看具體細節,Agno 的官方文件中包含了這一切:
指標 | Agno | LangGraph | 對比結果 |
---|---|---|---|
代理例項時間 | ~2μs | ~20ms | ~10,000x 快(Agno比LangGraph) |
每個代理的記憶體使用量 | ~3.75 KiB | ~137 KiB | ~50x 高(LangGraph比Agno) |
- 效能測試在 Apple M4 MacBook Pro 上進行,使用 Python 的 tracemalloc 進行記憶體分析。
- Agno 測量了 1000 次執行的平均例項化和記憶體使用情況,並隔離了 Agent 程式碼,以獲得乾淨利落的 delta。
這種速度和記憶體效率不僅僅是數字問題,它還是可擴充套件性的關鍵。在實際的代理部署中,成千上萬的代理可能需要同時啟動,每一毫秒和每一千位元組都至關重要。
LangGraph 雖然功能強大,結構更合理,適合某些基於流的應用,但除非經過大量最佳化,否則往往難以承受這種負載。這對於小規模應用來說可能不是問題,但在執行生產規模的代理時,代價就會變得非常高昂。
那麼……Agno 比 LangGraph 更好嗎?
不一定。這取決於您正在構建什麼:
- 如果您正在構建基於流程的代理邏輯(想想看:帶有高階控制的有向步驟圖),LangGraph 可能會提供更具表現力的結構。
- 但是,如果您需要超快、低指令碼、多模式的代理執行,尤其是在高併發或動態環境中,Agno 將以絕對優勢勝出。
Agno 顯然更傾向於速度和系統級效率,而 LangGraph 則偏重於結構化協調和可靠性。儘管如此,Agno 的開發人員自己也承認,準確性和可靠性基準同樣重要,而且這些基準目前正在制定中。在這些基準出來之前,我們無法斷定邊緣情況下的正確性或彈性。
小結
從實際操作的角度來看,Agno 已經為實際工作負載做好了準備,尤其是對於大規模構建代理系統的團隊而言。它的即時效能監控、對結構化輸出的支援,以及插入記憶體和向量知識的能力,使其成為快速構建強大應用程式的令人信服的平臺。
LangGraph 並沒有退出競爭,它的優勢在於清晰、面向流程的控制邏輯。但是,如果您遇到了擴充套件障礙,或者需要執行成千上萬的代理而又不影響基礎架構,那麼 Agno 值得您認真考慮。
評論留言