Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private ToolExecutor getToolExecutor(String methodName) {
toolExecutor = new QuarkusToolExecutor(
new QuarkusToolExecutor.Context(testTool, invokerClassName, methodCreateInfo.methodName(),
methodCreateInfo.argumentMapperClassName(), methodCreateInfo.executionModel(),
methodCreateInfo.returnBehavior()));
methodCreateInfo.returnBehavior(), false));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void populateToolMetadata(Collection<Object> objectsWithTools, Lis
QuarkusToolExecutor.Context executorContext = new QuarkusToolExecutor.Context(objectWithTool,
invokerClassName, methodCreateInfo.methodName(),
methodCreateInfo.argumentMapperClassName(), methodCreateInfo.executionModel(),
methodCreateInfo.returnBehavior());
methodCreateInfo.returnBehavior(), false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be configurable, not just hardcoded to false. But that's something I can have a look at in a subsequent PR, so no worries.

toolExecutors.put(toolSpecification.name(), toolExecutorFactory.create(executorContext));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ChatJsonRPCService(@All List<ChatModel> models, // don't use ChatModel mo
QuarkusToolExecutor.Context executorContext = new QuarkusToolExecutor.Context(objectWithTool,
methodCreateInfo.invokerClassName(), methodCreateInfo.methodName(),
methodCreateInfo.argumentMapperClassName(), methodCreateInfo.executionModel(),
methodCreateInfo.returnBehavior());
methodCreateInfo.returnBehavior(), false);
toolExecutors.put(methodCreateInfo.toolSpecification().name(),
toolExecutorFactory.create(executorContext));
toolSpecifications.add(methodCreateInfo.toolSpecification());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import dev.langchain4j.agent.tool.ReturnBehavior;
import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.exception.ToolExecutionException;
import dev.langchain4j.internal.Json;
import dev.langchain4j.invocation.InvocationContext;
import dev.langchain4j.service.tool.ToolExecutionResult;
Expand All @@ -29,7 +30,8 @@ public class QuarkusToolExecutor implements ToolExecutor {
private final Context context;

public record Context(Object tool, String toolInvokerName, String methodName, String argumentMapperClassName,
ToolMethodCreateInfo.ExecutionModel executionModel, ReturnBehavior returnBehavior) {
ToolMethodCreateInfo.ExecutionModel executionModel, ReturnBehavior returnBehavior,
boolean propagateToolExecutionExceptions) {
}

public interface Wrapper {
Expand Down Expand Up @@ -107,7 +109,7 @@ private ToolExecutionResult invoke(Object[] params, ToolInvoker invokerInstance)
String result;
if (invocationResult instanceof Uni<?>) { // TODO CS
if (io.vertx.core.Context.isOnEventLoopThread()) {
throw new IllegalStateException(
throw new ToolExecutionException(
"Cannot execute tools returning Uni on event loop thread due to a tool executor limitation");
}
result = handleResult(invokerInstance, ((Uni<?>) invocationResult).await().indefinitely());
Expand All @@ -116,12 +118,11 @@ private ToolExecutionResult invoke(Object[] params, ToolInvoker invokerInstance)
}
log.debugv("Tool execution result: {0}", result);
return ToolExecutionResult.builder().result(invocationResult).resultText(result).build();
} catch (ToolExecutionException e) {
throw e;
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
throw (IllegalArgumentException) e;
}
if (e instanceof IllegalStateException) {
throw (IllegalStateException) e;
if (context.propagateToolExecutionExceptions) {
throw new ToolExecutionException(e);
}
log.error("Error while executing tool '" + context.tool.getClass() + "'", e);
return ToolExecutionResult.builder().isError(true).resultText(e.getMessage()).build();
Expand Down
Loading