Submodules

google.adk.agents module

google.adk.artifacts module

class google.adk.artifacts.BaseArtifactService

Bases: ABC

Abstract base class for artifact services.

abstract delete_artifact(app_name, user_id, session_id, filename)

Deletes an artifact.

Return type:

None

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

abstract list_artifact_keys(app_name, user_id, session_id)

Lists all the artifact filenames within a session.

Return type:

list[str]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

Returns:

A list of all artifact filenames within a session.

abstract list_versions(app_name, user_id, session_id, filename)

Lists all versions of an artifact.

Return type:

list[int]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

Returns:

A list of all available versions of the artifact.

abstract load_artifact(app_name, user_id, session_id, filename, version=None)

Gets an artifact from the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename.

Return type:

Optional[Part]

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • version – The version of the artifact. If None, the latest version will be returned.

Returns:

The artifact or None if not found.

abstract save_artifact(app_name, user_id, session_id, filename, artifact)

Saves an artifact to the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename. After saving the artifact, a revision ID is returned to identify the artifact version.

Return type:

int

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • artifact – The artifact to save.

Returns:

The revision ID. The first version of the artifact has a revision ID of 0. This is incremented by 1 after each successful save.

class google.adk.artifacts.GcsArtifactService(bucket_name, **kwargs)

Bases: BaseArtifactService

An artifact service implementation using Google Cloud Storage (GCS).

delete_artifact(app_name, user_id, session_id, filename)

Deletes an artifact.

Return type:

None

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

list_artifact_keys(app_name, user_id, session_id)

Lists all the artifact filenames within a session.

Return type:

list[str]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

Returns:

A list of all artifact filenames within a session.

list_versions(app_name, user_id, session_id, filename)

Lists all versions of an artifact.

Return type:

list[int]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

Returns:

A list of all available versions of the artifact.

load_artifact(app_name, user_id, session_id, filename, version=None)

Gets an artifact from the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename.

Return type:

Optional[Part]

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • version – The version of the artifact. If None, the latest version will be returned.

Returns:

The artifact or None if not found.

save_artifact(app_name, user_id, session_id, filename, artifact)

Saves an artifact to the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename. After saving the artifact, a revision ID is returned to identify the artifact version.

Return type:

int

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • artifact – The artifact to save.

Returns:

The revision ID. The first version of the artifact has a revision ID of 0. This is incremented by 1 after each successful save.

pydantic model google.adk.artifacts.InMemoryArtifactService

Bases: BaseArtifactService, BaseModel

An in-memory implementation of the artifact service.

Show JSON schema
{
   "title": "InMemoryArtifactService",
   "description": "An in-memory implementation of the artifact service.",
   "type": "object",
   "properties": {
      "artifacts": {
         "additionalProperties": {
            "items": {
               "$ref": "#/$defs/Part"
            },
            "type": "array"
         },
         "title": "Artifacts",
         "type": "object"
      }
   },
   "$defs": {
      "Blob": {
         "additionalProperties": false,
         "description": "Content blob.",
         "properties": {
            "data": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Raw bytes.",
               "title": "Data"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "Blob",
         "type": "object"
      },
      "CodeExecutionResult": {
         "additionalProperties": false,
         "description": "Result of executing the [ExecutableCode].\n\nAlways follows a `part` containing the [ExecutableCode].",
         "properties": {
            "outcome": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Outcome"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Outcome of the code execution."
            },
            "output": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Contains stdout when code execution is successful, stderr or other description otherwise.",
               "title": "Output"
            }
         },
         "title": "CodeExecutionResult",
         "type": "object"
      },
      "ExecutableCode": {
         "additionalProperties": false,
         "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the [FunctionDeclaration] tool and\n[FunctionCallingConfig] mode is set to [Mode.CODE].",
         "properties": {
            "code": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The code to be executed.",
               "title": "Code"
            },
            "language": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Language"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Programming language of the `code`."
            }
         },
         "title": "ExecutableCode",
         "type": "object"
      },
      "FileData": {
         "additionalProperties": false,
         "description": "URI based data.",
         "properties": {
            "fileUri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. URI.",
               "title": "Fileuri"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "FileData",
         "type": "object"
      },
      "FunctionCall": {
         "additionalProperties": false,
         "description": "A function call.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The unique id of the function call. If populated, the client to execute the\n   `function_call` and return the response with the matching `id`.",
               "title": "Id"
            },
            "args": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Required. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.",
               "title": "Args"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name].",
               "title": "Name"
            }
         },
         "title": "FunctionCall",
         "type": "object"
      },
      "FunctionResponse": {
         "additionalProperties": false,
         "description": "A function response.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The id of the function call this response is for. Populated by the client\n   to match the corresponding function call `id`.",
               "title": "Id"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].",
               "title": "Name"
            },
            "response": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The function response in JSON object format. Use \"output\" key to specify function output and \"error\" key to specify error details (if any). If \"output\" and \"error\" keys are not specified, then whole \"response\" is treated as function output.",
               "title": "Response"
            }
         },
         "title": "FunctionResponse",
         "type": "object"
      },
      "Language": {
         "description": "Required. Programming language of the `code`.",
         "enum": [
            "LANGUAGE_UNSPECIFIED",
            "PYTHON"
         ],
         "title": "Language",
         "type": "string"
      },
      "Outcome": {
         "description": "Required. Outcome of the code execution.",
         "enum": [
            "OUTCOME_UNSPECIFIED",
            "OUTCOME_OK",
            "OUTCOME_FAILED",
            "OUTCOME_DEADLINE_EXCEEDED"
         ],
         "title": "Outcome",
         "type": "string"
      },
      "Part": {
         "additionalProperties": false,
         "description": "A datatype containing media content.\n\nExactly one field within a Part should be set, representing the specific type\nof content being conveyed. Using multiple fields within the same `Part`\ninstance is considered invalid.",
         "properties": {
            "videoMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/VideoMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Metadata for a given video."
            },
            "thought": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Indicates if the part is thought from the model.",
               "title": "Thought"
            },
            "codeExecutionResult": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/CodeExecutionResult"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Result of executing the [ExecutableCode]."
            },
            "executableCode": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/ExecutableCode"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Code generated by the model that is meant to be executed."
            },
            "fileData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FileData"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. URI based data."
            },
            "functionCall": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionCall"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values."
            },
            "functionResponse": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionResponse"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model."
            },
            "inlineData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Blob"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Inlined bytes data."
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Text part (can be code).",
               "title": "Text"
            }
         },
         "title": "Part",
         "type": "object"
      },
      "VideoMetadata": {
         "additionalProperties": false,
         "description": "Metadata describes the input video content.",
         "properties": {
            "endOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The end offset of the video.",
               "title": "Endoffset"
            },
            "startOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The start offset of the video.",
               "title": "Startoffset"
            }
         },
         "title": "VideoMetadata",
         "type": "object"
      }
   }
}

Fields:
  • artifacts (dict[str, list[google.genai.types.Part]])

field artifacts: dict[str, list[Part]] [Optional]
delete_artifact(app_name, user_id, session_id, filename)

Deletes an artifact.

Return type:

None

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

list_artifact_keys(app_name, user_id, session_id)

Lists all the artifact filenames within a session.

Return type:

list[str]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

Returns:

A list of all artifact filenames within a session.

list_versions(app_name, user_id, session_id, filename)

Lists all versions of an artifact.

Return type:

list[int]

