# Class BaseCodeExecutor

java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.codeexecutors.BaseCodeExecutor

Direct Known Subclasses:
  `BuiltInCodeExecutor, ContainerCodeExecutor, VertexAiCodeExecutor`

public abstract class BaseCodeExecutor extends JsonBaseModel
Abstract base class for all code executors.

The code executor allows the agent to execute code blocks from model responses and incorporate the execution results into the final response.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BaseCodeExecutor()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<String>>`
  `codeBlockDelimiters()`
  The list of the enclosing delimiters to identify the code blocks.
  `int`
  `errorRetryAttempts()`
  The number of attempts to retry on consecutive code execution errors.
  `abstract CodeExecutionUtils.CodeExecutionResult`
  `executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)`
  Executes code and return the code execution result.
  `com.google.common.collect.ImmutableList<String>`
  `executionResultDelimiters()`
  The delimiters to format the code execution result.
  `boolean`
  `optimizeDataFile()`
  If true, extract and process data files from the model request and attach them to the code executor.
  `boolean`
  `stateful()`
  Whether the code executor is stateful.

  ### Methods inherited from class JsonBaseModel

  `fromJsonNode, fromJsonString, getMapper, toJson, toJsonNode, toJsonString`
  Modifier and Type
  Method
  Description
  `static <T extends JsonBaseModel>
  T`
  `fromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clazz)`
  Deserializes a JsonNode to an object of the given type.
  `static <T extends JsonBaseModel>
  T`
  `fromJsonString(String jsonString, Class<T> clazz)`
  Deserializes a Json string to an object of the given type.
  `static com.fasterxml.jackson.databind.ObjectMapper`
  `getMapper()`
  Returns the mutable ObjectMapper instance used by ADK.
  `String`
  `toJson()`
  Serializes this object (i.e., the ObjectMappper instance used by ADK) to a Json string.
  `protected static com.fasterxml.jackson.databind.JsonNode`
  `toJsonNode(Object object)`
  Serializes an object to a JsonNode.
  `static String`
  `toJsonString(Object object)`
  Serializes an object to a Json string.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### BaseCodeExecutor

    public BaseCodeExecutor()

- ## Method Details

  - ### optimizeDataFile

    public boolean optimizeDataFile()
    If true, extract and process data files from the model request and attach them to the code executor.

    Supported data file MimeTypes are [text/csv]. Default to False.

  - ### stateful

    public boolean stateful()
    Whether the code executor is stateful. Default to False.

  - ### errorRetryAttempts

    public int errorRetryAttempts()
    The number of attempts to retry on consecutive code execution errors.

    Default to 2.

  - ### codeBlockDelimiters

    public com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<String>> codeBlockDelimiters()
    The list of the enclosing delimiters to identify the code blocks.

    Each inner list contains a pair of start and end delimiters. This supports multiple pairs of delimiters.

    For example, the delimiter ('```python\n', '\n```') can be used to identify code blocks with the following format:

    ```python

    print("hello")

    ```

  - ### executionResultDelimiters

    public com.google.common.collect.ImmutableList<String> executionResultDelimiters()
    The delimiters to format the code execution result.

  - ### executeCode

    public abstract CodeExecutionUtils.CodeExecutionResult executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)
    Executes code and return the code execution result.

    This method may perform blocking operations.

    Parameters:
      `invocationContext` - The invocation context of the code execution.
      `codeExecutionInput` - The code execution input.
    Returns:
      The code execution result.