Class BaseCodeExecutor
java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.codeexecutors.BaseCodeExecutor
- Direct Known Subclasses:
BuiltInCodeExecutor, ContainerCodeExecutor, VertexAiCodeExecutor
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 -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<String>> The list of the enclosing delimiters to identify the code blocks.intThe number of attempts to retry on consecutive code execution errors.executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput) Executes code and return the code execution result.com.google.common.collect.ImmutableList<String> The delimiters to format the code execution result.booleanIf true, extract and process data files from the model request and attach them to the code executor.booleanstateful()Whether the code executor is stateful.Methods inherited from class JsonBaseModel
fromJsonNode, fromJsonString, getMapper, toJson, toJsonNode, toJsonStringModifier and TypeMethodDescriptionstatic <T extends JsonBaseModel>
TfromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clazz) Deserializes a JsonNode to an object of the given type.static <T extends JsonBaseModel>
TfromJsonString(String jsonString, Class<T> clazz) Deserializes a Json string to an object of the given type.static com.fasterxml.jackson.databind.ObjectMapperReturns the mutable ObjectMapper instance used by ADK.toJson()Serializes this object (i.e., the ObjectMappper instance used by ADK) to a Json string.protected static com.fasterxml.jackson.databind.JsonNodetoJsonNode(Object object) Serializes an object to a JsonNode.static StringtoJsonString(Object object) Serializes an object to a Json string.
-
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
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.
-