You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Quarkus-LangChain4J中以编程方式提供工具?

在Quarkus-LangChain4J中编程式配置工具的问题

原生LangChain4J支持通过编程方式提供工具,但在Quarkus-LangChain4J中找不到对应的实现方式,现有示例仅针对动态工具,与需求不符。

已实现的ToolSpecification构建逻辑

private ToolSpecification createToolFromAction(Action action) {
    var toolname = action.name();
    var toolDescription = action.description();
    Map<String, JsonSchemaElement> params = new HashMap<>();
    action.parameters().forEach(parameter -> {
        params.put(parameter.name(), JsonStringSchema.builder().description(parameter.name()).build());
    });

    return ToolSpecification.builder()
            .name(toolname)
            .description(toolDescription)
            .parameters(JsonObjectSchema.builder().properties(params).build())
            .build();
}

public List<ToolSpecification> createToolSpecificationsFromActions() {
    return actionsRepository.listActions().stream()
            .map(this::createToolFromAction)
            .toList();
}

当前困境

已实现ToolExecutor,但不清楚如何将其与标注了@RegisterAiService的AiService配合使用。

后续尝试与报错

深入代码库后,找到测试示例中的自定义ToolSpecification和ToolExecutor实现:

@Override
public ToolProviderResult provideTools(ToolProviderRequest request) {
    assertNotNull(myServiceWithoutTools);

    ToolSpecification toolSpecification = ToolSpecification.builder()
            .name("get_booking_details")
            .description("Returns booking details")
            .build();
    ToolExecutor toolExecutor = (t, m) -> "0";
    return ToolProviderResult.builder()
            .add(toolSpecification, toolExecutor)
            .build();
}

但该实现会导致所有其他标注@RegisterAiService的接口抛出如下错误:

java.lang.IllegalArgumentException: Either the tools or the tool provider can be configured, but not both!

内容的提问来源于stack exchange,提问作者Christophe Willemsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 03:25:56