Parameters:
  • app_name – The name of the application.

  • user_id – The ID of the user.

  • session_id – The ID of the session.

  • filename – The name of the artifact file.

Returns:

A list of all available versions of the artifact.

load_artifact(app_name, user_id, session_id, filename, version=None)

Gets an artifact from the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename.

Return type:

Optional[Part]

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • version – The version of the artifact. If None, the latest version will be returned.

Returns:

The artifact or None if not found.

save_artifact(app_name, user_id, session_id, filename, artifact)

Saves an artifact to the artifact service storage.

The artifact is a file identified by the app name, user ID, session ID, and filename. After saving the artifact, a revision ID is returned to identify the artifact version.

Return type:

int

Parameters:
  • app_name – The app name.

  • user_id – The user ID.

  • session_id – The session ID.

  • filename – The filename of the artifact.

  • artifact – The artifact to save.

Returns:

The revision ID. The first version of the artifact has a revision ID of 0. This is incremented by 1 after each successful save.

google.adk.code_executors module

pydantic model google.adk.code_executors.BaseCodeExecutor

Bases: BaseModel

Base class for all code executors.

Show JSON schema
{
   "title": "BaseCodeExecutor",
   "description": "Base class for all code executors.",
   "type": "object",
   "properties": {
      "optimize_data_file": {
         "default": false,
         "title": "Optimize Data File",
         "type": "boolean"
      },
      "stateful": {
         "default": false,
         "title": "Stateful",
         "type": "boolean"
      },
      "error_retry_attempts": {
         "default": 2,
         "title": "Error Retry Attempts",
         "type": "integer"
      },
      "code_block_delimiters": {
         "default": [
            [
               "```tool_code\n",
               "\n```"
            ],
            [
               "```python\n",
               "\n```"
            ]
         ],
         "items": {
            "maxItems": 2,
            "minItems": 2,
            "prefixItems": [
               {
                  "type": "string"
               },
               {
                  "type": "string"
               }
            ],
            "type": "array"
         },
         "title": "Code Block Delimiters",
         "type": "array"
      },
      "execution_result_delimiters": {
         "default": [
            "```tool_output\n",
            "\n```"
         ],
         "maxItems": 2,
         "minItems": 2,
         "prefixItems": [
            {
               "type": "string"
            },
            {
               "type": "string"
            }
         ],
         "title": "Execution Result Delimiters",
         "type": "array"
      }
   }
}

Fields:
  • code_block_delimiters (List[tuple[str, str]])

  • error_retry_attempts (int)

  • execution_result_delimiters (tuple[str, str])

  • optimize_data_file (bool)

  • stateful (bool)

field code_block_delimiters: List[tuple[str, str]] = [('```tool_code\n', '\n```'), ('```python\n', '\n```')]

The list of the enclosing delimiters to identify the code blocks. For example, the delimiter (’```python

‘, ‘ ```’) can be

used to identify code blocks with the following format:

`python print("hello") `

field error_retry_attempts: int = 2

The number of attempts to retry on consecutive code execution errors. Default to 2.

field execution_result_delimiters: tuple[str, str] = ('```tool_output\n', '\n```')

The delimiters to format the code execution result.

field optimize_data_file: bool = False

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.

field stateful: bool = False

Whether the code executor is stateful. Default to False.

abstract execute_code(invocation_context, code_execution_input)

Executes code and return the result.

Return type:

CodeExecutionResult

class google.adk.code_executors.CodeExecutorContext(session_state)

Bases: object

The persistent context used to configure the code executor.

Initializes the code executor context.

Parameters:

session_state – The session state to get the code executor context from.

add_input_files(input_files)

Adds the input files to the code executor context.

add_processed_file_names(file_names)

Adds the processed file name to the session state.

clear_input_files()

Removes the input files and processed file names to the code executor context.

get_error_count(invocation_id)

Returns the error count from the session state.

Return type:

int

get_execution_id()

Returns the session ID for the code executor.

Return type:

Optional[str]

get_input_files()

Returns the input file names from the session state.

Return type:

list[File]

get_processed_file_names()

Returns the processed file names from the session state.

Return type:

list[str]

get_state_delta()

Returns the state delta to update in the persistent session state.

Return type:

dict[str, Any]

increment_error_count(invocation_id)

Increments the error count from the session state.

reset_error_count(invocation_id)

Resets the error count from the session state.

set_execution_id(session_id)

Sets the session ID for the code executor.

update_code_execution_result(invocation_id, code, result_stdout, result_stderr)

Updates the code execution result.

pydantic model google.adk.code_executors.ContainerCodeExecutor

Bases: BaseCodeExecutor

A tool that execute code in the container.

Show JSON schema
{
   "title": "ContainerCodeExecutor",
   "description": "A tool that execute code in the container.",
   "type": "object",
   "properties": {
      "optimize_data_file": {
         "default": false,
         "title": "Optimize Data File",
         "type": "boolean"
      },
      "stateful": {
         "default": false,
         "title": "Stateful",
         "type": "boolean"
      },
      "error_retry_attempts": {
         "default": 2,
         "title": "Error Retry Attempts",
         "type": "integer"
      },
      "code_block_delimiters": {
         "default": [
            [
               "```tool_code\n",
               "\n```"
            ],
            [
               "```python\n",
               "\n```"
            ]
         ],
         "items": {
            "maxItems": 2,
            "minItems": 2,
            "prefixItems": [
               {
                  "type": "string"
               },
               {
                  "type": "string"
               }
            ],
            "type": "array"
         },
         "title": "Code Block Delimiters",
         "type": "array"
      },
      "execution_result_delimiters": {
         "default": [
            "```tool_output\n",
            "\n```"
         ],
         "maxItems": 2,
         "minItems": 2,
         "prefixItems": [
            {
               "type": "string"
            },
            {
               "type": "string"
            }
         ],
         "title": "Execution Result Delimiters",
         "type": "array"
      },
      "base_url": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Base Url"
      },
      "image": {
         "default": null,
         "title": "Image",
         "type": "string"
      },
      "docker_path": {
         "default": null,
         "title": "Docker Path",
         "type": "string"
      }
   }
}

Fields:
  • base_url (str | None)

  • docker_path (str)

  • image (str)

  • optimize_data_file (bool)

  • stateful (bool)

field base_url: Optional[str] = None

Optional. The base url of the user hosted Docker client.

field docker_path: str = None

The path to the directory containing the Dockerfile. If set, build the image from the dockerfile path instead of using the predefined image. Either docker_path or image must be set.

field image: str = None

The tag of the predefined image or custom image to run on the container. Either docker_path or image must be set.

field optimize_data_file: bool = False

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.

field stateful: bool = False

Whether the code executor is stateful. Default to False.

execute_code(invocation_context, code_execution_input)

Executes the code in the container and collects the result.

Return type:

CodeExecutionResult

model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Return type:

None

Parameters:
  • self – The BaseModel instance.

  • context – The context.

pydantic model google.adk.code_executors.UnsafeLocalCodeExecutor

Bases: BaseCodeExecutor

A tool that unsafely execute code directly in the current local context.

