【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

相关推荐
badhope1 小时前
Mobile-Skills:移动端技能可视化的创新实践
开发语言·人工智能·git·智能手机·github
吴佳浩2 小时前
GPU 编号进阶:CUDA\_VISIBLE\_DEVICES、多进程与容器化陷阱
人工智能·pytorch·python
吴佳浩3 小时前
GPU 编号错乱踩坑指南:PyTorch cuda 编号与 nvidia-smi 不一致
人工智能·pytorch·nvidia
小饕3 小时前
苏格拉底式提问对抗315 AI投毒:实操指南
网络·人工智能
全栈凯哥3 小时前
18.Python中的导入类完全指南
python
卧蚕土豆3 小时前
【有啥问啥】OpenClaw 安装与使用教程
人工智能·深度学习
GoCodingInMyWay3 小时前
开源好物 26/03
人工智能·开源
AI科技星3 小时前
全尺度角速度统一:基于 v ≡ c 的纯推导与验证
c语言·开发语言·人工智能·opencv·算法·机器学习·数据挖掘
zhangfeng11333 小时前
Windows 的 Git Bash 中使用 md5sum 命令非常简单 md5做文件完整性检测 WinRAR 可以计算文件的 MD5 值
人工智能·windows·git·bash
sunwenjian8863 小时前
Java进阶——IO 流
java·开发语言·python