Skip to content
Open
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
16 changes: 13 additions & 3 deletions core/src/main/java/com/google/adk/flows/llmflows/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ public Single<RequestProcessor.RequestProcessingResult> processRequest(
}
LlmAgent agent = (LlmAgent) context.agent();
String modelName =
agent.resolvedModel().model().isPresent()
? agent.resolvedModel().model().get().model()
: agent.resolvedModel().modelName().get();
agent
.resolvedModel()
.model()
.map(model -> model.model())
.orElseGet(
() ->
agent
.resolvedModel()
.modelName()
.orElseThrow(
() ->
new IllegalStateException(
"Both model and modelName are not present in resolvedModel")));

LiveConnectConfig.Builder liveConnectConfigBuilder =
LiveConnectConfig.builder().responseModalities(context.runConfig().responseModalities());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ public Single<RequestProcessingResult> processRequest(
}

// Add the set_model_response tool to handle structured output
SetModelResponseTool setResponseTool = new SetModelResponseTool(agent.outputSchema().get());
SetModelResponseTool setResponseTool =
new SetModelResponseTool(
agent
.outputSchema()
.orElseThrow(
() ->
new IllegalStateException(
"outputSchema should be present when toolsUnion is not empty")));
LlmRequest.Builder builder = request.toBuilder();

return setResponseTool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ public Single<RequestProcessor.RequestProcessingResult> processRequest(
return Single.just(RequestProcessingResult.create(llmRequest, ImmutableList.of()));
}

int finalConfirmationEventIndex = confirmationResult.get().eventIndex();
ConfirmationResult result =
confirmationResult.orElseThrow(
() -> new IllegalStateException("confirmationResult should be present when not empty"));
int finalConfirmationEventIndex = result.eventIndex();
ImmutableMap<String, ToolConfirmation> requestConfirmationFunctionResponses =
confirmationResult.get().responses();
result.responses();
String agentName = invocationContext.agent().name();
ImmutableMap<String, AuthoredFunctionCall> functionCallsById =
functionCallsById(events, agentName);
Expand Down Expand Up @@ -129,10 +132,22 @@ public Single<RequestProcessor.RequestProcessingResult> processRequest(
ofc, functionCallsById, confirmationRequestedIds, agentName))
.ifPresent(
ofc -> {
String functionId =
ofc.id()
.orElseThrow(
() ->
new IllegalStateException(
"Function call should have an ID"));
String confirmationId =
fc.id()
.orElseThrow(
() ->
new IllegalStateException(
"Function call should have an ID"));
toolsToResumeWithConfirmation.put(
ofc.id().get(),
requestConfirmationFunctionResponses.get(fc.id().get()));
toolsToResumeWithArgs.put(ofc.id().get(), ofc);
functionId,
requestConfirmationFunctionResponses.get(confirmationId));
toolsToResumeWithArgs.put(functionId, ofc);
}));

// If all confirmed tools in this event have already been processed, continue
Expand Down
Loading