Show JSON schema
{
   "title": "UnsafeLocalCodeExecutor",
   "description": "A tool that unsafely execute code directly in the current local context.",
   "type": "object",
   "properties": {
      "optimize_data_file": {
         "default": false,
         "title": "Optimize Data File",
         "type": "boolean"
      },
      "stateful": {
         "default": false,
         "title": "Stateful",
         "type": "boolean"
      },
      "error_retry_attempts": {
         "default": 2,
         "title": "Error Retry Attempts",
         "type": "integer"
      },
      "code_block_delimiters": {
         "default": [
            [
               "```tool_code\n",
               "\n```"
            ],
            [
               "```python\n",
               "\n```"
            ]
         ],
         "items": {
            "maxItems": 2,
            "minItems": 2,
            "prefixItems": [
               {
                  "type": "string"
               },
               {
                  "type": "string"
               }
            ],
            "type": "array"
         },
         "title": "Code Block Delimiters",
         "type": "array"
      },
      "execution_result_delimiters": {
         "default": [
            "```tool_output\n",
            "\n```"
         ],
         "maxItems": 2,
         "minItems": 2,
         "prefixItems": [
            {
               "type": "string"
            },
            {
               "type": "string"
            }
         ],
         "title": "Execution Result Delimiters",
         "type": "array"
      }
   }
}

Fields:
  • optimize_data_file (bool)

  • stateful (bool)

field optimize_data_file: bool = False

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.

field stateful: bool = False

Whether the code executor is stateful. Default to False.

execute_code(invocation_context, code_execution_input)

Executes code and return the result.

Return type:

CodeExecutionResult

pydantic model google.adk.code_executors.VertexAiCodeExecutor

Bases: BaseCodeExecutor

A tool that uses Vertex Code Interpreter Extension to execute code.

Show JSON schema
{
   "title": "VertexAiCodeExecutor",
   "description": "A tool that uses Vertex Code Interpreter Extension to execute code.",
   "type": "object",
   "properties": {
      "optimize_data_file": {
         "default": false,
         "title": "Optimize Data File",
         "type": "boolean"
      },
      "stateful": {
         "default": false,
         "title": "Stateful",
         "type": "boolean"
      },
      "error_retry_attempts": {
         "default": 2,
         "title": "Error Retry Attempts",
         "type": "integer"
      },
      "code_block_delimiters": {
         "default": [
            [
               "```tool_code\n",
               "\n```"
            ],
            [
               "```python\n",
               "\n```"
            ]
         ],
         "items": {
            "maxItems": 2,
            "minItems": 2,
            "prefixItems": [
               {
                  "type": "string"
               },
               {
                  "type": "string"
               }
            ],
            "type": "array"
         },
         "title": "Code Block Delimiters",
         "type": "array"
      },
      "execution_result_delimiters": {
         "default": [
            "```tool_output\n",
            "\n```"
         ],
         "maxItems": 2,
         "minItems": 2,
         "prefixItems": [
            {
               "type": "string"
            },
            {
               "type": "string"
            }
         ],
         "title": "Execution Result Delimiters",
         "type": "array"
      },
      "resource_name": {
         "default": null,
         "title": "Resource Name",
         "type": "string"
      }
   }
}

Fields:
  • resource_name (str)

field resource_name: str = None

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

execute_code(invocation_context, code_execution_input)

Executes code and return the result.

Return type:

CodeExecutionResult

model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Return type:

None

Parameters:
  • self – The BaseModel instance.

  • context – The context.

google.adk.evaluation module

google.adk.events module

pydantic model google.adk.events.Event

Bases: LlmResponse

Represents an event in a conversation between agents and users.

It is used to store the content of the conversation, as well as the actions taken by the agents like function calls, etc.

invocation_id

The invocation ID of the event.

author

“user” or the name of the agent, indicating who appended the event to the session.

actions

The actions taken by the agent.

long_running_tool_ids

The ids of the long running function calls.

branch

The branch of the event.

id

The unique identifier of the event.

timestamp

The timestamp of the event.

is_final_response

Whether the event is the final response of the agent.

get_function_calls

Returns the function calls in the event.

