# Class CodeExecutionUtils

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

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

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `CodeExecutionUtils.CodeExecutionInput`
  A structure that contains the input of code execution.
  `static class`
  `CodeExecutionUtils.CodeExecutionResult`
  A structure that contains the result of code execution.
  `static class`
  `CodeExecutionUtils.File`
  A structure that contains a file name and its content.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static com.google.genai.types.Part`
  `buildCodeExecutionResultPart(CodeExecutionUtils.CodeExecutionResult result)`
  `static com.google.genai.types.Part`
  `buildExecutableCodePart(String code)`
  `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.
  `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.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.