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
10 changes: 0 additions & 10 deletions core/src/main/java/com/google/adk/flows/llmflows/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,6 @@ private static Function<FunctionCall, Maybe<Event>> getFunctionCallMapper(
.toolConfirmation(functionCall.id().map(toolConfirmations::get).orElse(null))
.build();

ToolConfirmation toolConfirmation = toolContext.toolConfirmation().orElse(null);
if (toolConfirmation != null && !toolConfirmation.confirmed()) {
return Maybe.just(
buildResponseEvent(
tool,
ImmutableMap.of("error", "User declined tool execution for " + tool.name()),
toolContext,
invocationContext));
}

Map<String, Object> functionArgs = functionCall.args().orElse(new HashMap<>());

Maybe<Map<String, Object>> maybeFunctionResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ public class RequestConfirmationLlmRequestProcessorTest {
.build()))
.build();

private static final Event USER_DECLINE_EVENT =
Event.builder()
.author("user")
.content(
Content.fromParts(
Part.builder()
.functionResponse(
FunctionResponse.builder()
.id(FUNCTION_CALL_ID)
.name(REQUEST_CONFIRMATION_FUNCTION_CALL_NAME)
.response(ImmutableMap.of("confirmed", false))
.build())
.build()))
.build();

private static final RequestConfirmationLlmRequestProcessor processor =
new RequestConfirmationLlmRequestProcessor();

Expand All @@ -123,30 +108,6 @@ public void runAsync_withConfirmation_callsOriginalFunction() {
assertThat(fr.response()).hasValue(ImmutableMap.of("result", ORIGINAL_FUNCTION_CALL_ARGS));
}

@Test
public void runAsync_withDecline_returnsErrorFunctionResponse() {
LlmAgent agent = createAgentWithEchoTool();
Session session =
Session.builder("session_id")
.events(ImmutableList.of(REQUEST_CONFIRMATION_EVENT, USER_DECLINE_EVENT))
.build();

InvocationContext context = createInvocationContext(agent, session);

RequestProcessor.RequestProcessingResult result =
processor.processRequest(context, LlmRequest.builder().build()).blockingGet();

assertThat(result).isNotNull();
assertThat(result.events()).hasSize(1);
Event event = result.events().iterator().next();
assertThat(event.functionResponses()).hasSize(1);
FunctionResponse fr = event.functionResponses().get(0);
assertThat(fr.id()).hasValue(ORIGINAL_FUNCTION_CALL_ID);
assertThat(fr.name()).hasValue(ECHO_TOOL_NAME);
assertThat(fr.response())
.hasValue(ImmutableMap.of("error", "User declined tool execution for echo_tool"));
}

@Test
public void runAsync_withConfirmationAndToolAlreadyCalled_doesNotCallOriginalFunction() {
LlmAgent agent = createAgentWithEchoTool();
Expand Down