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
23 changes: 23 additions & 0 deletions core/src/main/java/com/google/adk/agents/RunConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public enum StreamingMode {
BIDI
}

/**
* Tool execution mode for the runner, when they are multiple tools requested (by the models or
* callbacks).
*
* <p>NONE: default to PARALLEL.
*
* <p>SEQUENTIAL: Multiple tools are executed in the order they are requested.
*
* <p>PARALLEL: Multiple tools are executed in parallel.
*/
public enum ToolExecutionMode {
NONE,
SEQUENTIAL,
PARALLEL
}

public abstract @Nullable SpeechConfig speechConfig();

public abstract ImmutableList<Modality> responseModalities();
Expand All @@ -46,6 +62,8 @@ public enum StreamingMode {

public abstract StreamingMode streamingMode();

public abstract ToolExecutionMode toolExecutionMode();

public abstract @Nullable AudioTranscriptionConfig outputAudioTranscription();

public abstract @Nullable AudioTranscriptionConfig inputAudioTranscription();
Expand All @@ -59,13 +77,15 @@ public static Builder builder() {
.setSaveInputBlobsAsArtifacts(false)
.setResponseModalities(ImmutableList.of())
.setStreamingMode(StreamingMode.NONE)
.setToolExecutionMode(ToolExecutionMode.NONE)
.setMaxLlmCalls(500);
}

public static Builder builder(RunConfig runConfig) {
return new AutoValue_RunConfig.Builder()
.setSaveInputBlobsAsArtifacts(runConfig.saveInputBlobsAsArtifacts())
.setStreamingMode(runConfig.streamingMode())
.setToolExecutionMode(runConfig.toolExecutionMode())
.setMaxLlmCalls(runConfig.maxLlmCalls())
.setResponseModalities(runConfig.responseModalities())
.setSpeechConfig(runConfig.speechConfig())
Expand All @@ -89,6 +109,9 @@ public abstract static class Builder {
@CanIgnoreReturnValue
public abstract Builder setStreamingMode(StreamingMode streamingMode);

@CanIgnoreReturnValue
public abstract Builder setToolExecutionMode(ToolExecutionMode toolExecutionMode);

@CanIgnoreReturnValue
public abstract Builder setOutputAudioTranscription(
@Nullable AudioTranscriptionConfig outputAudioTranscription);
Expand Down
17 changes: 15 additions & 2 deletions core/src/main/java/com/google/adk/flows/llmflows/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.adk.agents.Callbacks.BeforeToolCallback;
import com.google.adk.agents.InvocationContext;
import com.google.adk.agents.LlmAgent;
import com.google.adk.agents.RunConfig.ToolExecutionMode;
import com.google.adk.events.Event;
import com.google.adk.events.EventActions;
import com.google.adk.tools.BaseTool;
Expand Down Expand Up @@ -198,7 +199,13 @@ public static Maybe<Event> handleFunctionCalls(
functionResponseEvents.add(maybeFunctionResponseEvent);
}

return Maybe.merge(functionResponseEvents)
Flowable<Event> functionResponseEventsFlowable;
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
functionResponseEventsFlowable = Maybe.concat(functionResponseEvents);
} else {
functionResponseEventsFlowable = Maybe.merge(functionResponseEvents);
}
return functionResponseEventsFlowable
.toList()
.flatMapMaybe(
events -> {
Expand Down Expand Up @@ -296,7 +303,13 @@ public static Maybe<Event> handleFunctionCallsLive(
responseEvents.add(maybeFunctionResponseEvent);
}

return Maybe.merge(responseEvents)
Flowable<Event> responseEventsFlowable;
if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) {
responseEventsFlowable = Maybe.concat(responseEvents);
} else {
responseEventsFlowable = Maybe.merge(responseEvents);
}
return responseEventsFlowable
.toList()
.flatMapMaybe(
events -> {
Expand Down