File tree Expand file tree Collapse file tree
test/java/com/google/adk/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525import com .google .genai .types .GenerateContentConfig ;
2626import com .google .genai .types .Tool ;
2727import com .google .genai .types .ToolCodeExecution ;
28+ import java .util .Optional ;
2829
2930/**
3031 * A code executor that uses the Model's built-in code executor.
@@ -43,7 +44,7 @@ public CodeExecutionResult executeCode(
4344 /** Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool. */
4445 public void processLlmRequest (LlmRequest .Builder llmRequestBuilder ) {
4546 LlmRequest llmRequest = llmRequestBuilder .build ();
46- if (ModelNameUtils . isGemini2Model (llmRequest .model (). orElse ( null ))) {
47+ if (isBuiltInCodeExecutionSupported (llmRequest .model ())) {
4748 GenerateContentConfig .Builder configBuilder =
4849 llmRequest .config ().map (c -> c .toBuilder ()).orElseGet (GenerateContentConfig ::builder );
4950 ImmutableList .Builder <Tool > toolsBuilder = ImmutableList .<Tool >builder ();
@@ -56,4 +57,10 @@ public void processLlmRequest(LlmRequest.Builder llmRequestBuilder) {
5657 throw new IllegalArgumentException (
5758 "Gemini code execution tool is not supported for model " + llmRequest .model ().orElse ("" ));
5859 }
60+
61+ private static boolean isBuiltInCodeExecutionSupported (Optional <String > modelString ) {
62+ return modelString
63+ .map (m -> ModelNameUtils .isGemini2Model (m ) || ModelNameUtils .isGemini3Model (m ))
64+ .orElse (false );
65+ }
5966}
Original file line number Diff line number Diff line change 2525public final class ModelNameUtils {
2626 private static final String GEMINI_PREFIX = "gemini-" ;
2727 private static final Pattern GEMINI_2_PATTERN = Pattern .compile ("^gemini-2\\ ..*" );
28+ private static final Pattern GEMINI_3_PATTERN = Pattern .compile ("^gemini-3\\ ..*" );
2829 private static final String GEMINI_CLASS = "com.google.adk.models.Gemini" ;
2930 private static final Pattern PATH_PATTERN =
3031 Pattern .compile ("^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$" );
@@ -39,6 +40,10 @@ public static boolean isGemini2Model(String modelString) {
3940 return matchesModelPattern (modelString , GEMINI_2_PATTERN );
4041 }
4142
43+ public static boolean isGemini3Model (String modelString ) {
44+ return matchesModelPattern (modelString , GEMINI_3_PATTERN );
45+ }
46+
4247 private static boolean matchesModelPattern (String modelString , Pattern pattern ) {
4348 if (modelString == null ) {
4449 return false ;
Original file line number Diff line number Diff line change @@ -71,6 +71,42 @@ public void isGemini2Model_withNullModel_returnsFalse() {
7171 assertThat (ModelNameUtils .isGemini2Model (null )).isFalse ();
7272 }
7373
74+ @ Test
75+ public void isGemini3Model_withGemini3Model_returnsTrue () {
76+ assertThat (ModelNameUtils .isGemini3Model ("gemini-3.0-pro" )).isTrue ();
77+ }
78+
79+ @ Test
80+ public void isGemini3Model_withNonGemini3Model_returnsFalse () {
81+ assertThat (ModelNameUtils .isGemini3Model ("gemini-1.5-pro" )).isFalse ();
82+ }
83+
84+ @ Test
85+ public void isGemini3Model_withPathBasedGemini3Model_returnsTrue () {
86+ assertThat (
87+ ModelNameUtils .isGemini3Model (
88+ "projects/test-project/locations/us-central1/publishers/google/models/gemini-3.0-flash" ))
89+ .isTrue ();
90+ }
91+
92+ @ Test
93+ public void isGemini3Model_withPathBasedNonGemini3Model_returnsFalse () {
94+ assertThat (
95+ ModelNameUtils .isGemini3Model (
96+ "projects/test-project/locations/us-central1/publishers/google/models/gemini-1.5-pro" ))
97+ .isFalse ();
98+ }
99+
100+ @ Test
101+ public void isGemini3Model_withApigeeGemini3Model_returnsTrue () {
102+ assertThat (ModelNameUtils .isGemini3Model ("apigee/gemini-3.0-flash" )).isTrue ();
103+ }
104+
105+ @ Test
106+ public void isGemini3Model_withNullModel_returnsFalse () {
107+ assertThat (ModelNameUtils .isGemini3Model (null )).isFalse ();
108+ }
109+
74110 @ Test
75111 public void isGeminiModel_withGeminiModel_returnsTrue () {
76112 assertThat (ModelNameUtils .isGeminiModel ("gemini-1.5-flash" )).isTrue ();
You can’t perform that action at this time.
0 commit comments