Show JSON schema
{
   "title": "Event",
   "description": "Represents an event in a conversation between agents and users.\n\nIt is used to store the content of the conversation, as well as the actions\ntaken by the agents like function calls, etc.\n\nAttributes:\n  invocation_id: The invocation ID of the event.\n  author: \"user\" or the name of the agent, indicating who appended the event\n    to the session.\n  actions: The actions taken by the agent.\n  long_running_tool_ids: The ids of the long running function calls.\n  branch: The branch of the event.\n  id: The unique identifier of the event.\n  timestamp: The timestamp of the event.\n  is_final_response: Whether the event is the final response of the agent.\n  get_function_calls: Returns the function calls in the event.",
   "type": "object",
   "properties": {
      "content": {
         "anyOf": [
            {
               "$ref": "#/$defs/Content"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "grounding_metadata": {
         "anyOf": [
            {
               "$ref": "#/$defs/GroundingMetadata"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "partial": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Partial"
      },
      "turn_complete": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Turn Complete"
      },
      "error_code": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Error Code"
      },
      "error_message": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Error Message"
      },
      "interrupted": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Interrupted"
      },
      "invocation_id": {
         "default": "",
         "title": "Invocation Id",
         "type": "string"
      },
      "author": {
         "title": "Author",
         "type": "string"
      },
      "actions": {
         "$ref": "#/$defs/EventActions"
      },
      "long_running_tool_ids": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array",
               "uniqueItems": true
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Long Running Tool Ids"
      },
      "branch": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Branch"
      },
      "id": {
         "default": "",
         "title": "Id",
         "type": "string"
      },
      "timestamp": {
         "title": "Timestamp",
         "type": "number"
      }
   },
   "$defs": {
      "Blob": {
         "additionalProperties": false,
         "description": "Content blob.",
         "properties": {
            "data": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Raw bytes.",
               "title": "Data"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "Blob",
         "type": "object"
      },
      "CodeExecutionResult": {
         "additionalProperties": false,
         "description": "Result of executing the [ExecutableCode].\n\nAlways follows a `part` containing the [ExecutableCode].",
         "properties": {
            "outcome": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Outcome"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Outcome of the code execution."
            },
            "output": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Contains stdout when code execution is successful, stderr or other description otherwise.",
               "title": "Output"
            }
         },
         "title": "CodeExecutionResult",
         "type": "object"
      },
      "Content": {
         "additionalProperties": false,
         "description": "Contains the multi-part content of a message.",
         "properties": {
            "parts": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/Part"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "List of parts that constitute a single message. Each part may have\n      a different IANA MIME type.",
               "title": "Parts"
            },
            "role": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The producer of the content. Must be either 'user' or\n      'model'. Useful to set for multi-turn conversations, otherwise can be\n      empty. If role is not specified, SDK will determine the role.",
               "title": "Role"
            }
         },
         "title": "Content",
         "type": "object"
      },
      "EventActions": {
         "additionalProperties": false,
         "description": "Represents the actions attached to an event.",
         "properties": {
            "skip_summarization": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Skip Summarization"
            },
            "state_delta": {
               "title": "State Delta",
               "type": "object"
            },
            "artifact_delta": {
               "additionalProperties": {
                  "type": "integer"
               },
               "title": "Artifact Delta",
               "type": "object"
            },
            "transfer_to_agent": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Transfer To Agent"
            },
            "escalate": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Escalate"
            },
            "requested_auth_configs": {
               "additionalProperties": {
                  "type": "object"
               },
               "title": "Requested Auth Configs",
               "type": "object"
            }
         },
         "title": "EventActions",
         "type": "object"
      },
      "ExecutableCode": {
         "additionalProperties": false,
         "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the [FunctionDeclaration] tool and\n[FunctionCallingConfig] mode is set to [Mode.CODE].",
         "properties": {
            "code": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The code to be executed.",
               "title": "Code"
            },
            "language": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Language"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Programming language of the `code`."
            }
         },
         "title": "ExecutableCode",
         "type": "object"
      },
      "FileData": {
         "additionalProperties": false,
         "description": "URI based data.",
         "properties": {
            "fileUri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. URI.",
               "title": "Fileuri"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "FileData",
         "type": "object"
      },
      "FunctionCall": {
         "additionalProperties": false,
         "description": "A function call.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The unique id of the function call. If populated, the client to execute the\n   `function_call` and return the response with the matching `id`.",
               "title": "Id"
            },
            "args": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Required. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.",
               "title": "Args"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name].",
               "title": "Name"
            }
         },
         "title": "FunctionCall",
         "type": "object"
      },
      "FunctionResponse": {
         "additionalProperties": false,
         "description": "A function response.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The id of the function call this response is for. Populated by the client\n   to match the corresponding function call `id`.",
               "title": "Id"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].",
               "title": "Name"
            },
            "response": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The function response in JSON object format. Use \"output\" key to specify function output and \"error\" key to specify error details (if any). If \"output\" and \"error\" keys are not specified, then whole \"response\" is treated as function output.",
               "title": "Response"
            }
         },
         "title": "FunctionResponse",
         "type": "object"
      },
      "GroundingChunk": {
         "additionalProperties": false,
         "description": "Grounding chunk.",
         "properties": {
            "retrievedContext": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/GroundingChunkRetrievedContext"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Grounding chunk from context retrieved by the retrieval tools."
            },
            "web": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/GroundingChunkWeb"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Grounding chunk from the web."
            }
         },
         "title": "GroundingChunk",
         "type": "object"
      },
      "GroundingChunkRetrievedContext": {
         "additionalProperties": false,
         "description": "Chunk from context retrieved by the retrieval tools.",
         "properties": {
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Text of the attribution.",
               "title": "Text"
            },
            "title": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Title of the attribution.",
               "title": "Title"
            },
            "uri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "URI reference of the attribution.",
               "title": "Uri"
            }
         },
         "title": "GroundingChunkRetrievedContext",
         "type": "object"
      },
      "GroundingChunkWeb": {
         "additionalProperties": false,
         "description": "Chunk from the web.",
         "properties": {
            "title": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Title of the chunk.",
               "title": "Title"
            },
            "uri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "URI reference of the chunk.",
               "title": "Uri"
            }
         },
         "title": "GroundingChunkWeb",
         "type": "object"
      },
      "GroundingMetadata": {
         "additionalProperties": false,
         "description": "Metadata returned to client when grounding is enabled.",
         "properties": {
            "groundingChunks": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/GroundingChunk"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "List of supporting references retrieved from specified grounding source.",
               "title": "Groundingchunks"
            },
            "groundingSupports": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/GroundingSupport"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. List of grounding support.",
               "title": "Groundingsupports"
            },
            "retrievalMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/RetrievalMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Output only. Retrieval metadata."
            },
            "retrievalQueries": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Queries executed by the retrieval tools.",
               "title": "Retrievalqueries"
            },
            "searchEntryPoint": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/SearchEntryPoint"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Google search entry for the following-up web searches."
            },
            "webSearchQueries": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Web search queries for the following-up web search.",
               "title": "Websearchqueries"
            }
         },
         "title": "GroundingMetadata",
         "type": "object"
      },
      "GroundingSupport": {
         "additionalProperties": false,
         "description": "Grounding support.",
         "properties": {
            "confidenceScores": {
               "anyOf": [
                  {
                     "items": {
                        "type": "number"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Confidence score of the support references. Ranges from 0 to 1. 1 is the most confident. This list must have the same size as the grounding_chunk_indices.",
               "title": "Confidencescores"
            },
            "groundingChunkIndices": {
               "anyOf": [
                  {
                     "items": {
                        "type": "integer"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "A list of indices (into 'grounding_chunk') specifying the citations associated with the claim. For instance [1,3,4] means that grounding_chunk[1], grounding_chunk[3], grounding_chunk[4] are the retrieved content attributed to the claim.",
               "title": "Groundingchunkindices"
            },
            "segment": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Segment"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Segment of the content this support belongs to."
            }
         },
         "title": "GroundingSupport",
         "type": "object"
      },
      "Language": {
         "description": "Required. Programming language of the `code`.",
         "enum": [
            "LANGUAGE_UNSPECIFIED",
            "PYTHON"
         ],
         "title": "Language",
         "type": "string"
      },
      "Outcome": {
         "description": "Required. Outcome of the code execution.",
         "enum": [
            "OUTCOME_UNSPECIFIED",
            "OUTCOME_OK",
            "OUTCOME_FAILED",
            "OUTCOME_DEADLINE_EXCEEDED"
         ],
         "title": "Outcome",
         "type": "string"
      },
      "Part": {
         "additionalProperties": false,
         "description": "A datatype containing media content.\n\nExactly one field within a Part should be set, representing the specific type\nof content being conveyed. Using multiple fields within the same `Part`\ninstance is considered invalid.",
         "properties": {
            "videoMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/VideoMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Metadata for a given video."
            },
            "thought": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Indicates if the part is thought from the model.",
               "title": "Thought"
            },
            "codeExecutionResult": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/CodeExecutionResult"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Result of executing the [ExecutableCode]."
            },
            "executableCode": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/ExecutableCode"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Code generated by the model that is meant to be executed."
            },
            "fileData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FileData"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. URI based data."
            },
            "functionCall": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionCall"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values."
            },
            "functionResponse": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionResponse"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model."
            },
            "inlineData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Blob"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Inlined bytes data."
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Text part (can be code).",
               "title": "Text"
            }
         },
         "title": "Part",
         "type": "object"
      },
      "RetrievalMetadata": {
         "additionalProperties": false,
         "description": "Metadata related to retrieval in the grounding flow.",
         "properties": {
            "googleSearchDynamicRetrievalScore": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Score indicating how likely information from Google Search could help answer the prompt. The score is in the range `[0, 1]`, where 0 is the least likely and 1 is the most likely. This score is only populated when Google Search grounding and dynamic retrieval is enabled. It will be compared to the threshold to determine whether to trigger Google Search.",
               "title": "Googlesearchdynamicretrievalscore"
            }
         },
         "title": "RetrievalMetadata",
         "type": "object"
      },
      "SearchEntryPoint": {
         "additionalProperties": false,
         "description": "Google search entry point.",
         "properties": {
            "renderedContent": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Web content snippet that can be embedded in a web page or an app webview.",
               "title": "Renderedcontent"
            },
            "sdkBlob": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Base64 encoded JSON representing array of tuple.",
               "title": "Sdkblob"
            }
         },
         "title": "SearchEntryPoint",
         "type": "object"
      },
      "Segment": {
         "additionalProperties": false,
         "description": "Segment of the content.",
         "properties": {
            "endIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. End index in the given Part, measured in bytes. Offset from the start of the Part, exclusive, starting at zero.",
               "title": "Endindex"
            },
            "partIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. The index of a Part object within its parent Content object.",
               "title": "Partindex"
            },
            "startIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. Start index in the given Part, measured in bytes. Offset from the start of the Part, inclusive, starting at zero.",
               "title": "Startindex"
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. The text corresponding to the segment from the response.",
               "title": "Text"
            }
         },
         "title": "Segment",
         "type": "object"
      },
      "VideoMetadata": {
         "additionalProperties": false,
         "description": "Metadata describes the input video content.",
         "properties": {
            "endOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The end offset of the video.",
               "title": "Endoffset"
            },
            "startOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The start offset of the video.",
               "title": "Startoffset"
            }
         },
         "title": "VideoMetadata",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "author"
   ]
}

