# Class VertexAiCodeExecutor

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

public final class VertexAiCodeExecutor extends BaseCodeExecutor
A code executor that uses Vertex Code Interpreter Extension to execute code.

Attributes: resourceName: If set, load the existing resource name of the code interpreter extension instead of creating a new one. Format: projects/123/locations/us-central1/extensions/456

Follow https://cloud.google.com/vertex-ai/generative-ai/docs/extensions/code-interpreter for setup.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `VertexAiCodeExecutor(String resourceName)`
  Initializes the VertexAiCodeExecutor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `CodeExecutionUtils.CodeExecutionResult`
  `executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)`
  Executes code and return the code execution result.

  ### Methods inherited from class BaseCodeExecutor

  `codeBlockDelimiters, errorRetryAttempts, executionResultDelimiters, optimizeDataFile, stateful`
  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.
  `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

  - ### VertexAiCodeExecutor

    public VertexAiCodeExecutor(String resourceName)
    Initializes the VertexAiCodeExecutor.
    Parameters:
      `resourceName` - If set, load the existing resource name of the code interpreter extension instead of creating a new one. Format: projects/123/locations/us-central1/extensions/456

- ## Method Details

  - ### executeCode

    public CodeExecutionUtils.CodeExecutionResult executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)
    Description copied from class: `BaseCodeExecutor`
    Executes code and return the code execution result.

    This method may perform blocking operations.

    Specified by:
      `executeCode` in class `BaseCodeExecutor`
    Parameters:
      `invocationContext` - The invocation context of the code execution.
      `codeExecutionInput` - The code execution input.
    Returns:
      The code execution result.