From 12cd93b392b96ee619630853e1840302a8ee6490 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Tue, 12 May 2026 02:44:03 -0700 Subject: [PATCH] fix: Steps is not optional PiperOrigin-RevId: 914167385 --- .../genai/examples/InteractionBasic.java | 33 +- .../genai/examples/InteractionCreate.java | 33 +- .../examples/InteractionCreateAsync.java | 36 ++- ...InteractionFunctionCallingClientState.java | 37 ++- ...InteractionFunctionCallingServerState.java | 37 ++- .../google/genai/examples/InteractionGet.java | 33 +- ...nteractionMultimodalInputTextAndAudio.java | 12 +- ...nteractionMultimodalInputTextAndImage.java | 12 +- .../InteractionMultimodalResponseAudio.java | 14 +- ...modalResponseAudioWithGenerateContent.java | 14 +- .../InteractionMultimodalResponseImage.java | 14 +- ...modalResponseImageWithGenerateContent.java | 14 +- .../genai/examples/InteractionStateful.java | 29 +- .../genai/examples/InteractionStateless.java | 68 ++-- .../InteractionToolCallWithCodeExecution.java | 35 ++- .../InteractionToolCallWithComputerUse.java | 33 +- .../InteractionToolCallWithFunctions.java | 45 +-- .../InteractionToolCallWithGoogleSearch.java | 35 ++- .../InteractionToolCallWithMcpServer.java | 35 ++- .../InteractionToolCallWithUrlContext.java | 35 ++- .../genai/examples/InteractionWithConfig.java | 33 +- .../CreateAgentInteractionParams.kt | 146 ++++++++- .../CreateModelInteractionParams.kt | 146 ++++++++- .../models/interactions/Interaction.kt | 292 +++++++++--------- 24 files changed, 808 insertions(+), 413 deletions(-) diff --git a/examples/src/main/java/com/google/genai/examples/InteractionBasic.java b/examples/src/main/java/com/google/genai/examples/InteractionBasic.java index 1cd3d78dcdc..bb67785a169 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionBasic.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionBasic.java @@ -70,20 +70,25 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent(text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent(text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } private InteractionBasic() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionCreate.java b/examples/src/main/java/com/google/genai/examples/InteractionCreate.java index 52f4597c5b6..8f1652ee95c 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionCreate.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionCreate.java @@ -77,20 +77,25 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent(text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent(text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } private InteractionCreate() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java b/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java index 19b5144a602..61b9eaa3b75 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java @@ -82,21 +82,27 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent( - text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent( + text -> + System.out.println("Output: " + text.text())); + } + }); + } + } + }); }) .join(); } diff --git a/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingClientState.java b/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingClientState.java index a3f87d86326..f2c9eaef2c4 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingClientState.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingClientState.java @@ -139,7 +139,7 @@ public static void main(String[] args) { String functionCallId = null; String functionName = null; - List steps = response.steps(); + List steps = response.steps().orElse(null); if (steps != null) { for (Step step : steps) { if (step.isFunctionCall()) { @@ -191,21 +191,26 @@ public static void main(String[] args) { Interaction followUpResponse = client.interactions.create(followUpParams); System.out.println("Final response status: " + followUpResponse.status()); - for (Step step : followUpResponse.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content output : contents) { - output - .text() - .ifPresent( - text -> System.out.println("Final Output: " + text.text())); - } - }); - } - } + followUpResponse + .steps() + .ifPresent( + finalSteps -> { + for (Step step : finalSteps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content output : contents) { + output + .text() + .ifPresent( + text -> System.out.println("Final Output: " + text.text())); + } + }); + } + } + }); } else { System.out.println("No function call requested by the model."); } diff --git a/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingServerState.java b/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingServerState.java index 7652c71270d..0fe03c40f4f 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingServerState.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionFunctionCallingServerState.java @@ -123,7 +123,7 @@ public static void main(String[] args) { String functionCallId = null; String functionName = null; - List steps = response.steps(); + List steps = response.steps().orElse(null); if (steps != null) { for (Step step : steps) { if (step.isFunctionCall()) { @@ -170,21 +170,26 @@ public static void main(String[] args) { Interaction followUpResponse = client.interactions.create(followUpParams); System.out.println("Final response status: " + followUpResponse.status()); - for (Step step : followUpResponse.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content output : contents) { - output - .text() - .ifPresent( - text -> System.out.println("Final Output: " + text.text())); - } - }); - } - } + followUpResponse + .steps() + .ifPresent( + finalSteps -> { + for (Step step : finalSteps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content output : contents) { + output + .text() + .ifPresent( + text -> System.out.println("Final Output: " + text.text())); + } + }); + } + } + }); } else { System.out.println("No function call requested by the model."); } diff --git a/examples/src/main/java/com/google/genai/examples/InteractionGet.java b/examples/src/main/java/com/google/genai/examples/InteractionGet.java index f19f5566741..cbf5b10a585 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionGet.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionGet.java @@ -75,20 +75,25 @@ public static void main(String[] args) { System.out.println("Status: " + retrievedInteraction.status()); // Print the text outputs from the retrieved interaction. - for (Step step : retrievedInteraction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent(text -> System.out.println("Output: " + text.text())); - } - }); - } - } + retrievedInteraction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent(text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } private InteractionGet() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java index 1e5b582b0b9..d440e0fb957 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java @@ -74,10 +74,14 @@ private static void createInteractions(Client client) { Interaction interaction = client.interactions.create(params); - List steps = interaction.steps(); - for (int i = 0; i < steps.size(); i++) { - System.out.println("Step " + (i + 1) + ": " + steps.get(i)); - } + interaction + .steps() + .ifPresent( + steps -> { + for (int i = 0; i < steps.size(); i++) { + System.out.println("Step " + (i + 1) + ": " + steps.get(i)); + } + }); } public static void main(String[] args) { diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndImage.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndImage.java index 68bb9ab5e71..5fe1c1a2ec0 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndImage.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndImage.java @@ -74,10 +74,14 @@ private static void createInteractions(Client client) { Interaction interaction = client.interactions.create(params); - List steps = interaction.steps(); - for (int i = 0; i < steps.size(); i++) { - System.out.println("Step " + (i + 1) + ": " + steps.get(i)); - } + interaction + .steps() + .ifPresent( + steps -> { + for (int i = 0; i < steps.size(); i++) { + System.out.println("Step " + (i + 1) + ": " + steps.get(i)); + } + }); } public static void main(String[] args) { diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudio.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudio.java index 8083d9735b8..2f82cfa2f62 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudio.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudio.java @@ -46,7 +46,6 @@ import com.google.genai.interactions.models.interactions.GenerationConfig; import com.google.genai.interactions.models.interactions.Interaction; import com.google.genai.interactions.models.interactions.SpeechConfig; -import com.google.genai.interactions.models.interactions.Step; import java.util.Arrays; /** Example of generating audio using the Interactions API. */ @@ -69,11 +68,14 @@ private static void createInteractions(Client client) { Interaction interaction = client.interactions.create(params); - int i = 1; - for (Step step : interaction.steps()) { - System.out.println("Output " + i + ": " + step); - i++; - } + interaction + .steps() + .ifPresent( + outputs -> { + for (int i = 0; i < outputs.size(); i++) { + System.out.println("Output " + (i + 1) + ": " + outputs.get(i)); + } + }); } public static void main(String[] args) { diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java index f6a5c2f39c1..78ffc6f781b 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java @@ -87,11 +87,15 @@ public static void main(String[] args) { System.out.println("Interaction ID: " + interaction.id()); System.out.println("Status: " + interaction.status()); - int i = 1; - for (Step step : interaction.steps()) { - System.out.println("Step " + i + ": " + step); - i++; - } + interaction + .steps() + .ifPresent( + steps -> { + for (int i = 0; i < steps.size(); i++) { + Step step = steps.get(i); + System.out.println("Step " + (i + 1) + ": " + step); + } + }); System.out.println("[Generate Content] Start generate content"); GenerateContentConfig config = diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java index 2476809c5ee..8933a45e608 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java @@ -44,7 +44,6 @@ import com.google.genai.interactions.models.interactions.CreateModelInteractionParams; import com.google.genai.interactions.models.interactions.CreateModelInteractionParams.ResponseModality; import com.google.genai.interactions.models.interactions.Interaction; -import com.google.genai.interactions.models.interactions.Step; import java.util.Arrays; /** Example of generating an image using the Interactions API. */ @@ -61,11 +60,14 @@ private static void createInteractions(Client client) { Interaction interaction = client.interactions.create(params); - int i = 1; - for (Step step : interaction.steps()) { - System.out.println("Output " + i + ": " + step); - i++; - } + interaction + .steps() + .ifPresent( + outputs -> { + for (int i = 0; i < outputs.size(); i++) { + System.out.println("Output " + (i + 1) + ": " + outputs.get(i)); + } + }); } public static void main(String[] args) { diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java index 6927477b9ea..fa6b170a706 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java @@ -79,11 +79,15 @@ public static void main(String[] args) { System.out.println("Interaction ID: " + interaction.id()); System.out.println("Status: " + interaction.status()); - int i = 1; - for (Step step : interaction.steps()) { - System.out.println("Step " + i + ": " + step); - i++; - } + interaction + .steps() + .ifPresent( + steps -> { + for (int i = 0; i < steps.size(); i++) { + Step step = steps.get(i); + System.out.println("Step " + (i + 1) + ": " + step); + } + }); System.out.println("[Generate Content] Start generate content"); GenerateContentConfig config = diff --git a/examples/src/main/java/com/google/genai/examples/InteractionStateful.java b/examples/src/main/java/com/google/genai/examples/InteractionStateful.java index a74def6597d..11a6c8b7efb 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionStateful.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionStateful.java @@ -83,18 +83,23 @@ public static void main(String[] args) { } private static void printOutput(Interaction interaction) { - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content.text().ifPresent(text -> System.out.println(text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content.text().ifPresent(text -> System.out.println(text.text())); + } + }); + } + } + }); } private InteractionStateful() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionStateless.java b/examples/src/main/java/com/google/genai/examples/InteractionStateless.java index af0037da85f..34f2190f881 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionStateless.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionStateless.java @@ -90,20 +90,33 @@ public static void main(String[] args) { Interaction response1 = client.interactions.create(params1); System.out.println("Model: "); + response1 + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content output : contents) { + output.text().ifPresent(text -> System.out.println(text.text())); + } + }); + } + } + }); + // Add model response to history - for (Step step : response1.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content output : contents) { - output.text().ifPresent(text -> System.out.println(text.text())); - } - }); - } - conversationHistory.add(step); - } + response1 + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + conversationHistory.add(step); + } + }); // Add next user message conversationHistory.add( @@ -129,18 +142,23 @@ public static void main(String[] args) { Interaction response2 = client.interactions.create(params2); System.out.println("Model: "); - for (Step step : response2.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content output : contents) { - output.text().ifPresent(text -> System.out.println(text.text())); - } - }); - } - } + response2 + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content output : contents) { + output.text().ifPresent(text -> System.out.println(text.text())); + } + }); + } + } + }); } private InteractionStateless() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithCodeExecution.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithCodeExecution.java index 79cbffc508a..1f5d0d92fae 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithCodeExecution.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithCodeExecution.java @@ -74,21 +74,26 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent( - text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent( + text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } catch (RuntimeException e) { System.err.println("Error creating interaction: " + e.getMessage()); e.printStackTrace(); diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java index 83c32cb8561..5b00c9bc05d 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java @@ -81,20 +81,25 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent(text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent(text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } private InteractionToolCallWithComputerUse() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java index 9705ca33253..8729abb4fdb 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java @@ -123,26 +123,31 @@ public static void main(String[] args) { System.out.println("Interaction ID: " + interaction.id()); System.out.println("Status: " + interaction.status()); - for (Step step : interaction.steps()) { - if (step.isFunctionCall()) { - FunctionCallStep fc = step.asFunctionCall(); - System.out.println("Function Call: " + fc.name()); - System.out.println("Arguments: " + fc.arguments()); - } else if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content output : contents) { - output - .text() - .ifPresent( - text -> - System.out.println("Output Text: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isFunctionCall()) { + FunctionCallStep fc = step.asFunctionCall(); + System.out.println("Function Call: " + fc.name()); + System.out.println("Arguments: " + fc.arguments()); + } else if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content output : contents) { + output + .text() + .ifPresent( + text -> + System.out.println("Output Text: " + text.text())); + } + }); + } + } + }); } private InteractionToolCallWithFunctions() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithGoogleSearch.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithGoogleSearch.java index 4520ee36e63..e4179d405a3 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithGoogleSearch.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithGoogleSearch.java @@ -76,21 +76,26 @@ public static void main(String[] args) { System.out.println("Interaction ID: " + interaction.id()); System.out.println("Status: " + interaction.status()); - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent( - text -> System.out.println("Output Text: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent( + text -> System.out.println("Output Text: " + text.text())); + } + }); + } + } + }); } private InteractionToolCallWithGoogleSearch() {} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java index e554058a3b8..c1660861925 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java @@ -83,21 +83,26 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent( - text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent( + text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } catch (RuntimeException e) { System.err.println("Error creating interaction: " + e.getMessage()); e.printStackTrace(); diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java index c4b38865ef4..7ffdd80a78f 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java @@ -77,21 +77,26 @@ public static void main(String[] args) { System.out.println("Status: " + interaction.status()); // Print the text outputs from the interaction. - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent( - text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent( + text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } catch (RuntimeException e) { System.err.println("Error creating interaction: " + e.getMessage()); e.printStackTrace(); diff --git a/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java b/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java index 0624c37bf5c..846b1982d19 100644 --- a/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java +++ b/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java @@ -70,20 +70,25 @@ public static void main(String[] args) { System.out.println("Interaction ID: " + interaction.id()); System.out.println("Status: " + interaction.status()); - for (Step step : interaction.steps()) { - if (step.isModelOutput()) { - step.asModelOutput() - .content() - .ifPresent( - contents -> { - for (Content content : contents) { - content - .text() - .ifPresent(text -> System.out.println("Output: " + text.text())); - } - }); - } - } + interaction + .steps() + .ifPresent( + steps -> { + for (Step step : steps) { + if (step.isModelOutput()) { + step.asModelOutput() + .content() + .ifPresent( + contents -> { + for (Content content : contents) { + content + .text() + .ifPresent(text -> System.out.println("Output: " + text.text())); + } + }); + } + } + }); } private InteractionWithConfig() {} diff --git a/src/main/java/com/google/genai/interactions/models/interactions/CreateAgentInteractionParams.kt b/src/main/java/com/google/genai/interactions/models/interactions/CreateAgentInteractionParams.kt index 316778dbc52..94cd32d078d 100644 --- a/src/main/java/com/google/genai/interactions/models/interactions/CreateAgentInteractionParams.kt +++ b/src/main/java/com/google/genai/interactions/models/interactions/CreateAgentInteractionParams.kt @@ -65,6 +65,7 @@ private constructor( private val role: JsonField, private val serviceTier: JsonField, private val status: JsonField, + private val steps: JsonField>, private val store: JsonField, private val stream: JsonField, private val systemInstruction: JsonField, @@ -106,6 +107,7 @@ private constructor( @ExcludeMissing serviceTier: JsonField = JsonMissing.of(), @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("steps") @ExcludeMissing steps: JsonField> = JsonMissing.of(), @JsonProperty("store") @ExcludeMissing store: JsonField = JsonMissing.of(), @JsonProperty("stream") @ExcludeMissing stream: JsonField = JsonMissing.of(), @JsonProperty("system_instruction") @@ -133,6 +135,7 @@ private constructor( role, serviceTier, status, + steps, store, stream, systemInstruction, @@ -251,6 +254,14 @@ private constructor( */ fun status(): Optional = status.getOptional("status") + /** + * Output only. The steps that make up the interaction. + * + * @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun steps(): Optional> = steps.getOptional("steps") + /** * Input only. Whether to store the response and request for later retrieval. * @@ -417,6 +428,13 @@ private constructor( */ @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + /** + * Returns the raw JSON value of [steps]. + * + * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps + /** * Returns the raw JSON value of [store]. * @@ -513,6 +531,7 @@ private constructor( private var role: JsonField = JsonMissing.of() private var serviceTier: JsonField = JsonMissing.of() private var status: JsonField = JsonMissing.of() + private var steps: JsonField>? = null private var store: JsonField = JsonMissing.of() private var stream: JsonField = JsonMissing.of() private var systemInstruction: JsonField = JsonMissing.of() @@ -538,6 +557,7 @@ private constructor( role = createAgentInteractionParams.role serviceTier = createAgentInteractionParams.serviceTier status = createAgentInteractionParams.status + steps = createAgentInteractionParams.steps.map { it.toMutableList() } store = createAgentInteractionParams.store stream = createAgentInteractionParams.stream systemInstruction = createAgentInteractionParams.systemInstruction @@ -796,6 +816,125 @@ private constructor( */ fun status(status: JsonField) = apply { this.status = status } + /** Output only. The steps that make up the interaction. */ + fun steps(steps: List) = steps(JsonField.of(steps)) + + /** + * Sets [Builder.steps] to an arbitrary JSON value. + * + * You should usually call [Builder.steps] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun steps(steps: JsonField>) = apply { + this.steps = steps.map { it.toMutableList() } + } + + /** + * Adds a single [Step] to [steps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStep(step: Step) = apply { + steps = + (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } + } + + /** Alias for calling [addStep] with `Step.ofUserInput(userInput)`. */ + fun addStep(userInput: UserInputStep) = addStep(Step.ofUserInput(userInput)) + + /** Alias for calling [addStep] with `Step.ofModelOutput(modelOutput)`. */ + fun addStep(modelOutput: ModelOutputStep) = addStep(Step.ofModelOutput(modelOutput)) + + /** Alias for calling [addStep] with `Step.ofThought(thought)`. */ + fun addStep(thought: ThoughtStep) = addStep(Step.ofThought(thought)) + + /** Alias for calling [addStep] with `Step.ofFunctionCall(functionCall)`. */ + fun addStep(functionCall: FunctionCallStep) = addStep(Step.ofFunctionCall(functionCall)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionCall(codeExecutionCall)`. */ + fun addStep(codeExecutionCall: CodeExecutionCallStep) = + addStep(Step.ofCodeExecutionCall(codeExecutionCall)) + + /** Alias for calling [addStep] with `Step.ofUrlContextCall(urlContextCall)`. */ + fun addStep(urlContextCall: UrlContextCallStep) = + addStep(Step.ofUrlContextCall(urlContextCall)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolCall(mcpServerToolCall)`. */ + fun addStep(mcpServerToolCall: McpServerToolCallStep) = + addStep(Step.ofMcpServerToolCall(mcpServerToolCall)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchCall(googleSearchCall)`. */ + fun addStep(googleSearchCall: GoogleSearchCallStep) = + addStep(Step.ofGoogleSearchCall(googleSearchCall)) + + /** Alias for calling [addStep] with `Step.ofFileSearchCall(fileSearchCall)`. */ + fun addStep(fileSearchCall: FileSearchCallStep) = + addStep(Step.ofFileSearchCall(fileSearchCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addFileSearchCallStep(id: String) = addStep(FileSearchCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsCall(googleMapsCall)`. */ + fun addStep(googleMapsCall: GoogleMapsCallStep) = + addStep(Step.ofGoogleMapsCall(googleMapsCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * GoogleMapsCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addGoogleMapsCallStep(id: String) = addStep(GoogleMapsCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofFunctionResult(functionResult)`. */ + fun addStep(functionResult: FunctionResultStep) = + addStep(Step.ofFunctionResult(functionResult)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionResult(codeExecutionResult)`. */ + fun addStep(codeExecutionResult: CodeExecutionResultStep) = + addStep(Step.ofCodeExecutionResult(codeExecutionResult)) + + /** Alias for calling [addStep] with `Step.ofUrlContextResult(urlContextResult)`. */ + fun addStep(urlContextResult: UrlContextResultStep) = + addStep(Step.ofUrlContextResult(urlContextResult)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchResult(googleSearchResult)`. */ + fun addStep(googleSearchResult: GoogleSearchResultStep) = + addStep(Step.ofGoogleSearchResult(googleSearchResult)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolResult(mcpServerToolResult)`. */ + fun addStep(mcpServerToolResult: McpServerToolResultStep) = + addStep(Step.ofMcpServerToolResult(mcpServerToolResult)) + + /** Alias for calling [addStep] with `Step.ofFileSearchResult(fileSearchResult)`. */ + fun addStep(fileSearchResult: FileSearchResultStep) = + addStep(Step.ofFileSearchResult(fileSearchResult)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchResultStep.builder() + * .callId(callId) + * .build() + * ``` + */ + fun addFileSearchResultStep(callId: String) = + addStep(FileSearchResultStep.builder().callId(callId).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsResult(googleMapsResult)`. */ + fun addStep(googleMapsResult: GoogleMapsResultStep) = + addStep(Step.ofGoogleMapsResult(googleMapsResult)) + /** Input only. Whether to store the response and request for later retrieval. */ fun store(store: Boolean) = store(JsonField.of(store)) @@ -974,6 +1113,7 @@ private constructor( role, serviceTier, status, + (steps ?: JsonMissing.of()).map { it.toImmutable() }, store, stream, systemInstruction, @@ -1005,6 +1145,7 @@ private constructor( role() serviceTier().ifPresent { it.validate() } status().ifPresent { it.validate() } + steps().ifPresent { it.forEach { it.validate() } } store() stream() systemInstruction() @@ -1043,6 +1184,7 @@ private constructor( (if (role.asKnown().isPresent) 1 else 0) + (serviceTier.asKnown().getOrNull()?.validity() ?: 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + + (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (store.asKnown().isPresent) 1 else 0) + (if (stream.asKnown().isPresent) 1 else 0) + (if (systemInstruction.asKnown().isPresent) 1 else 0) + @@ -3073,6 +3215,7 @@ private constructor( role == other.role && serviceTier == other.serviceTier && status == other.status && + steps == other.steps && store == other.store && stream == other.stream && systemInstruction == other.systemInstruction && @@ -3098,6 +3241,7 @@ private constructor( role, serviceTier, status, + steps, store, stream, systemInstruction, @@ -3112,5 +3256,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "CreateAgentInteractionParams{agent=$agent, input=$input, id=$id, agentConfig=$agentConfig, background=$background, created=$created, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, status=$status, store=$store, stream=$stream, systemInstruction=$systemInstruction, tools=$tools, updated=$updated, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" + "CreateAgentInteractionParams{agent=$agent, input=$input, id=$id, agentConfig=$agentConfig, background=$background, created=$created, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, status=$status, steps=$steps, store=$store, stream=$stream, systemInstruction=$systemInstruction, tools=$tools, updated=$updated, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" } diff --git a/src/main/java/com/google/genai/interactions/models/interactions/CreateModelInteractionParams.kt b/src/main/java/com/google/genai/interactions/models/interactions/CreateModelInteractionParams.kt index 2467673aa03..8594fce1a80 100644 --- a/src/main/java/com/google/genai/interactions/models/interactions/CreateModelInteractionParams.kt +++ b/src/main/java/com/google/genai/interactions/models/interactions/CreateModelInteractionParams.kt @@ -65,6 +65,7 @@ private constructor( private val role: JsonField, private val serviceTier: JsonField, private val status: JsonField, + private val steps: JsonField>, private val store: JsonField, private val stream: JsonField, private val systemInstruction: JsonField, @@ -106,6 +107,7 @@ private constructor( @ExcludeMissing serviceTier: JsonField = JsonMissing.of(), @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("steps") @ExcludeMissing steps: JsonField> = JsonMissing.of(), @JsonProperty("store") @ExcludeMissing store: JsonField = JsonMissing.of(), @JsonProperty("stream") @ExcludeMissing stream: JsonField = JsonMissing.of(), @JsonProperty("system_instruction") @@ -133,6 +135,7 @@ private constructor( role, serviceTier, status, + steps, store, stream, systemInstruction, @@ -253,6 +256,14 @@ private constructor( */ fun status(): Optional = status.getOptional("status") + /** + * Output only. The steps that make up the interaction. + * + * @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun steps(): Optional> = steps.getOptional("steps") + /** * Input only. Whether to store the response and request for later retrieval. * @@ -420,6 +431,13 @@ private constructor( */ @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + /** + * Returns the raw JSON value of [steps]. + * + * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps + /** * Returns the raw JSON value of [store]. * @@ -516,6 +534,7 @@ private constructor( private var role: JsonField = JsonMissing.of() private var serviceTier: JsonField = JsonMissing.of() private var status: JsonField = JsonMissing.of() + private var steps: JsonField>? = null private var store: JsonField = JsonMissing.of() private var stream: JsonField = JsonMissing.of() private var systemInstruction: JsonField = JsonMissing.of() @@ -541,6 +560,7 @@ private constructor( role = createModelInteractionParams.role serviceTier = createModelInteractionParams.serviceTier status = createModelInteractionParams.status + steps = createModelInteractionParams.steps.map { it.toMutableList() } store = createModelInteractionParams.store stream = createModelInteractionParams.stream systemInstruction = createModelInteractionParams.systemInstruction @@ -796,6 +816,125 @@ private constructor( */ fun status(status: JsonField) = apply { this.status = status } + /** Output only. The steps that make up the interaction. */ + fun steps(steps: List) = steps(JsonField.of(steps)) + + /** + * Sets [Builder.steps] to an arbitrary JSON value. + * + * You should usually call [Builder.steps] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun steps(steps: JsonField>) = apply { + this.steps = steps.map { it.toMutableList() } + } + + /** + * Adds a single [Step] to [steps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStep(step: Step) = apply { + steps = + (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } + } + + /** Alias for calling [addStep] with `Step.ofUserInput(userInput)`. */ + fun addStep(userInput: UserInputStep) = addStep(Step.ofUserInput(userInput)) + + /** Alias for calling [addStep] with `Step.ofModelOutput(modelOutput)`. */ + fun addStep(modelOutput: ModelOutputStep) = addStep(Step.ofModelOutput(modelOutput)) + + /** Alias for calling [addStep] with `Step.ofThought(thought)`. */ + fun addStep(thought: ThoughtStep) = addStep(Step.ofThought(thought)) + + /** Alias for calling [addStep] with `Step.ofFunctionCall(functionCall)`. */ + fun addStep(functionCall: FunctionCallStep) = addStep(Step.ofFunctionCall(functionCall)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionCall(codeExecutionCall)`. */ + fun addStep(codeExecutionCall: CodeExecutionCallStep) = + addStep(Step.ofCodeExecutionCall(codeExecutionCall)) + + /** Alias for calling [addStep] with `Step.ofUrlContextCall(urlContextCall)`. */ + fun addStep(urlContextCall: UrlContextCallStep) = + addStep(Step.ofUrlContextCall(urlContextCall)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolCall(mcpServerToolCall)`. */ + fun addStep(mcpServerToolCall: McpServerToolCallStep) = + addStep(Step.ofMcpServerToolCall(mcpServerToolCall)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchCall(googleSearchCall)`. */ + fun addStep(googleSearchCall: GoogleSearchCallStep) = + addStep(Step.ofGoogleSearchCall(googleSearchCall)) + + /** Alias for calling [addStep] with `Step.ofFileSearchCall(fileSearchCall)`. */ + fun addStep(fileSearchCall: FileSearchCallStep) = + addStep(Step.ofFileSearchCall(fileSearchCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addFileSearchCallStep(id: String) = addStep(FileSearchCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsCall(googleMapsCall)`. */ + fun addStep(googleMapsCall: GoogleMapsCallStep) = + addStep(Step.ofGoogleMapsCall(googleMapsCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * GoogleMapsCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addGoogleMapsCallStep(id: String) = addStep(GoogleMapsCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofFunctionResult(functionResult)`. */ + fun addStep(functionResult: FunctionResultStep) = + addStep(Step.ofFunctionResult(functionResult)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionResult(codeExecutionResult)`. */ + fun addStep(codeExecutionResult: CodeExecutionResultStep) = + addStep(Step.ofCodeExecutionResult(codeExecutionResult)) + + /** Alias for calling [addStep] with `Step.ofUrlContextResult(urlContextResult)`. */ + fun addStep(urlContextResult: UrlContextResultStep) = + addStep(Step.ofUrlContextResult(urlContextResult)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchResult(googleSearchResult)`. */ + fun addStep(googleSearchResult: GoogleSearchResultStep) = + addStep(Step.ofGoogleSearchResult(googleSearchResult)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolResult(mcpServerToolResult)`. */ + fun addStep(mcpServerToolResult: McpServerToolResultStep) = + addStep(Step.ofMcpServerToolResult(mcpServerToolResult)) + + /** Alias for calling [addStep] with `Step.ofFileSearchResult(fileSearchResult)`. */ + fun addStep(fileSearchResult: FileSearchResultStep) = + addStep(Step.ofFileSearchResult(fileSearchResult)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchResultStep.builder() + * .callId(callId) + * .build() + * ``` + */ + fun addFileSearchResultStep(callId: String) = + addStep(FileSearchResultStep.builder().callId(callId).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsResult(googleMapsResult)`. */ + fun addStep(googleMapsResult: GoogleMapsResultStep) = + addStep(Step.ofGoogleMapsResult(googleMapsResult)) + /** Input only. Whether to store the response and request for later retrieval. */ fun store(store: Boolean) = store(JsonField.of(store)) @@ -974,6 +1113,7 @@ private constructor( role, serviceTier, status, + (steps ?: JsonMissing.of()).map { it.toImmutable() }, store, stream, systemInstruction, @@ -1005,6 +1145,7 @@ private constructor( role() serviceTier().ifPresent { it.validate() } status().ifPresent { it.validate() } + steps().ifPresent { it.forEach { it.validate() } } store() stream() systemInstruction() @@ -1043,6 +1184,7 @@ private constructor( (if (role.asKnown().isPresent) 1 else 0) + (serviceTier.asKnown().getOrNull()?.validity() ?: 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + + (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (store.asKnown().isPresent) 1 else 0) + (if (stream.asKnown().isPresent) 1 else 0) + (if (systemInstruction.asKnown().isPresent) 1 else 0) + @@ -2747,6 +2889,7 @@ private constructor( role == other.role && serviceTier == other.serviceTier && status == other.status && + steps == other.steps && store == other.store && stream == other.stream && systemInstruction == other.systemInstruction && @@ -2772,6 +2915,7 @@ private constructor( role, serviceTier, status, + steps, store, stream, systemInstruction, @@ -2786,5 +2930,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "CreateModelInteractionParams{input=$input, model=$model, id=$id, background=$background, created=$created, generationConfig=$generationConfig, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, status=$status, store=$store, stream=$stream, systemInstruction=$systemInstruction, tools=$tools, updated=$updated, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" + "CreateModelInteractionParams{input=$input, model=$model, id=$id, background=$background, created=$created, generationConfig=$generationConfig, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, status=$status, steps=$steps, store=$store, stream=$stream, systemInstruction=$systemInstruction, tools=$tools, updated=$updated, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" } diff --git a/src/main/java/com/google/genai/interactions/models/interactions/Interaction.kt b/src/main/java/com/google/genai/interactions/models/interactions/Interaction.kt index e5b9b43ebe4..f13f058645a 100644 --- a/src/main/java/com/google/genai/interactions/models/interactions/Interaction.kt +++ b/src/main/java/com/google/genai/interactions/models/interactions/Interaction.kt @@ -55,7 +55,6 @@ private constructor( private val id: JsonField, private val created: JsonField, private val status: JsonField, - private val steps: JsonField>, private val updated: JsonField, private val agent: JsonField, private val agentConfig: JsonField, @@ -68,6 +67,7 @@ private constructor( private val responseModalities: JsonField>, private val role: JsonField, private val serviceTier: JsonField, + private val steps: JsonField>, private val systemInstruction: JsonField, private val tools: JsonField>, private val usage: JsonField, @@ -82,7 +82,6 @@ private constructor( @ExcludeMissing created: JsonField = JsonMissing.of(), @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), - @JsonProperty("steps") @ExcludeMissing steps: JsonField> = JsonMissing.of(), @JsonProperty("updated") @ExcludeMissing updated: JsonField = JsonMissing.of(), @@ -111,6 +110,7 @@ private constructor( @JsonProperty("service_tier") @ExcludeMissing serviceTier: JsonField = JsonMissing.of(), + @JsonProperty("steps") @ExcludeMissing steps: JsonField> = JsonMissing.of(), @JsonProperty("system_instruction") @ExcludeMissing systemInstruction: JsonField = JsonMissing.of(), @@ -123,7 +123,6 @@ private constructor( id, created, status, - steps, updated, agent, agentConfig, @@ -136,6 +135,7 @@ private constructor( responseModalities, role, serviceTier, + steps, systemInstruction, tools, usage, @@ -168,14 +168,6 @@ private constructor( */ fun status(): Status = status.getRequired("status") - /** - * Required. Output only. The steps that make up the interaction. - * - * @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun steps(): List = steps.getRequired("steps") - /** * Required. Output only. The time at which the response was last updated in ISO 8601 format * (YYYY-MM-DDThh:mm:ssZ). @@ -278,6 +270,14 @@ private constructor( */ fun serviceTier(): Optional = serviceTier.getOptional("service_tier") + /** + * Output only. The steps that make up the interaction. + * + * @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun steps(): Optional> = steps.getOptional("steps") + /** * System instruction for the interaction. * @@ -331,13 +331,6 @@ private constructor( */ @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status - /** - * Returns the raw JSON value of [steps]. - * - * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps - /** * Returns the raw JSON value of [updated]. * @@ -443,6 +436,13 @@ private constructor( @ExcludeMissing fun _serviceTier(): JsonField = serviceTier + /** + * Returns the raw JSON value of [steps]. + * + * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps + /** * Returns the raw JSON value of [systemInstruction]. * @@ -498,7 +498,6 @@ private constructor( * .id() * .created() * .status() - * .steps() * .updated() * ``` */ @@ -511,7 +510,6 @@ private constructor( private var id: JsonField? = null private var created: JsonField? = null private var status: JsonField? = null - private var steps: JsonField>? = null private var updated: JsonField? = null private var agent: JsonField = JsonMissing.of() private var agentConfig: JsonField = JsonMissing.of() @@ -524,6 +522,7 @@ private constructor( private var responseModalities: JsonField>? = null private var role: JsonField = JsonMissing.of() private var serviceTier: JsonField = JsonMissing.of() + private var steps: JsonField>? = null private var systemInstruction: JsonField = JsonMissing.of() private var tools: JsonField>? = null private var usage: JsonField = JsonMissing.of() @@ -535,7 +534,6 @@ private constructor( id = interaction.id created = interaction.created status = interaction.status - steps = interaction.steps.map { it.toMutableList() } updated = interaction.updated agent = interaction.agent agentConfig = interaction.agentConfig @@ -548,6 +546,7 @@ private constructor( responseModalities = interaction.responseModalities.map { it.toMutableList() } role = interaction.role serviceTier = interaction.serviceTier + steps = interaction.steps.map { it.toMutableList() } systemInstruction = interaction.systemInstruction tools = interaction.tools.map { it.toMutableList() } usage = interaction.usage @@ -592,125 +591,6 @@ private constructor( */ fun status(status: JsonField) = apply { this.status = status } - /** Required. Output only. The steps that make up the interaction. */ - fun steps(steps: List) = steps(JsonField.of(steps)) - - /** - * Sets [Builder.steps] to an arbitrary JSON value. - * - * You should usually call [Builder.steps] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun steps(steps: JsonField>) = apply { - this.steps = steps.map { it.toMutableList() } - } - - /** - * Adds a single [Step] to [steps]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addStep(step: Step) = apply { - steps = - (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } - } - - /** Alias for calling [addStep] with `Step.ofUserInput(userInput)`. */ - fun addStep(userInput: UserInputStep) = addStep(Step.ofUserInput(userInput)) - - /** Alias for calling [addStep] with `Step.ofModelOutput(modelOutput)`. */ - fun addStep(modelOutput: ModelOutputStep) = addStep(Step.ofModelOutput(modelOutput)) - - /** Alias for calling [addStep] with `Step.ofThought(thought)`. */ - fun addStep(thought: ThoughtStep) = addStep(Step.ofThought(thought)) - - /** Alias for calling [addStep] with `Step.ofFunctionCall(functionCall)`. */ - fun addStep(functionCall: FunctionCallStep) = addStep(Step.ofFunctionCall(functionCall)) - - /** Alias for calling [addStep] with `Step.ofCodeExecutionCall(codeExecutionCall)`. */ - fun addStep(codeExecutionCall: CodeExecutionCallStep) = - addStep(Step.ofCodeExecutionCall(codeExecutionCall)) - - /** Alias for calling [addStep] with `Step.ofUrlContextCall(urlContextCall)`. */ - fun addStep(urlContextCall: UrlContextCallStep) = - addStep(Step.ofUrlContextCall(urlContextCall)) - - /** Alias for calling [addStep] with `Step.ofMcpServerToolCall(mcpServerToolCall)`. */ - fun addStep(mcpServerToolCall: McpServerToolCallStep) = - addStep(Step.ofMcpServerToolCall(mcpServerToolCall)) - - /** Alias for calling [addStep] with `Step.ofGoogleSearchCall(googleSearchCall)`. */ - fun addStep(googleSearchCall: GoogleSearchCallStep) = - addStep(Step.ofGoogleSearchCall(googleSearchCall)) - - /** Alias for calling [addStep] with `Step.ofFileSearchCall(fileSearchCall)`. */ - fun addStep(fileSearchCall: FileSearchCallStep) = - addStep(Step.ofFileSearchCall(fileSearchCall)) - - /** - * Alias for calling [addStep] with the following: - * ```java - * FileSearchCallStep.builder() - * .id(id) - * .build() - * ``` - */ - fun addFileSearchCallStep(id: String) = addStep(FileSearchCallStep.builder().id(id).build()) - - /** Alias for calling [addStep] with `Step.ofGoogleMapsCall(googleMapsCall)`. */ - fun addStep(googleMapsCall: GoogleMapsCallStep) = - addStep(Step.ofGoogleMapsCall(googleMapsCall)) - - /** - * Alias for calling [addStep] with the following: - * ```java - * GoogleMapsCallStep.builder() - * .id(id) - * .build() - * ``` - */ - fun addGoogleMapsCallStep(id: String) = addStep(GoogleMapsCallStep.builder().id(id).build()) - - /** Alias for calling [addStep] with `Step.ofFunctionResult(functionResult)`. */ - fun addStep(functionResult: FunctionResultStep) = - addStep(Step.ofFunctionResult(functionResult)) - - /** Alias for calling [addStep] with `Step.ofCodeExecutionResult(codeExecutionResult)`. */ - fun addStep(codeExecutionResult: CodeExecutionResultStep) = - addStep(Step.ofCodeExecutionResult(codeExecutionResult)) - - /** Alias for calling [addStep] with `Step.ofUrlContextResult(urlContextResult)`. */ - fun addStep(urlContextResult: UrlContextResultStep) = - addStep(Step.ofUrlContextResult(urlContextResult)) - - /** Alias for calling [addStep] with `Step.ofGoogleSearchResult(googleSearchResult)`. */ - fun addStep(googleSearchResult: GoogleSearchResultStep) = - addStep(Step.ofGoogleSearchResult(googleSearchResult)) - - /** Alias for calling [addStep] with `Step.ofMcpServerToolResult(mcpServerToolResult)`. */ - fun addStep(mcpServerToolResult: McpServerToolResultStep) = - addStep(Step.ofMcpServerToolResult(mcpServerToolResult)) - - /** Alias for calling [addStep] with `Step.ofFileSearchResult(fileSearchResult)`. */ - fun addStep(fileSearchResult: FileSearchResultStep) = - addStep(Step.ofFileSearchResult(fileSearchResult)) - - /** - * Alias for calling [addStep] with the following: - * ```java - * FileSearchResultStep.builder() - * .callId(callId) - * .build() - * ``` - */ - fun addFileSearchResultStep(callId: String) = - addStep(FileSearchResultStep.builder().callId(callId).build()) - - /** Alias for calling [addStep] with `Step.ofGoogleMapsResult(googleMapsResult)`. */ - fun addStep(googleMapsResult: GoogleMapsResultStep) = - addStep(Step.ofGoogleMapsResult(googleMapsResult)) - /** * Required. Output only. The time at which the response was last updated in ISO 8601 format * (YYYY-MM-DDThh:mm:ssZ). @@ -962,6 +842,125 @@ private constructor( this.serviceTier = serviceTier } + /** Output only. The steps that make up the interaction. */ + fun steps(steps: List) = steps(JsonField.of(steps)) + + /** + * Sets [Builder.steps] to an arbitrary JSON value. + * + * You should usually call [Builder.steps] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun steps(steps: JsonField>) = apply { + this.steps = steps.map { it.toMutableList() } + } + + /** + * Adds a single [Step] to [steps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStep(step: Step) = apply { + steps = + (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } + } + + /** Alias for calling [addStep] with `Step.ofUserInput(userInput)`. */ + fun addStep(userInput: UserInputStep) = addStep(Step.ofUserInput(userInput)) + + /** Alias for calling [addStep] with `Step.ofModelOutput(modelOutput)`. */ + fun addStep(modelOutput: ModelOutputStep) = addStep(Step.ofModelOutput(modelOutput)) + + /** Alias for calling [addStep] with `Step.ofThought(thought)`. */ + fun addStep(thought: ThoughtStep) = addStep(Step.ofThought(thought)) + + /** Alias for calling [addStep] with `Step.ofFunctionCall(functionCall)`. */ + fun addStep(functionCall: FunctionCallStep) = addStep(Step.ofFunctionCall(functionCall)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionCall(codeExecutionCall)`. */ + fun addStep(codeExecutionCall: CodeExecutionCallStep) = + addStep(Step.ofCodeExecutionCall(codeExecutionCall)) + + /** Alias for calling [addStep] with `Step.ofUrlContextCall(urlContextCall)`. */ + fun addStep(urlContextCall: UrlContextCallStep) = + addStep(Step.ofUrlContextCall(urlContextCall)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolCall(mcpServerToolCall)`. */ + fun addStep(mcpServerToolCall: McpServerToolCallStep) = + addStep(Step.ofMcpServerToolCall(mcpServerToolCall)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchCall(googleSearchCall)`. */ + fun addStep(googleSearchCall: GoogleSearchCallStep) = + addStep(Step.ofGoogleSearchCall(googleSearchCall)) + + /** Alias for calling [addStep] with `Step.ofFileSearchCall(fileSearchCall)`. */ + fun addStep(fileSearchCall: FileSearchCallStep) = + addStep(Step.ofFileSearchCall(fileSearchCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addFileSearchCallStep(id: String) = addStep(FileSearchCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsCall(googleMapsCall)`. */ + fun addStep(googleMapsCall: GoogleMapsCallStep) = + addStep(Step.ofGoogleMapsCall(googleMapsCall)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * GoogleMapsCallStep.builder() + * .id(id) + * .build() + * ``` + */ + fun addGoogleMapsCallStep(id: String) = addStep(GoogleMapsCallStep.builder().id(id).build()) + + /** Alias for calling [addStep] with `Step.ofFunctionResult(functionResult)`. */ + fun addStep(functionResult: FunctionResultStep) = + addStep(Step.ofFunctionResult(functionResult)) + + /** Alias for calling [addStep] with `Step.ofCodeExecutionResult(codeExecutionResult)`. */ + fun addStep(codeExecutionResult: CodeExecutionResultStep) = + addStep(Step.ofCodeExecutionResult(codeExecutionResult)) + + /** Alias for calling [addStep] with `Step.ofUrlContextResult(urlContextResult)`. */ + fun addStep(urlContextResult: UrlContextResultStep) = + addStep(Step.ofUrlContextResult(urlContextResult)) + + /** Alias for calling [addStep] with `Step.ofGoogleSearchResult(googleSearchResult)`. */ + fun addStep(googleSearchResult: GoogleSearchResultStep) = + addStep(Step.ofGoogleSearchResult(googleSearchResult)) + + /** Alias for calling [addStep] with `Step.ofMcpServerToolResult(mcpServerToolResult)`. */ + fun addStep(mcpServerToolResult: McpServerToolResultStep) = + addStep(Step.ofMcpServerToolResult(mcpServerToolResult)) + + /** Alias for calling [addStep] with `Step.ofFileSearchResult(fileSearchResult)`. */ + fun addStep(fileSearchResult: FileSearchResultStep) = + addStep(Step.ofFileSearchResult(fileSearchResult)) + + /** + * Alias for calling [addStep] with the following: + * ```java + * FileSearchResultStep.builder() + * .callId(callId) + * .build() + * ``` + */ + fun addFileSearchResultStep(callId: String) = + addStep(FileSearchResultStep.builder().callId(callId).build()) + + /** Alias for calling [addStep] with `Step.ofGoogleMapsResult(googleMapsResult)`. */ + fun addStep(googleMapsResult: GoogleMapsResultStep) = + addStep(Step.ofGoogleMapsResult(googleMapsResult)) + /** System instruction for the interaction. */ fun systemInstruction(systemInstruction: String) = systemInstruction(JsonField.of(systemInstruction)) @@ -1085,7 +1084,6 @@ private constructor( * .id() * .created() * .status() - * .steps() * .updated() * ``` * @@ -1096,7 +1094,6 @@ private constructor( checkRequired("id", id), checkRequired("created", created), checkRequired("status", status), - checkRequired("steps", steps).map { it.toImmutable() }, checkRequired("updated", updated), agent, agentConfig, @@ -1109,6 +1106,7 @@ private constructor( (responseModalities ?: JsonMissing.of()).map { it.toImmutable() }, role, serviceTier, + (steps ?: JsonMissing.of()).map { it.toImmutable() }, systemInstruction, (tools ?: JsonMissing.of()).map { it.toImmutable() }, usage, @@ -1127,7 +1125,6 @@ private constructor( id() created() status().validate() - steps().forEach { it.validate() } updated() agent() agentConfig().ifPresent { it.validate() } @@ -1140,6 +1137,7 @@ private constructor( responseModalities().ifPresent { it.forEach { it.validate() } } role() serviceTier().ifPresent { it.validate() } + steps().ifPresent { it.forEach { it.validate() } } systemInstruction() tools().ifPresent { it.forEach { it.validate() } } usage().ifPresent { it.validate() } @@ -1165,7 +1163,6 @@ private constructor( (if (id.asKnown().isPresent) 1 else 0) + (if (created.asKnown().isPresent) 1 else 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + - (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (updated.asKnown().isPresent) 1 else 0) + (if (agent.asKnown().isPresent) 1 else 0) + (agentConfig.asKnown().getOrNull()?.validity() ?: 0) + @@ -1178,6 +1175,7 @@ private constructor( (responseModalities.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (role.asKnown().isPresent) 1 else 0) + (serviceTier.asKnown().getOrNull()?.validity() ?: 0) + + (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (systemInstruction.asKnown().isPresent) 1 else 0) + (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (usage.asKnown().getOrNull()?.validity() ?: 0) + @@ -3195,7 +3193,6 @@ private constructor( id == other.id && created == other.created && status == other.status && - steps == other.steps && updated == other.updated && agent == other.agent && agentConfig == other.agentConfig && @@ -3208,6 +3205,7 @@ private constructor( responseModalities == other.responseModalities && role == other.role && serviceTier == other.serviceTier && + steps == other.steps && systemInstruction == other.systemInstruction && tools == other.tools && usage == other.usage && @@ -3220,7 +3218,6 @@ private constructor( id, created, status, - steps, updated, agent, agentConfig, @@ -3233,6 +3230,7 @@ private constructor( responseModalities, role, serviceTier, + steps, systemInstruction, tools, usage, @@ -3244,5 +3242,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Interaction{id=$id, created=$created, status=$status, steps=$steps, updated=$updated, agent=$agent, agentConfig=$agentConfig, generationConfig=$generationConfig, input=$input, model=$model, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, systemInstruction=$systemInstruction, tools=$tools, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" + "Interaction{id=$id, created=$created, status=$status, updated=$updated, agent=$agent, agentConfig=$agentConfig, generationConfig=$generationConfig, input=$input, model=$model, previousInteractionId=$previousInteractionId, responseFormat=$responseFormat, responseMimeType=$responseMimeType, responseModalities=$responseModalities, role=$role, serviceTier=$serviceTier, steps=$steps, systemInstruction=$systemInstruction, tools=$tools, usage=$usage, webhookConfig=$webhookConfig, additionalProperties=$additionalProperties}" }