org.bsc.langgraph4j.langchain4j.tool.ToolNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of langgraph4j-langchain4j Show documentation
Show all versions of langgraph4j-langchain4j Show documentation
Integration stuff for langchain4j
package org.bsc.langgraph4j.langchain4j.tool;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.ToolExecutionResultMessage;
import dev.langchain4j.service.tool.DefaultToolExecutor;
import dev.langchain4j.service.tool.ToolExecutor;
import static dev.langchain4j.agent.tool.ToolSpecifications.toolSpecificationFrom;
import lombok.NonNull;
import lombok.Value;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public final class ToolNode {
@Value
@Accessors( fluent = true)
static class Specification {
@NonNull
ToolSpecification value;
@NonNull
ToolExecutor executor;
public Specification(@NonNull Object objectWithTool, @NonNull Method method ) {
this.value = toolSpecificationFrom(method);
this.executor = new DefaultToolExecutor(objectWithTool, method);
}
}
public static ToolNode of( Collection