【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

相关推荐
恋猫de小郭1 小时前
AI 正在造就你的「认知卸载」,但是时代如此
前端·人工智能·ai编程
飞哥数智坊9 小时前
我的“龙虾”罢工了!正好对比下GLM、MiniMax、Kimi 3家谁更香
人工智能
风象南10 小时前
很多人说,AI 让技术平权了,小白也能乱杀老师傅 ?
人工智能·后端
董董灿是个攻城狮11 小时前
大模型连载1:了解 Token
人工智能
花酒锄作田12 小时前
使用 pkgutil 实现动态插件系统
python
RoyLin13 小时前
沉睡三十年的标准:HTTP 402、生成式 UI 与智能体原生软件的时代
人工智能
needn15 小时前
TRAE为什么要发布SOLO版本?
人工智能·ai编程
毅航15 小时前
自然语言处理发展史:从规则、统计到深度学习
人工智能·后端
前端付豪16 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
ursazoo16 小时前
写了一份 7000字指南,让 AI 帮我消化每天的信息流
人工智能·开源·github