• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • 生成式人工智能/大語言模型

    擴展 NVIDIA Agent Intelligence Toolkit 以支持新的代理式框架

    NVIDIA Agent Intelligence toolkit 是一個開源庫,用于高效連接和優化 AI 智能體 團隊。它專注于幫助開發者快速構建、評估、分析和加速復雜的代理式 AI 工作流,即多個 AI 智能體協作執行任務的系統。

    “智能體工具包作為一個統一框架,集成了各種平臺 (例如 LangChain、LlamaIndex、Semantic Kernel 和 CrewAI) 中的現有智能體、工具和工作流。該工具包將這些組件視為函數調用,使其可組合和可重復使用。可以將智能體工具包視為編排 AI 智能體團隊的“指揮”。此外,它還提供用于分析 (例如跟蹤延遲和 token 使用情況) 、優化、擴展和可觀察性的工具,確保企業級代理式系統的高效性能。

    Overview of Agent Intelligence toolkit architecture.
    圖 1。Agent Intelligence 工具包架構圖

    Agent Intelligence 工具包的核心優勢在于其可擴展性。本文將介紹如何通過添加與其他代理式框架 Agno 的集成來擴展工具包。

    “Agno (以前稱為 Phidata) 是一個輕量級構建智能體庫,特別是具有多模態功能的智能體。它將 大語言模型 (LLMs) 作為統一的 API 公開,并為它們提供內存、知識、工具和推理等超能力。截至撰寫本文之時,Agno 的開發者生態系統不斷發展,擁有超過 26,000 個 GitHub 星。Agno 與模型無關、速度快且原生多模態。有關功能的完整列表,請在 GitHub 上查看 agno-agi/agno 。”

    智能體工具包的主要功能

    Agent 工具包生態系統中的常見特征和術語包括以下內容:

    • 工作流 :工作流是 Agent 工具包應用的主要切入點。它由 YAML 配置文件完全配置 ,該文件指定了要在工作流中使用的實體 (例如函數、LLMs 或 embedders) ,以及常規配置設置。
    • 軟件包 :模塊化組件或插件,可擴展工具包的功能,使其能夠與各種框架、工具和工作流集成。這些軟件包可以根據特定用例或要求單獨安裝,并使 Agent 工具包能夠支持各種代理式工作流。例如,CrewAI 的多智能體協作等工作流將使用 agentiq-crewai 包。
    • 插件 :Agent 工具包具有可擴展的插件系統,支持您向庫中添加新工具、代理、工作流程等。Agent 工具包插件系統圍繞兩個主要概念設計:entry points 和 decorators。借助 entry points,工具包可以從 Python 環境中安裝的任何分發包中發現插件。decorators 支持開發者向庫注冊插件。

    圖 2 顯示了工具包不同級別的 plugins。

    A diagram with three levels labeled (top to bottom): Workflow-Level Plugins, Package-Level Plugins, and Toolkit-Level Plugins.
    圖 2。Agent Intelligence 工具包中的插件

    將 Agno 集成到 Agent Intelligence Toolkit 中

    本節介紹將 Agno 集成到 Agent 工具包的步驟。可以應用相同的步驟將其他代理式框架集成到工具包中。

    第 0 步:預備知識

    在訪問 NVIDIA NIM 微服務時 ,運行 Agent 工具包工作流沒有特定的 GPU 要求。但是,如果您自行托管 NIM,則需要所選 NIM 所需的特定 GPU 或 GPU。有關 Agent 工具包的前提條件及其安裝步驟的更多詳細信息, 請參閱 GitHub 上的 NVIDIA/AIQToolkit

    第 1 步:創建新的 Agent Toolkit 包

    代理工具包使用軟件包 (位于 packages 目錄中) 與外部框架集成。創建一個新軟件包 agentiq_agno,將 Agno 連接到 Agent 工具包。首先,在 AgentIQ/packages/ 下創建名為 agentiq_agno 的新文件夾。通過研究 agentiq_crewai 等現有軟件包結構,可以得到如 Figure 3 所示的基本結構。

    Screenshot of agentiq_agno directory structure.
    圖 3。agentiq_agno 的目錄結構

    其次,配置 pyproject.toml,用于定義 package 及其 dependencies:

    [build-system]
    build-backend = "setuptools.build_meta"
    requires = ["setuptools &gt;= 64", "setuptools-scm&gt;=8"]
     
    [tool.setuptools.packages.find]
    where = ["src"]
    include = ["aiq.*"]
     
    [tool.setuptools_scm]
    root = "../.."
     
    [project]
    name = "agentiq-agno"
    dynamic = ["version"]
    dependencies = [
      "agentiq",
      "agno~=1.2.3",
    ]
    requires-python = "&gt;=3.12"
    readme = "src/aiq/meta/pypi.md"
    description = "Subpackage for Agno integration in Agent toolkit"
    keywords = ["ai", "rag", "agents"]
    classifiers = ["Programming Language :: Python"]
     
    [tool.uv]
    config-settings = { editable_mode = "compat" }
     
    [tool.uv.sources]
    agentiq = { workspace = true }
     
    [project.entry-points.'aiq.components']
    aiq_agno = "aiq.plugins.agno.register"

    請注意此 pyproject.toml 中的以下內容:

    • 依賴項:agentiqagno 等依賴項庫的列表。
    • 項目切入點: 掃描 Python 環境中名為 aiq.components 的切入點。入口點的值是加載入口點時將導入的 Python 模塊。例如,它指向 aiq.plugins.agno.register,這意味著在安裝 aiq-agno 發行版時,將在加載入口點時導入 aiq.plugins.agno.register 模塊。此模塊必須包含初始化庫時需要加載的所有 @register_<plugin_type> 裝飾器。

    然后使用以下命令定義 LLM 客戶端進行集成 NVIDIA NIM 。在以下代碼示例中,@register_llm_client 裝飾器注冊了用于 Agno 集成的 LLM 客戶端,可供使用 Agno 的代理式工作流使用。

    @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.AGNO)
    async def nim_agno(llm_config: NIMModelConfig, builder: Builder):
     
        from agno.models.nvidia import Nvidia
     
        config_obj = {
            **llm_config.model_dump(exclude={"type", "model_name"}, by_alias=True),
            "id": f"{llm_config.model_name}",
        }
     
        if ("api_key" not in config_obj or config_obj["api_key"] is None):
     
            if ("NVIDIA_API_KEY" in os.environ):
                pass
            else:
                nvidai_api_key = os.getenv("NVIDIA_API_KEY")
     
                if (nvidai_api_key is not None):
                    os.environ["NVIDIA_API_KEY"] = nvidai_api_key
     
        nvidia_args = {"id": config_obj.get("id")}
        if "base_url" in config_obj and config_obj.get("base_url") is not None:
            nvidia_args["base_url"] = config_obj.get("base_url")
        yield Nvidia(**nvidia_args)

    接下來,為 Agno 注冊一個工具包裝器。工具包裝器用于以特定于 LLM 框架的方式包裝函數。例如,使用 Agno 框架時,Agent 工具包函數需要封裝在 Agno 的 Tool 類中,以便與 Agno 兼容。查看 agno_tool_wrapper 的源代碼。

    第 2 步:安裝新 toolkit 包

    現在,您可以運行以下命令來安裝新創建的 Agno 包及其新插件:

    uv pip install -e '.[agno]'

    第 3 步:使用新支持的 agentic framework 創建自定義工作流

    下一步是使用 Agno 創建智能體的自定義工作流程。此示例將使用個人財務智能體,該智能體使用 NVIDIA LLM NIM 生成個性化財務計劃。它可以自動執行研究、規劃和制定量身定制的預算、投資策略和節約目標的過程,使用戶能夠控制自己的財務未來。

    Agent 工具包隨附一組命令行界面來管理工作流。您可以在 agentiq 項目根目錄下運行以下命令,為新工作流程 agno_personal_finance 生成必要的文件和目錄結構,從而實現設置流程的自動化:

    aiq workflow create --workflow-dir examples agno_personal_finance

    此命令會在 agentiqexamples 目錄下生成以下文件和文件夾:

    Screenshot of agno_personal_finance directory structure.
    圖 4。agno_personal_finance 的目錄結構

    此結構是一個 starter template。接下來,填寫詳細信息。

    pyproject.toml

    [build-system]
    build-backend = "setuptools.build_meta"
    requires = ["setuptools &gt;= 64", "setuptools-scm&gt;=8"]
     
    [tool.setuptools_scm]
    root = "../.."
     
    [project]
    name = "aiq_agno_personal_finance"
    dynamic = ["version"]
    dependencies = [
      "agentiq[agno]",
      "openai~=1.66",
      "litellm~=1.63.14"
    ]
    requires-python = "&gt;=3.12"
    description = "Custom Workflow using Agno for personal finance"
    classifiers = ["Programming Language :: Python"]
     
    [tool.uv.sources]
    agentiq = { path = "../..", editable = true }
     
    [project.entry-points.'aiq.components']
    aiq_agno_personal_finance = "aiq_agno_personal_finance.register"

    agno_personal_finance_function.py

    此文件包含個人金融智能體的主要功能。AgnoPersonalFinanceFunctionConfig 類定義用于創建函數 agno_personal_finance 的運行時實例的參數。該功能以用戶的財務目標和當前狀況為依據,調用研究人員智能體根據用戶偏好尋找財務建議、投資機會和節約策略,然后規劃器智能體生成個性化的財務計劃。要查看此文件的來源,請參閱 GitHub 上的 wenqiglantz/AgentIQ

    config.yml

    工作流配置文件用于指定函數和 LLM,并根據定義的函數和 LLM 以及常規配置設置來構建工作流。此示例使用 Llama 3.3 70B Instruct 作為 LLM。您可以對其進行自定義,以使用任何支持從 build.nvidia.com 或自托管 NIM 進行函數調用的 LLM。

    general:
      use_uvloop: true
     
    functions:
      agno_personal_finance:
        _type: agno_personal_finance
        llm_name: nim_llm
     
    llms:
      nim_llm:
        _type: nim
        model_name: meta/llama-3.3-70b-instruct
        temperature: 0.0
     
    workflow:
      _type: agno_personal_finance
      tool_names: [agno_personal_finance]
      llm_name: nim_llm
      verbose: true
      retry_parsing_errors: true
      max_retries: 3

    第 4 步:使用可重復使用的函數優化 workflow

    Agent 工具包的顯著特點之一是能夠使用其 builder 以與框架無關的方式獲取或創建工具。這意味著,任何需要使用工具中定義的功能的工作流程都可以重復使用這些工具。

    在當前 agno_personal_finance 的實現中,研究代理調用了一個 Serp API 搜索工具,根據用戶輸入來搜索金融建議、投資機會或其他信息。通過在 agno_personal_finance_function.py 中直接調用 Agno 的 SerpApiTools 來初始化搜索工具:

    search_tool = SerpApiTools(api_key=os.getenv("SERP_API_KEY"))

    對于 Agent 工具包中的可重用函數,Serp API 搜索是一個很好的選擇。下一節將介紹如何在工具包中為 Serp API 搜索添加可重復使用的函數。

    首先,研究 Agent 工具包插件圖 (圖 2) ,并確定此可重復使用函數的最佳位置是在軟件包級別。為什么?因為 SerpApiTools 是由 Agno 框架定義的類。然后,添加配置類 SerpApiToolConfig,實現 serp_api_tool 函數,并將此新函數 serp_api_tool 注冊到工具包中。請參閱 serp_api_tool 函數的完整源代碼。

    定義為新函數并在 Agent 工具包中注冊后,Agent 工具包的構建器即可發現此新函數。然后,您可以修改工作流中構建 Serp API 搜索工具的原始代碼行:

    search_tool = SerpApiTools(api_key=os.getenv("SERP_API_KEY"))

    以便:

    search_tool = builder.get_tool(fn_name=config.serp_api_tool, wrapper_type=LLMFrameworkEnum.AGNO)

    請參閱 agno_personal_finance_function.py 的最終源代碼

    新函數開發完成后,需要對工作流配置文件 config.yml 進行一些調整。在“functions” (函數) 部分下聲明 serp_api_tool,并將其注入到 agno_personal_finance 函數中。工作流部分將 llm_nameserp_api_tool 拼接在一起,將其組合成 agno_personal_finance 工作流。請參閱以下 config.yml 的示例片段:

    general:
      use_uvloop: true
     
    functions:
      serp_api_tool:
        _type: serp_api_tool
        # You can add your SerpAPI key here or use environment variables
        # api_key: your_serp_api_key
       
      agno_personal_finance:
        _type: agno_personal_finance
        llm_name: nim_llm
        serp_api_tool: serp_api_tool
       
    llms:
      nim_llm:
        _type: nim
        model_name: meta/llama-3.3-70b-instruct
        temperature: 0.0
     
    workflow:
      _type: agno_personal_finance
      llm_name: nim_llm
      serp_api_tool: serp_api_tool
      verbose: true
      retry_parsing_errors: true
      max_retries: 3

    最后但并非最不重要的一點是,在 agentiq_agno 包中添加新函數 serp_api_tool 后,有必要修改該包的 pyproject.toml 入口點。請注意 aiq_agno_tools 的新入口點:

    [project.entry-points.'aiq.components']
    aiq_agno = "aiq.plugins.agno.register"
    aiq_agno_tools = "aiq.plugins.agno.tools.register"

    第 5 步:安裝并運行新 workflow

    接下來,運行以下命令安裝新 workflow:

    uv pip install -e examples/agno_personal_finance

    在開始工作流之前,請設置兩個 environment variables:

    • NVIDIA_API_KEY,用于訪問 NVIDIA 托管的 NIM 端點
    • SERP_API_KEY,用于搜索工具

    然后調用 aiq run 運行工作流程:

    export NVIDIA_API_KEY=<YOUR_NVIDIA_API_KEY>
    export SERP_API_KEY=<YOUR_SERP_API_KEY>
     
    aiq run --config_file examples/agno_personal_finance/src/aiq_agno_personal_finance/configs/config.yml --input "My financial goal is to retire at age 60.  I am currently 40 years old, working as a Machine Learning engineer at NVIDIA."

    響應示例如下所示:

    Workflow Result:
    ["To create a personalized financial plan for a 40-year-old Machine Learning engineer at NVIDIA with a goal to retire at 60, we'll need to consider several factors, including their current income, expenses, savings, and investment goals.\n\nAssuming the engineer has a stable income and a decent savings rate, here's a possible plan:\n\n1. **Retirement Savings**: Contribute at least 10% to 15% of their income towards retirement accounts such as 401(k) or IRA. NVIDIA may offer a matching program, so it's essential to contribute enough to maximize the match.\n2. **Investment Strategy**: Allocate a significant portion of their portfolio towards low-cost index funds or ETFs, which provide broad diversification and tend to be less volatile. A possible allocation could be:\n\t* 60% Stocks (40% US, 20% International)\n\t* 30% Bonds (20% Government, 10% Corporate)\n\t* 10% Alternatives (Real Estate, Commodities, etc.)\n3. **Savings Rate**: Aim to save at least 20% to 25% of their income towards short-term and long-term goals, including retirement, emergencies, and large purchases.\n4. **Expense Management**: Create a budget that accounts for all necessary expenses, including housing, food, transportation, and insurance. Aim to keep discretionary spending in check and allocate any excess funds towards savings and investments.\n5. **Tax Optimization**: Consider contributing to tax"]

    總結

    NVIDIA Agent Intelligence 工具包 使開發者能夠快速構建、評估、分析和加速復雜的代理式 AI 工作流。它是開源的,具有顯著的可擴展性,使開發者能夠根據不同需求定制其功能。

    本文詳細介紹了如何通過集成 Agno 等代理式框架和構建自定義工作流來增強 Agent 工具包。這一過程展示了工具包的靈活性,并凸顯了其作為企業環境中創新 AI Agent 驅動解決方案的基礎的潛力。

    通過無縫整合新的框架和工作流,Agent 工具包使您能夠突破基于 Agent 的系統的極限,精準高效地適應特定用例。有關功能、配置選項和高級應用程序等更多詳細信息,請參閱官方 文檔

    準備好向我們展示您的能力了嗎?報名參加 NVIDIA Agent Toolkit 黑客松,即有機會贏得 NVIDIA GeForce RTX 5090。

    ?

    0

    標簽

    人人超碰97caoporen国产