【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

相关推荐
Elastic 中国社区官方博客几秒前
使用 Elasticsearch + Jina embeddings 进行无监督文档聚类
大数据·人工智能·elasticsearch·搜索引擎·全文检索·jina
2501_921649491 分钟前
2026个人量化交易免费数据API接入:从选型到实操
经验分享·python·金融·api·个人开发·量化交易
熊猫钓鱼>_>3 分钟前
从零构建大模型可调用的Skill:基于Function Calling的完整指南
人工智能·算法·语言模型·架构·agent·skill·functioncall
wgzrmlrm747 分钟前
如何解决ORA-28040没有匹配的验证协议_sqlnet.ora版本兼容设置
jvm·数据库·python
维度攻城狮7 分钟前
pycallgraph2drawio:Python 调用链可视化 + Draw.io 自由编辑
开发语言·python·draw.io·graphviz
陈天伟教授8 分钟前
六种人工智能模型
人工智能
清空mega11 分钟前
动手学深度学习——边界框
人工智能
永霖光电_UVLED15 分钟前
美国能源部(DOE)发布“关键矿产与材料加速器”资助机会
人工智能
舒一笑18 分钟前
技术圈爆火新词:Harness 工程,OpenAI 和 Anthropic 都在卷这个!
人工智能·程序员·设计
极光代码工作室19 分钟前
基于NLP的智能客服系统设计与实现
python·深度学习·机器学习·ai·自然语言处理