Class CodeExecutionUtils

java.lang.Object
com.google.adk.codeexecutors.CodeExecutionUtils

public final class CodeExecutionUtils extends Object
Utility functions for code execution.
  • Method Details

    • buildCodeExecutionResultPart

      public static com.google.genai.types.Part buildCodeExecutionResultPart(CodeExecutionUtils.CodeExecutionResult result)
    • buildExecutableCodePart

      public static com.google.genai.types.Part buildExecutableCodePart(String code)
    • 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.