【NVIDIA AIQ】自定义函数实践

NVIDIA Agent Intelligence Toolkit自定义函数实践

定义工具函数

python 复制代码
import logging

from pydantic import BaseModel
from pydantic import Field
from pydantic import HttpUrl

from aiq.builder.builder import Builder
from aiq.builder.function_info import FunctionInfo
from aiq.cli.register_workflow import register_function
from aiq.data_models.function import FunctionBaseConfig

logger = logging.getLogger(__name__)

# 工具类
class CustomToolConfig(FunctionBaseConfig, name="custom_tool"):
    """ 测试自定义工具调用 """
    

# 注册工具函数
@register_function(config_type=CustomToolConfig)
async def custom_tool(config: CustomToolConfig, builder: Builder):

  	# 工具函数逻辑处理
    async def _custom_tool_test(text: str) -> str:
        return '这是一个自定义工具调用测试${text}'

    # 逻辑导出调用
    yield FunctionInfo.from_fn(
        _custom_tool_test,
        description="这是一个自定义工具调用测试",
    )

注册: 工具导出

  • aiq/tool/register.py
python 复制代码
from . import custom_tool

配置引用

yaml 复制代码
# NVIDIA NeMo Agent Toolkit 黑客松配置
# 支持用户自定义OpenAI兼容API

general:
  use_uvloop: true

functions:
  custom_tool:
    _type: custom_tool
    description: "自定义工具测试"

workflow:
  _type: react_agent
  tool_names:
    - custom_tool
  llm_name: default_llm
  verbose: true
  parse_agent_response_max_retries: 3
  max_iterations: 10

测试验证

输入关键字,触发AI调用

终端调用打印

参考资源

NVIDIA Agent Intelligence Toolkit

Custom Functions

相关推荐
正经教主4 分钟前
Trae Work 提示词使用要求与教程
人工智能
潜龙95278 分钟前
手机自动化测试AI新方案
人工智能·智能手机
我的xiaodoujiao15 分钟前
快速学习Python基础知识详细图文教程14--模块
开发语言·python·学习·测试工具
wdfk_prog18 分钟前
嵌入式面试真题学习笔记系列
笔记·学习·面试
烂蜻蜓19 分钟前
AI入门教程(十):AI API开发:从“会用AI聊天”到“让AI在你的代码里干活”的完整指南
人工智能·ai
残影飞雪19 分钟前
Ollama对话脚本
python
懿路向前21 分钟前
【HarmonyOS学习笔记】2026-07-30 | 小艺开放平台智能体接入实战
笔记·学习·harmonyos
jerryinwuhan22 分钟前
数据预处理技术 2026-2027-1 开篇-课程介绍
大数据·python
吃好睡好便好28 分钟前
MATLAB中图像的线性变换
开发语言·图像处理·学习·计算机视觉·matlab
书签123635 分钟前
产教融合的技术解法:AI数字孪生驱动的校企协同育人系统架构与实践
人工智能·系统架构