Skip to content

chore: Add around tool calling execution #2855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -203,7 +203,7 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess

String toolResult;
try {
toolResult = toolCallback.call(toolInputArguments, toolContext);
toolResult = aroundToolCallingExecution(toolCallback, toolInputArguments, toolContext);
}
catch (ToolExecutionException ex) {
toolResult = this.toolExecutionExceptionProcessor.process(ex);
Expand All @@ -215,6 +215,14 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess
return new InternalToolExecutionResult(new ToolResponseMessage(toolResponses, Map.of()), returnDirect);
}

/**
* Been added to allow for custom behavior around tool execution.
*/
protected String aroundToolCallingExecution(ToolCallback toolCallback, String toolInputArguments,
ToolContext toolContext) {
return toolCallback.call(toolInputArguments, toolContext);
}

private List<Message> buildConversationHistoryAfterToolExecution(List<Message> previousMessages,
AssistantMessage assistantMessage, ToolResponseMessage toolResponseMessage) {
List<Message> messages = new ArrayList<>(previousMessages);
Expand Down