Class CodeExecutionUtils
java.lang.Object
com.google.adk.codeexecutors.CodeExecutionUtils
Utility functions for code execution.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA structure that contains the input of code execution.static classA structure that contains the result of code execution.static classA structure that contains a file name and its content. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.genai.types.Partstatic com.google.genai.types.Partstatic com.google.genai.types.ContentconvertCodeExecutionParts(com.google.genai.types.Content content, List<String> codeBlockDelimiters, List<String> executionResultDelimiters) Converts the code execution parts to text parts in a Content.extractCodeAndTruncateContent(com.google.genai.types.Content.Builder contentBuilder, List<? extends List<String>> codeBlockDelimiters) Extracts the first code block from the content and truncates everything after it.
-
Method Details
-
buildCodeExecutionResultPart
public static com.google.genai.types.Part buildCodeExecutionResultPart(CodeExecutionUtils.CodeExecutionResult result) -
buildExecutableCodePart
-
convertCodeExecutionParts
public static com.google.genai.types.Content convertCodeExecutionParts(com.google.genai.types.Content content, List<String> codeBlockDelimiters, List<String> executionResultDelimiters) Converts the code execution parts to text parts in a Content.- Parameters:
content- The content to convert.codeBlockDelimiters- The delimiters to format the code block.executionResultDelimiters- The delimiters to format the code execution result.- Returns:
- The updated content.
-
extractCodeAndTruncateContent
public static Optional<String> extractCodeAndTruncateContent(com.google.genai.types.Content.Builder contentBuilder, List<? extends List<String>> codeBlockDelimiters) Extracts the first code block from the content and truncates everything after it.- Parameters:
contentBuilder- The content builder to extract the code from and modify.codeBlockDelimiters- The list of the enclosing delimiters to identify the code blocks.- Returns:
- The extracted code if found.
-