Fields:
  • actions (google.adk.events.event_actions.EventActions)

  • author (str)

  • branch (str | None)

  • id (str)

  • invocation_id (str)

  • long_running_tool_ids (set[str] | None)

  • timestamp (float)

field actions: EventActions [Optional]

The actions taken by the agent.

field author: str [Required]

‘user’ or the name of the agent, indicating who appended the event to the session.

field branch: Optional[str] = None

The branch of the event.

The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of agent_2, and agent_2 is the parent of agent_3.

Branch is used when multiple sub-agent shouldn’t see their peer agents’ conversaction history.

field id: str = ''

The unique identifier of the event.

field invocation_id: str = ''

The invocation ID of the event.

field long_running_tool_ids: Optional[set[str]] = None

Set of ids of the long running function calls. Agent client will know from this field about which function call is long running. only valid for function call event

field timestamp: float [Optional]

The timestamp of the event.

classmethod from_function_response(function_call_event, function_call, function_result)
get_function_calls()

Returns the function calls in the event.

Return type:

list[FunctionCall]

get_function_responses()

Returns the function responses in the event.

Return type:

list[FunctionResponse]

has_trailing_code_exeuction_result()

Returns whether the event has a trailing code execution result.

Return type:

bool

is_final_response()

Returns whether the event is the final response of the agent.

Return type:

bool

model_post_init(_Event__context)

Post initialization logic for the event.

static new_id()
pydantic model google.adk.events.EventActions

Bases: BaseModel

Represents the actions attached to an event.

Show JSON schema
{
   "title": "EventActions",
   "description": "Represents the actions attached to an event.",
   "type": "object",
   "properties": {
      "skip_summarization": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Skip Summarization"
      },
      "state_delta": {
         "title": "State Delta",
         "type": "object"
      },
      "artifact_delta": {
         "additionalProperties": {
            "type": "integer"
         },
         "title": "Artifact Delta",
         "type": "object"
      },
      "transfer_to_agent": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Transfer To Agent"
      },
      "escalate": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Escalate"
      },
      "requested_auth_configs": {
         "additionalProperties": {
            "type": "object"
         },
         "title": "Requested Auth Configs",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Fields:
  • artifact_delta (dict[str, int])

  • escalate (bool | None)

  • requested_auth_configs (dict[str, dict])

  • skip_summarization (bool | None)

  • state_delta (dict[str, object])

  • transfer_to_agent (str | None)

field artifact_delta: dict[str, int] [Optional]

Indicates that the event is updating an artifact. key is the filename, value is the version.

field escalate: Optional[bool] = None

The agent is escalating to a higher level agent.

field requested_auth_configs: dict[str, dict] [Optional]

Will only be set by a tool response indicating tool request euc. dict key is the function call id since one function call response (from model) could correspond to multiple function calls. dict value is the required auth config.

field skip_summarization: Optional[bool] = None

If true, it won’t call model to summarize function response.

Only used for function_response event.

field state_delta: dict[str, object] [Optional]

Indicates that the event is updating the state with the given delta.

field transfer_to_agent: Optional[str] = None

If set, the event transfers to the specified agent.

google.adk.examples module

class google.adk.examples.BaseExampleProvider

Bases: ABC

Base class for example providers.

This class defines the interface for providing examples for a given query.

abstract get_examples(query)

Returns a list of examples for a given query.

Return type:

list[Example]

Parameters:

query – The query to get examples for.

Returns:

A list of Example objects.

pydantic model google.adk.examples.Example

Bases: BaseModel

A few-shot example.

input

The input content for the example.

output

The expected output content for the example.

Show JSON schema
{
   "title": "Example",
   "description": "A few-shot example.\n\nAttributes:\n  input: The input content for the example.\n  output: The expected output content for the example.",
   "type": "object",
   "properties": {
      "input": {
         "$ref": "#/$defs/Content"
      },
      "output": {
         "items": {
            "$ref": "#/$defs/Content"
         },
         "title": "Output",
         "type": "array"
      }
   },
   "$defs": {
      "Blob": {
         "additionalProperties": false,
         "description": "Content blob.",
         "properties": {
            "data": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Raw bytes.",
               "title": "Data"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "Blob",
         "type": "object"
      },
      "CodeExecutionResult": {
         "additionalProperties": false,
         "description": "Result of executing the [ExecutableCode].\n\nAlways follows a `part` containing the [ExecutableCode].",
         "properties": {
            "outcome": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Outcome"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Outcome of the code execution."
            },
            "output": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Contains stdout when code execution is successful, stderr or other description otherwise.",
               "title": "Output"
            }
         },
         "title": "CodeExecutionResult",
         "type": "object"
      },
      "Content": {
         "additionalProperties": false,
         "description": "Contains the multi-part content of a message.",
         "properties": {
            "parts": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/Part"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "List of parts that constitute a single message. Each part may have\n      a different IANA MIME type.",
               "title": "Parts"
            },
            "role": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The producer of the content. Must be either 'user' or\n      'model'. Useful to set for multi-turn conversations, otherwise can be\n      empty. If role is not specified, SDK will determine the role.",
               "title": "Role"
            }
         },
         "title": "Content",
         "type": "object"
      },
      "ExecutableCode": {
         "additionalProperties": false,
         "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the [FunctionDeclaration] tool and\n[FunctionCallingConfig] mode is set to [Mode.CODE].",
         "properties": {
            "code": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The code to be executed.",
               "title": "Code"
            },
            "language": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Language"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Programming language of the `code`."
            }
         },
         "title": "ExecutableCode",
         "type": "object"
      },
      "FileData": {
         "additionalProperties": false,
         "description": "URI based data.",
         "properties": {
            "fileUri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. URI.",
               "title": "Fileuri"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "FileData",
         "type": "object"
      },
      "FunctionCall": {
         "additionalProperties": false,
         "description": "A function call.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The unique id of the function call. If populated, the client to execute the\n   `function_call` and return the response with the matching `id`.",
               "title": "Id"
            },
            "args": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Required. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.",
               "title": "Args"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name].",
               "title": "Name"
            }
         },
         "title": "FunctionCall",
         "type": "object"
      },
      "FunctionResponse": {
         "additionalProperties": false,
         "description": "A function response.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The id of the function call this response is for. Populated by the client\n   to match the corresponding function call `id`.",
               "title": "Id"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].",
               "title": "Name"
            },
            "response": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The function response in JSON object format. Use \"output\" key to specify function output and \"error\" key to specify error details (if any). If \"output\" and \"error\" keys are not specified, then whole \"response\" is treated as function output.",
               "title": "Response"
            }
         },
         "title": "FunctionResponse",
         "type": "object"
      },
      "Language": {
         "description": "Required. Programming language of the `code`.",
         "enum": [
            "LANGUAGE_UNSPECIFIED",
            "PYTHON"
         ],
         "title": "Language",
         "type": "string"
      },
      "Outcome": {
         "description": "Required. Outcome of the code execution.",
         "enum": [
            "OUTCOME_UNSPECIFIED",
            "OUTCOME_OK",
            "OUTCOME_FAILED",
            "OUTCOME_DEADLINE_EXCEEDED"
         ],
         "title": "Outcome",
         "type": "string"
      },
      "Part": {
         "additionalProperties": false,
         "description": "A datatype containing media content.\n\nExactly one field within a Part should be set, representing the specific type\nof content being conveyed. Using multiple fields within the same `Part`\ninstance is considered invalid.",
         "properties": {
            "videoMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/VideoMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Metadata for a given video."
            },
            "thought": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Indicates if the part is thought from the model.",
               "title": "Thought"
            },
            "codeExecutionResult": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/CodeExecutionResult"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Result of executing the [ExecutableCode]."
            },
            "executableCode": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/ExecutableCode"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Code generated by the model that is meant to be executed."
            },
            "fileData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FileData"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. URI based data."
            },
            "functionCall": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionCall"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values."
            },
            "functionResponse": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionResponse"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model."
            },
            "inlineData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Blob"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Inlined bytes data."
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Text part (can be code).",
               "title": "Text"
            }
         },
         "title": "Part",
         "type": "object"
      },
      "VideoMetadata": {
         "additionalProperties": false,
         "description": "Metadata describes the input video content.",
         "properties": {
            "endOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The end offset of the video.",
               "title": "Endoffset"
            },
            "startOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The start offset of the video.",
               "title": "Startoffset"
            }
         },
         "title": "VideoMetadata",
         "type": "object"
      }
   },
   "required": [
      "input",
      "output"
   ]
}

Fields:
  • input (google.genai.types.Content)

  • output (list[google.genai.types.Content])

field input: Content [Required]
field output: list[Content] [Required]
class google.adk.examples.VertexAiExampleStore(examples_store_name)

Bases: BaseExampleProvider

Provides examples from Vertex example store.

Initializes the VertexAiExampleStore.

Parameters:

examples_store_name – The resource name of the vertex example store, in the format of projects/{project}/locations/{location}/exampleStores/{example_store}.

get_examples(query)

Returns a list of examples for a given query.

Return type:

list[Example]

Parameters:

query – The query to get examples for.

Returns:

A list of Example objects.

google.adk.memory module

class google.adk.memory.BaseMemoryService

Bases: ABC

Base class for memory services.

The service provides functionalities to ingest sessions into memory so that the memory can be used for user queries.

abstract add_session_to_memory(session)

Adds a session to the memory service.

A session may be added multiple times during its lifetime.

Parameters:

session – The session to add.

abstract search_memory(app_name, user_id, query)

Searches for sessions that match the query.

Return type:

SearchMemoryResponse

Parameters:
  • app_name – The name of the application.

  • user_id – The id of the user.

  • query – The query to search for.

Returns:

A SearchMemoryResponse containing the matching memories.

class google.adk.memory.InMemoryMemoryService

Bases: BaseMemoryService

An in-memory memory service for prototyping purpose only.

Uses keyword matching instead of semantic search.

add_session_to_memory(session)

Adds a session to the memory service.

A session may be added multiple times during its lifetime.

Parameters:

session – The session to add.

search_memory(app_name, user_id, query)

Prototyping purpose only.

Return type:

SearchMemoryResponse

session_events: dict[str, list[Event]]

keys are app_name/user_id/session_id

class google.adk.memory.VertexAiRagMemoryService(rag_corpus=None, similarity_top_k=None, vector_distance_threshold=10)

Bases: BaseMemoryService

A memory service that uses Vertex AI RAG for storage and retrieval.

Initializes a VertexAiRagMemoryService.

Parameters:
  • rag_corpus – The name of the Vertex AI RAG corpus to use. Format: projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id} or {rag_corpus_id}

  • similarity_top_k – The number of contexts to retrieve.

  • vector_distance_threshold – Only returns contexts with vector distance smaller than the threshold..

add_session_to_memory(session)

Adds a session to the memory service.

A session may be added multiple times during its lifetime.

Parameters:

session – The session to add.

search_memory(app_name, user_id, query)

Searches for sessions that match the query using rag.retrieval_query.

Return type:

SearchMemoryResponse

google.adk.models module

google.adk.planners module

google.adk.runners module

google.adk.sessions module

class google.adk.sessions.BaseSessionService

Bases: ABC

Base class for session services.

The service provides a set of methods for managing sessions and events.

append_event(session, event)

Appends an event to a session object.

Return type:

Event

close_session(session)

Closes a session.

abstract create_session(app_name, user_id, state=None, *, session_id=None)

Creates a new session.

Return type:

Session

Parameters:
  • app_name – the name of the app.

  • user_id – the id of the user.

  • state – the initial state of the session.

  • session_id – the client-provided id of the session. If not provided, a generated ID will be used.

Returns:

The newly created session instance.

Return type:

session

abstract delete_session(app_name, user_id, session_id)

Deletes a session.

Return type:

None

abstract get_session(app_name, user_id, session_id, config=None)

Gets a session.

Return type:

Optional[Session]

abstract list_events(app_name, user_id, session_id)

Lists events in a session.

Return type:

ListEventsResponse

abstract list_sessions(app_name, user_id)

Lists all the sessions.

Return type:

ListSessionsResponse

class google.adk.sessions.DatabaseSessionService(db_url)

Bases: BaseSessionService

A session service that uses a database for storage.

Parameters:

db_url – The database URL to connect to.

append_event(session, event)

Appends an event to a session object.

Return type:

Event

create_session(app_name, user_id, state=None, *, session_id=None)

Creates a new session.

Return type:

Session

Parameters:
  • app_name – the name of the app.

  • user_id – the id of the user.

  • state – the initial state of the session.

  • session_id – the client-provided id of the session. If not provided, a generated ID will be used.

Returns:

The newly created session instance.

Return type:

session

delete_session(app_name, user_id, session_id)

Deletes a session.

Return type:

None

get_session(app_name, user_id, session_id, config=None)

Gets a session.

Return type:

Optional[Session]

list_events(app_name, user_id, session_id)

Lists events in a session.

Return type:

ListEventsResponse

list_sessions(app_name, user_id)

Lists all the sessions.

Return type:

ListSessionsResponse

class google.adk.sessions.InMemorySessionService

Bases: BaseSessionService

An in-memory implementation of the session service.

app_state: dict[str, dict[str, Any]] = {}
append_event(session, event)

Appends an event to a session object.

Return type:

Event

create_session(app_name, user_id, state=None, *, session_id=None)

Creates a new session.

Return type:

Session

Parameters:
  • app_name – the name of the app.

  • user_id – the id of the user.

  • state – the initial state of the session.

  • session_id – the client-provided id of the session. If not provided, a generated ID will be used.

Returns:

The newly created session instance.

Return type:

session

delete_session(app_name, user_id, session_id)

Deletes a session.

Return type:

None

get_session(app_name, user_id, session_id, config=None)

Gets a session.

Return type:

Session

list_events(app_name, user_id, session_id)

Lists events in a session.

Return type:

ListEventsResponse

list_sessions(app_name, user_id)

Lists all the sessions.

Return type:

ListSessionsResponse

sessions: dict[str, dict[str, dict[str, Session]]] = {}
user_state: dict[str, dict[str, dict[str, Any]]] = {}
pydantic model google.adk.sessions.Session

Bases: BaseModel

Represents a series of interactions between a user and agents.

id

The unique identifier of the session.

app_name

The name of the app.

user_id

The id of the user.

state

The state of the session.

events

The events of the session, e.g. user input, model response, function call/response, etc.

last_update_time

The last update time of the session.

Show JSON schema
{
   "title": "Session",
   "description": "Represents a series of interactions between a user and agents.\n\nAttributes:\n  id: The unique identifier of the session.\n  app_name: The name of the app.\n  user_id: The id of the user.\n  state: The state of the session.\n  events: The events of the session, e.g. user input, model response, function\n    call/response, etc.\n  last_update_time: The last update time of the session.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "app_name": {
         "title": "App Name",
         "type": "string"
      },
      "user_id": {
         "title": "User Id",
         "type": "string"
      },
      "state": {
         "title": "State",
         "type": "object"
      },
      "events": {
         "items": {
            "$ref": "#/$defs/Event"
         },
         "title": "Events",
         "type": "array"
      },
      "last_update_time": {
         "default": 0.0,
         "title": "Last Update Time",
         "type": "number"
      }
   },
   "$defs": {
      "Blob": {
         "additionalProperties": false,
         "description": "Content blob.",
         "properties": {
            "data": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Raw bytes.",
               "title": "Data"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "Blob",
         "type": "object"
      },
      "CodeExecutionResult": {
         "additionalProperties": false,
         "description": "Result of executing the [ExecutableCode].\n\nAlways follows a `part` containing the [ExecutableCode].",
         "properties": {
            "outcome": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Outcome"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Outcome of the code execution."
            },
            "output": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Contains stdout when code execution is successful, stderr or other description otherwise.",
               "title": "Output"
            }
         },
         "title": "CodeExecutionResult",
         "type": "object"
      },
      "Content": {
         "additionalProperties": false,
         "description": "Contains the multi-part content of a message.",
         "properties": {
            "parts": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/Part"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "List of parts that constitute a single message. Each part may have\n      a different IANA MIME type.",
               "title": "Parts"
            },
            "role": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The producer of the content. Must be either 'user' or\n      'model'. Useful to set for multi-turn conversations, otherwise can be\n      empty. If role is not specified, SDK will determine the role.",
               "title": "Role"
            }
         },
         "title": "Content",
         "type": "object"
      },
      "Event": {
         "additionalProperties": false,
         "description": "Represents an event in a conversation between agents and users.\n\nIt is used to store the content of the conversation, as well as the actions\ntaken by the agents like function calls, etc.\n\nAttributes:\n  invocation_id: The invocation ID of the event.\n  author: \"user\" or the name of the agent, indicating who appended the event\n    to the session.\n  actions: The actions taken by the agent.\n  long_running_tool_ids: The ids of the long running function calls.\n  branch: The branch of the event.\n  id: The unique identifier of the event.\n  timestamp: The timestamp of the event.\n  is_final_response: Whether the event is the final response of the agent.\n  get_function_calls: Returns the function calls in the event.",
         "properties": {
            "content": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Content"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null
            },
            "grounding_metadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/GroundingMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null
            },
            "partial": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Partial"
            },
            "turn_complete": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Turn Complete"
            },
            "error_code": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Error Code"
            },
            "error_message": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Error Message"
            },
            "interrupted": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Interrupted"
            },
            "invocation_id": {
               "default": "",
               "title": "Invocation Id",
               "type": "string"
            },
            "author": {
               "title": "Author",
               "type": "string"
            },
            "actions": {
               "$ref": "#/$defs/EventActions"
            },
            "long_running_tool_ids": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array",
                     "uniqueItems": true
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Long Running Tool Ids"
            },
            "branch": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Branch"
            },
            "id": {
               "default": "",
               "title": "Id",
               "type": "string"
            },
            "timestamp": {
               "title": "Timestamp",
               "type": "number"
            }
         },
         "required": [
            "author"
         ],
         "title": "Event",
         "type": "object"
      },
      "EventActions": {
         "additionalProperties": false,
         "description": "Represents the actions attached to an event.",
         "properties": {
            "skip_summarization": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Skip Summarization"
            },
            "state_delta": {
               "title": "State Delta",
               "type": "object"
            },
            "artifact_delta": {
               "additionalProperties": {
                  "type": "integer"
               },
               "title": "Artifact Delta",
               "type": "object"
            },
            "transfer_to_agent": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Transfer To Agent"
            },
            "escalate": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Escalate"
            },
            "requested_auth_configs": {
               "additionalProperties": {
                  "type": "object"
               },
               "title": "Requested Auth Configs",
               "type": "object"
            }
         },
         "title": "EventActions",
         "type": "object"
      },
      "ExecutableCode": {
         "additionalProperties": false,
         "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the [FunctionDeclaration] tool and\n[FunctionCallingConfig] mode is set to [Mode.CODE].",
         "properties": {
            "code": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The code to be executed.",
               "title": "Code"
            },
            "language": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Language"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. Programming language of the `code`."
            }
         },
         "title": "ExecutableCode",
         "type": "object"
      },
      "FileData": {
         "additionalProperties": false,
         "description": "URI based data.",
         "properties": {
            "fileUri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. URI.",
               "title": "Fileuri"
            },
            "mimeType": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The IANA standard MIME type of the source data.",
               "title": "Mimetype"
            }
         },
         "title": "FileData",
         "type": "object"
      },
      "FunctionCall": {
         "additionalProperties": false,
         "description": "A function call.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The unique id of the function call. If populated, the client to execute the\n   `function_call` and return the response with the matching `id`.",
               "title": "Id"
            },
            "args": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Required. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.",
               "title": "Args"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name].",
               "title": "Name"
            }
         },
         "title": "FunctionCall",
         "type": "object"
      },
      "FunctionResponse": {
         "additionalProperties": false,
         "description": "A function response.",
         "properties": {
            "id": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The id of the function call this response is for. Populated by the client\n   to match the corresponding function call `id`.",
               "title": "Id"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].",
               "title": "Name"
            },
            "response": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Required. The function response in JSON object format. Use \"output\" key to specify function output and \"error\" key to specify error details (if any). If \"output\" and \"error\" keys are not specified, then whole \"response\" is treated as function output.",
               "title": "Response"
            }
         },
         "title": "FunctionResponse",
         "type": "object"
      },
      "GroundingChunk": {
         "additionalProperties": false,
         "description": "Grounding chunk.",
         "properties": {
            "retrievedContext": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/GroundingChunkRetrievedContext"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Grounding chunk from context retrieved by the retrieval tools."
            },
            "web": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/GroundingChunkWeb"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Grounding chunk from the web."
            }
         },
         "title": "GroundingChunk",
         "type": "object"
      },
      "GroundingChunkRetrievedContext": {
         "additionalProperties": false,
         "description": "Chunk from context retrieved by the retrieval tools.",
         "properties": {
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Text of the attribution.",
               "title": "Text"
            },
            "title": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Title of the attribution.",
               "title": "Title"
            },
            "uri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "URI reference of the attribution.",
               "title": "Uri"
            }
         },
         "title": "GroundingChunkRetrievedContext",
         "type": "object"
      },
      "GroundingChunkWeb": {
         "additionalProperties": false,
         "description": "Chunk from the web.",
         "properties": {
            "title": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Title of the chunk.",
               "title": "Title"
            },
            "uri": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "URI reference of the chunk.",
               "title": "Uri"
            }
         },
         "title": "GroundingChunkWeb",
         "type": "object"
      },
      "GroundingMetadata": {
         "additionalProperties": false,
         "description": "Metadata returned to client when grounding is enabled.",
         "properties": {
            "groundingChunks": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/GroundingChunk"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "List of supporting references retrieved from specified grounding source.",
               "title": "Groundingchunks"
            },
            "groundingSupports": {
               "anyOf": [
                  {
                     "items": {
                        "$ref": "#/$defs/GroundingSupport"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. List of grounding support.",
               "title": "Groundingsupports"
            },
            "retrievalMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/RetrievalMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Output only. Retrieval metadata."
            },
            "retrievalQueries": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Queries executed by the retrieval tools.",
               "title": "Retrievalqueries"
            },
            "searchEntryPoint": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/SearchEntryPoint"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Google search entry for the following-up web searches."
            },
            "webSearchQueries": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Web search queries for the following-up web search.",
               "title": "Websearchqueries"
            }
         },
         "title": "GroundingMetadata",
         "type": "object"
      },
      "GroundingSupport": {
         "additionalProperties": false,
         "description": "Grounding support.",
         "properties": {
            "confidenceScores": {
               "anyOf": [
                  {
                     "items": {
                        "type": "number"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Confidence score of the support references. Ranges from 0 to 1. 1 is the most confident. This list must have the same size as the grounding_chunk_indices.",
               "title": "Confidencescores"
            },
            "groundingChunkIndices": {
               "anyOf": [
                  {
                     "items": {
                        "type": "integer"
                     },
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "A list of indices (into 'grounding_chunk') specifying the citations associated with the claim. For instance [1,3,4] means that grounding_chunk[1], grounding_chunk[3], grounding_chunk[4] are the retrieved content attributed to the claim.",
               "title": "Groundingchunkindices"
            },
            "segment": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Segment"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Segment of the content this support belongs to."
            }
         },
         "title": "GroundingSupport",
         "type": "object"
      },
      "Language": {
         "description": "Required. Programming language of the `code`.",
         "enum": [
            "LANGUAGE_UNSPECIFIED",
            "PYTHON"
         ],
         "title": "Language",
         "type": "string"
      },
      "Outcome": {
         "description": "Required. Outcome of the code execution.",
         "enum": [
            "OUTCOME_UNSPECIFIED",
            "OUTCOME_OK",
            "OUTCOME_FAILED",
            "OUTCOME_DEADLINE_EXCEEDED"
         ],
         "title": "Outcome",
         "type": "string"
      },
      "Part": {
         "additionalProperties": false,
         "description": "A datatype containing media content.\n\nExactly one field within a Part should be set, representing the specific type\nof content being conveyed. Using multiple fields within the same `Part`\ninstance is considered invalid.",
         "properties": {
            "videoMetadata": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/VideoMetadata"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Metadata for a given video."
            },
            "thought": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Indicates if the part is thought from the model.",
               "title": "Thought"
            },
            "codeExecutionResult": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/CodeExecutionResult"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Result of executing the [ExecutableCode]."
            },
            "executableCode": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/ExecutableCode"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Code generated by the model that is meant to be executed."
            },
            "fileData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FileData"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. URI based data."
            },
            "functionCall": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionCall"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values."
            },
            "functionResponse": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/FunctionResponse"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model."
            },
            "inlineData": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Blob"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Inlined bytes data."
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Text part (can be code).",
               "title": "Text"
            }
         },
         "title": "Part",
         "type": "object"
      },
      "RetrievalMetadata": {
         "additionalProperties": false,
         "description": "Metadata related to retrieval in the grounding flow.",
         "properties": {
            "googleSearchDynamicRetrievalScore": {
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Score indicating how likely information from Google Search could help answer the prompt. The score is in the range `[0, 1]`, where 0 is the least likely and 1 is the most likely. This score is only populated when Google Search grounding and dynamic retrieval is enabled. It will be compared to the threshold to determine whether to trigger Google Search.",
               "title": "Googlesearchdynamicretrievalscore"
            }
         },
         "title": "RetrievalMetadata",
         "type": "object"
      },
      "SearchEntryPoint": {
         "additionalProperties": false,
         "description": "Google search entry point.",
         "properties": {
            "renderedContent": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Web content snippet that can be embedded in a web page or an app webview.",
               "title": "Renderedcontent"
            },
            "sdkBlob": {
               "anyOf": [
                  {
                     "format": "base64url",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. Base64 encoded JSON representing array of tuple.",
               "title": "Sdkblob"
            }
         },
         "title": "SearchEntryPoint",
         "type": "object"
      },
      "Segment": {
         "additionalProperties": false,
         "description": "Segment of the content.",
         "properties": {
            "endIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. End index in the given Part, measured in bytes. Offset from the start of the Part, exclusive, starting at zero.",
               "title": "Endindex"
            },
            "partIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. The index of a Part object within its parent Content object.",
               "title": "Partindex"
            },
            "startIndex": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. Start index in the given Part, measured in bytes. Offset from the start of the Part, inclusive, starting at zero.",
               "title": "Startindex"
            },
            "text": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Output only. The text corresponding to the segment from the response.",
               "title": "Text"
            }
         },
         "title": "Segment",
         "type": "object"
      },
      "VideoMetadata": {
         "additionalProperties": false,
         "description": "Metadata describes the input video content.",
         "properties": {
            "endOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The end offset of the video.",
               "title": "Endoffset"
            },
            "startOffset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Optional. The start offset of the video.",
               "title": "Startoffset"
            }
         },
         "title": "VideoMetadata",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "id",
      "app_name",
      "user_id"
   ]
}

Fields:
  • app_name (str)

  • events (list[google.adk.events.event.Event])

  • id (str)

  • last_update_time (float)

  • state (dict[str, Any])

  • user_id (str)

field app_name: str [Required]

The name of the app.

field events: list[Event] [Optional]

The events of the session, e.g. user input, model response, function call/response, etc.

field id: str [Required]

The unique identifier of the session.

field last_update_time: float = 0.0

The last update time of the session.

field state: dict[str, Any] [Optional]

The state of the session.

field user_id: str [Required]

The id of the user.

class google.adk.sessions.State(value, delta)

Bases: object

A state dict that maintain the current value and the pending-commit delta.

Parameters:
  • value – The current value of the state dict.

  • delta – The delta change to the current value that hasn’t been commited.

APP_PREFIX = 'app:'
TEMP_PREFIX = 'temp:'
USER_PREFIX = 'user:'
get(key, default=None)

Returns the value of the state dict for the given key.

Return type:

Any

has_delta()

Whether the state has pending detla.

Return type:

bool

to_dict()

Returns the state dict.

Return type:

dict[str, Any]

update(delta)

Updates the state dict with the given delta.

class google.adk.sessions.VertexAiSessionService(project=None, location=None)

Bases: BaseSessionService

Connects to the managed Vertex AI Session Service.

append_event(session, event)

Appends an event to a session object.

Return type:

Event

create_session(app_name, user_id, state=None, *, session_id=None)

Creates a new session.

Return type:

Session

Parameters:
  • app_name – the name of the app.

  • user_id – the id of the user.

  • state – the initial state of the session.

  • session_id – the client-provided id of the session. If not provided, a generated ID will be used.

Returns:

The newly created session instance.

Return type:

session

delete_session(app_name, user_id, session_id)

Deletes a session.

Return type:

None

get_session(app_name, user_id, session_id, config=None)

Gets a session.

Return type:

Session

list_events(app_name, user_id, session_id)

Lists events in a session.

Return type:

ListEventsResponse

list_sessions(app_name, user_id)

Lists all the sessions.

Return type:

ListSessionsResponse

google.adk.tools module