Submodules¶
google.adk.agents module¶
- pydantic model google.adk.agents.BaseAgent¶
Bases:
BaseModel
Base class for all agents in Agent Development Kit.
Show JSON schema
{ "title": "BaseAgent", "type": "object", "properties": { "name": { "title": "Name", "type": "string" }, "description": { "default": "", "title": "Description", "type": "string" }, "parent_agent": { "default": null, "title": "Parent Agent" }, "sub_agents": { "default": null, "title": "Sub Agents" }, "before_agent_callback": { "default": null, "title": "Before Agent Callback" }, "after_agent_callback": { "default": null, "title": "After Agent Callback" } }, "additionalProperties": false, "required": [ "name" ] }
- Fields:
after_agent_callback (Callable[[google.adk.agents.callback_context.CallbackContext], google.genai.types.Content | None] | None)
before_agent_callback (Callable[[google.adk.agents.callback_context.CallbackContext], google.genai.types.Content | None] | None)
description (str)
name (str)
parent_agent (google.adk.agents.base_agent.BaseAgent | None)
sub_agents (list[google.adk.agents.base_agent.BaseAgent])
- Validators:
__validate_name
»name
- field after_agent_callback: Optional[AfterAgentCallback] = None¶
Callback signature that is invoked after the agent run.
- Parameters:
callback_context – MUST be named ‘callback_context’ (enforced).
- Returns:
The content to return to the user. When set, the agent run will skipped and the provided content will be appended to event history as agent response.
- field before_agent_callback: Optional[BeforeAgentCallback] = None¶
Callback signature that is invoked before the agent run.
- Parameters:
callback_context – MUST be named ‘callback_context’ (enforced).
- Returns:
The content to return to the user. When set, the agent run will skipped and the provided content will be returned to user.
- field description: str = ''¶
Description about the agent’s capability.
The model uses this to determine whether to delegate control to the agent. One-line description is enough and preferred.
- field name: str [Required]¶
The agent’s name.
Agent name must be a Python identifier and unique within the agent tree. Agent name cannot be “user”, since it’s reserved for end-user’s input.
- Validated by:
__validate_name
- field parent_agent: Optional[BaseAgent] = None¶
The parent agent of this agent.
Note that an agent can ONLY be added as sub-agent once.
If you want to add one agent twice as sub-agent, consider to create two agent instances with identical config, but with different name and add them to the agent tree.
- field sub_agents: list[BaseAgent] [Optional]¶
The sub-agents of this agent.
- find_agent(name)¶
Finds the agent with the given name in this agent and its descendants.
- Return type:
Optional
[BaseAgent
]- Parameters:
name – The name of the agent to find.
- Returns:
The agent with the matching name, or None if no such agent is found.
- find_sub_agent(name)¶
Finds the agent with the given name in this agent’s descendants.
- Return type:
Optional
[BaseAgent
]- Parameters:
name – The name of the agent to find.
- Returns:
The agent with the matching name, or None if no such agent is found.
- model_post_init(_BaseAgent__context)¶
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Return type:
None
- final async run_async(parent_context)¶
Entry method to run an agent via text-based conversaction.
- Return type:
AsyncGenerator
[Event
,None
]- Parameters:
parent_context – InvocationContext, the invocation context of the parent agent.
- Yields:
Event – the events generated by the agent.
- pydantic model google.adk.agents.LlmAgent¶
Bases:
BaseAgent
LLM-based Agent.
Show JSON schema
{ "title": "LlmAgent", "type": "object", "properties": { "name": { "title": "Name", "type": "string" }, "description": { "default": "", "title": "Description", "type": "string" }, "parent_agent": { "default": null, "title": "Parent Agent" }, "sub_agents": { "default": null, "title": "Sub Agents" }, "before_agent_callback": { "default": null, "title": "Before Agent Callback" }, "after_agent_callback": { "default": null, "title": "After Agent Callback" }, "model": { "anyOf": [ { "type": "string" }, { "$ref": "#/$defs/BaseLlm" } ], "default": "", "title": "Model" }, "instruction": { "default": "", "title": "Instruction", "type": "string" }, "global_instruction": { "default": "", "title": "Global Instruction", "type": "string" }, "tools": { "items": { "anyOf": [] }, "title": "Tools", "type": "array" }, "generate_content_config": { "anyOf": [ { "$ref": "#/$defs/GenerateContentConfig" }, { "type": "null" } ], "default": null }, "disallow_transfer_to_parent": { "default": false, "title": "Disallow Transfer To Parent", "type": "boolean" }, "disallow_transfer_to_peers": { "default": false, "title": "Disallow Transfer To Peers", "type": "boolean" }, "include_contents": { "default": "default", "enum": [ "default", "none" ], "title": "Include Contents", "type": "string" }, "input_schema": { "anyOf": [ {}, { "type": "null" } ], "default": null, "title": "Input Schema" }, "output_schema": { "anyOf": [ {}, { "type": "null" } ], "default": null, "title": "Output Schema" }, "output_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Output Key" }, "planner": { "default": null, "title": "Planner" }, "code_executor": { "anyOf": [ { "$ref": "#/$defs/BaseCodeExecutor" }, { "type": "null" } ], "default": null }, "examples": { "anyOf": [ { "items": { "$ref": "#/$defs/Example" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Examples" }, "before_model_callback": { "default": null, "title": "Before Model Callback" }, "after_model_callback": { "default": null, "title": "After Model Callback" }, "before_tool_callback": { "default": null, "title": "Before Tool Callback" }, "after_tool_callback": { "default": null, "title": "After Tool Callback" } }, "$defs": { "AutomaticFunctionCallingConfig": { "additionalProperties": false, "description": "The configuration for automatic function calling.", "properties": { "disable": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "Whether to disable automatic function calling.\n If not set or set to False, will enable automatic function calling.\n If set to True, will disable automatic function calling.\n ", "title": "Disable" }, "maximumRemoteCalls": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": 10, "description": "If automatic function calling is enabled,\n maximum number of remote calls for automatic function calling.\n This number should be a positive integer.\n If not set, SDK will set maximum number of remote calls to 10.\n ", "title": "Maximumremotecalls" }, "ignoreCallHistory": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "If automatic function calling is enabled,\n whether to ignore call history to the response.\n If not set, SDK will set ignore_call_history to false,\n and will append the call history to\n GenerateContentResponse.automatic_function_calling_history.\n ", "title": "Ignorecallhistory" } }, "title": "AutomaticFunctionCallingConfig", "type": "object" }, "BaseCodeExecutor": { "description": "Abstract base class for all code executors.\n\nThe code executor allows the agent to execute code blocks from model responses\nand incorporate the execution results into the final response.\n\nAttributes:\n optimize_data_file: If true, extract and process data files from the model\n request and attach them to the code executor. Supported data file\n MimeTypes are [text/csv]. Default to False.\n stateful: Whether the code executor is stateful. Default to False.\n error_retry_attempts: The number of attempts to retry on consecutive code\n execution errors. Default to 2.\n code_block_delimiters: The list of the enclosing delimiters to identify the\n code blocks.\n execution_result_delimiters: The delimiters to format the code execution\n result.", "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" } }, "title": "BaseCodeExecutor", "type": "object" }, "BaseLlm": { "description": "The BaseLLM class.\n\nAttributes:\n model: The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.\n model_config: The model config", "properties": { "model": { "title": "Model", "type": "string" } }, "required": [ "model" ], "title": "BaseLlm", "type": "object" }, "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" }, "DynamicRetrievalConfig": { "additionalProperties": false, "description": "Describes the options to customize dynamic retrieval.", "properties": { "mode": { "anyOf": [ { "$ref": "#/$defs/DynamicRetrievalConfigMode" }, { "type": "null" } ], "default": null, "description": "The mode of the predictor to be used in dynamic retrieval." }, "dynamicThreshold": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is used.", "title": "Dynamicthreshold" } }, "title": "DynamicRetrievalConfig", "type": "object" }, "DynamicRetrievalConfigMode": { "description": "Config for the dynamic retrieval config mode.", "enum": [ "MODE_UNSPECIFIED", "MODE_DYNAMIC" ], "title": "DynamicRetrievalConfigMode", "type": "string" }, "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.", "properties": { "input": { "$ref": "#/$defs/Content" }, "output": { "items": { "$ref": "#/$defs/Content" }, "title": "Output", "type": "array" } }, "required": [ "input", "output" ], "title": "Example", "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" }, "File": { "additionalProperties": false, "description": "A file uploaded to the API.", "properties": { "name": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The `File` resource name. The ID (name excluding the \"files/\" prefix) can contain up to 40 characters that are lowercase alphanumeric or dashes (-). The ID cannot start or end with a dash. If the name is empty on create, a unique name will be generated. Example: `files/123-456`", "title": "Name" }, "displayName": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. The human-readable display name for the `File`. The display name must be no more than 512 characters in length, including spaces. Example: 'Welcome Image'", "title": "Displayname" }, "mimeType": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. MIME type of the file.", "title": "Mimetype" }, "sizeBytes": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Output only. Size of the file in bytes.", "title": "Sizebytes" }, "createTime": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. The timestamp of when the `File` was created.", "title": "Createtime" }, "expirationTime": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. The timestamp of when the `File` will be deleted. Only set if the `File` is scheduled to expire.", "title": "Expirationtime" }, "updateTime": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. The timestamp of when the `File` was last updated.", "title": "Updatetime" }, "sha256Hash": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. SHA-256 hash of the uploaded bytes. The hash value is encoded in base64 format.", "title": "Sha256Hash" }, "uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. The URI of the `File`.", "title": "Uri" }, "downloadUri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Output only. The URI of the `File`, only set for downloadable (generated) files.", "title": "Downloaduri" }, "state": { "anyOf": [ { "$ref": "#/$defs/FileState" }, { "type": "null" } ], "default": null, "description": "Output only. Processing state of the File." }, "source": { "anyOf": [ { "$ref": "#/$defs/FileSource" }, { "type": "null" } ], "default": null, "description": "Output only. The source of the `File`." }, "videoMetadata": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "type": "null" } ], "default": null, "description": "Output only. Metadata for a video.", "title": "Videometadata" }, "error": { "anyOf": [ { "$ref": "#/$defs/FileStatus" }, { "type": "null" } ], "default": null, "description": "Output only. Error status if File processing failed." } }, "title": "File", "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" }, "FileSource": { "description": "Source of the File.", "enum": [ "SOURCE_UNSPECIFIED", "UPLOADED", "GENERATED" ], "title": "FileSource", "type": "string" }, "FileState": { "description": "State for the lifecycle of a File.", "enum": [ "STATE_UNSPECIFIED", "PROCESSING", "ACTIVE", "FAILED" ], "title": "FileState", "type": "string" }, "FileStatus": { "additionalProperties": false, "description": "Status of a File that uses a common error model.", "properties": { "details": { "anyOf": [ { "items": { "additionalProperties": true, "type": "object" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "A list of messages that carry the error details. There is a common set of message types for APIs to use.", "title": "Details" }, "message": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "A list of messages that carry the error details. There is a common set of message types for APIs to use.", "title": "Message" }, "code": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "The status code. 0 for OK, 1 for CANCELLED", "title": "Code" } }, "title": "FileStatus", "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": [ { "additionalProperties": true, "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" }, "FunctionCallingConfig": { "additionalProperties": false, "description": "Function calling config.", "properties": { "mode": { "anyOf": [ { "$ref": "#/$defs/FunctionCallingConfigMode" }, { "type": "null" } ], "default": null, "description": "Optional. Function calling mode." }, "allowedFunctionNames": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. Function names to call. Only set when the Mode is ANY. Function names should match [FunctionDeclaration.name]. With mode set to ANY, model will predict a function call from the set of function names provided.", "title": "Allowedfunctionnames" } }, "title": "FunctionCallingConfig", "type": "object" }, "FunctionCallingConfigMode": { "description": "Config for the function calling config mode.", "enum": [ "MODE_UNSPECIFIED", "AUTO", "ANY", "NONE" ], "title": "FunctionCallingConfigMode", "type": "string" }, "FunctionDeclaration": { "additionalProperties": false, "description": "Defines a function that the model can generate JSON inputs for.\n\nThe inputs are based on `OpenAPI 3.0 specifications\n<https://spec.openapis.org/oas/v3.0.3>`_.", "properties": { "response": { "anyOf": [ { "$ref": "#/$defs/Schema" }, { "type": "null" } ], "default": null, "description": "Describes the output from the function in the OpenAPI JSON Schema\n Object format." }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function.", "title": "Description" }, "name": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Required. The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores, dots and dashes, with a maximum length of 64.", "title": "Name" }, "parameters": { "anyOf": [ { "$ref": "#/$defs/Schema" }, { "type": "null" } ], "default": null, "description": "Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. Parameter names must start with a letter or an underscore and must only contain chars a-z, A-Z, 0-9, or underscores with a maximum length of 64. Example with 1 required and 1 optional parameter: type: OBJECT properties: param1: type: STRING param2: type: INTEGER required: - param1" } }, "title": "FunctionDeclaration", "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": [ { "additionalProperties": true, "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" }, "GenerateContentConfig": { "additionalProperties": false, "description": "Optional model configuration parameters.\n\nFor more information, see `Content generation parameters\n<https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/content-generation-parameters>`_.", "properties": { "httpOptions": { "anyOf": [ { "$ref": "#/$defs/HttpOptions" }, { "type": "null" } ], "default": null, "description": "Used to override HTTP request options." }, "systemInstruction": { "anyOf": [ { "$ref": "#/$defs/Content" }, { "items": { "anyOf": [ { "$ref": "#/$defs/File" }, { "$ref": "#/$defs/Part" }, { "type": "string" } ] }, "type": "array" }, { "$ref": "#/$defs/File" }, { "$ref": "#/$defs/Part" }, { "type": "string" }, { "type": "null" } ], "default": null, "description": "Instructions for the model to steer it toward better performance.\n For example, \"Answer as concisely as possible\" or \"Don't use technical\n terms in your response\".\n ", "title": "Systeminstruction" }, "temperature": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Value that controls the degree of randomness in token selection.\n Lower temperatures are good for prompts that require a less open-ended or\n creative response, while higher temperatures can lead to more diverse or\n creative results.\n ", "title": "Temperature" }, "topP": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Tokens are selected from the most to least probable until the sum\n of their probabilities equals this value. Use a lower value for less\n random responses and a higher value for more random responses.\n ", "title": "Topp" }, "topK": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "For each token selection step, the ``top_k`` tokens with the\n highest probabilities are sampled. Then tokens are further filtered based\n on ``top_p`` with the final token selected using temperature sampling. Use\n a lower number for less random responses and a higher number for more\n random responses.\n ", "title": "Topk" }, "candidateCount": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Number of response variations to return.\n ", "title": "Candidatecount" }, "maxOutputTokens": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Maximum number of tokens that can be generated in the response.\n ", "title": "Maxoutputtokens" }, "stopSequences": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "List of strings that tells the model to stop generating text if one\n of the strings is encountered in the response.\n ", "title": "Stopsequences" }, "responseLogprobs": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "Whether to return the log probabilities of the tokens that were\n chosen by the model at each step.\n ", "title": "Responselogprobs" }, "logprobs": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Number of top candidate tokens to return the log probabilities for\n at each generation step.\n ", "title": "Logprobs" }, "presencePenalty": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Positive values penalize tokens that already appear in the\n generated text, increasing the probability of generating more diverse\n content.\n ", "title": "Presencepenalty" }, "frequencyPenalty": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Positive values penalize tokens that repeatedly appear in the\n generated text, increasing the probability of generating more diverse\n content.\n ", "title": "Frequencypenalty" }, "seed": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "When ``seed`` is fixed to a specific number, the model makes a best\n effort to provide the same response for repeated requests. By default, a\n random number is used.\n ", "title": "Seed" }, "responseMimeType": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Output response media type of the generated candidate text.\n ", "title": "Responsemimetype" }, "responseSchema": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "$ref": "#/$defs/Schema" }, { "type": "null" } ], "default": null, "description": "Schema that the generated candidate text must adhere to.\n ", "title": "Responseschema" }, "routingConfig": { "anyOf": [ { "$ref": "#/$defs/GenerationConfigRoutingConfig" }, { "type": "null" } ], "default": null, "description": "Configuration for model router requests.\n " }, "safetySettings": { "anyOf": [ { "items": { "$ref": "#/$defs/SafetySetting" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Safety settings in the request to block unsafe content in the\n response.\n ", "title": "Safetysettings" }, "tools": { "anyOf": [ { "items": { "$ref": "#/$defs/Tool" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Code that enables the system to interact with external systems to\n perform an action outside of the knowledge and scope of the model.\n ", "title": "Tools" }, "toolConfig": { "anyOf": [ { "$ref": "#/$defs/ToolConfig" }, { "type": "null" } ], "default": null, "description": "Associates model output to a specific function call.\n " }, "labels": { "anyOf": [ { "additionalProperties": { "type": "string" }, "type": "object" }, { "type": "null" } ], "default": null, "description": "Labels with user-defined metadata to break down billed charges.", "title": "Labels" }, "cachedContent": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Resource name of a context cache that can be used in subsequent\n requests.\n ", "title": "Cachedcontent" }, "responseModalities": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "The requested modalities of the response. Represents the set of\n modalities that the model can return.\n ", "title": "Responsemodalities" }, "mediaResolution": { "anyOf": [ { "$ref": "#/$defs/MediaResolution" }, { "type": "null" } ], "default": null, "description": "If specified, the media resolution specified will be used.\n " }, "speechConfig": { "anyOf": [ { "$ref": "#/$defs/SpeechConfig" }, { "type": "string" }, { "type": "null" } ], "default": null, "description": "The speech generation configuration.\n ", "title": "Speechconfig" }, "audioTimestamp": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "If enabled, audio timestamp will be included in the request to the\n model.\n ", "title": "Audiotimestamp" }, "automaticFunctionCalling": { "anyOf": [ { "$ref": "#/$defs/AutomaticFunctionCallingConfig" }, { "type": "null" } ], "default": null, "description": "The configuration for automatic function calling.\n " }, "thinkingConfig": { "anyOf": [ { "$ref": "#/$defs/ThinkingConfig" }, { "type": "null" } ], "default": null, "description": "The thinking features configuration.\n " } }, "title": "GenerateContentConfig", "type": "object" }, "GenerationConfigRoutingConfig": { "additionalProperties": false, "description": "The configuration for routing the request to a specific model.", "properties": { "autoMode": { "anyOf": [ { "$ref": "#/$defs/GenerationConfigRoutingConfigAutoRoutingMode" }, { "type": "null" } ], "default": null, "description": "Automated routing." }, "manualMode": { "anyOf": [ { "$ref": "#/$defs/GenerationConfigRoutingConfigManualRoutingMode" }, { "type": "null" } ], "default": null, "description": "Manual routing." } }, "title": "GenerationConfigRoutingConfig", "type": "object" }, "GenerationConfigRoutingConfigAutoRoutingMode": { "additionalProperties": false, "description": "When automated routing is specified, the routing will be determined by the pretrained routing model and customer provided model routing preference.", "properties": { "modelRoutingPreference": { "anyOf": [ { "enum": [ "UNKNOWN", "PRIORITIZE_QUALITY", "BALANCED", "PRIORITIZE_COST" ], "type": "string" }, { "type": "null" } ], "default": null, "description": "The model routing preference.", "title": "Modelroutingpreference" } }, "title": "GenerationConfigRoutingConfigAutoRoutingMode", "type": "object" }, "GenerationConfigRoutingConfigManualRoutingMode": { "additionalProperties": false, "description": "When manual routing is set, the specified model will be used directly.", "properties": { "modelName": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The model name to use. Only the public LLM models are accepted. e.g. 'gemini-1.5-pro-001'.", "title": "Modelname" } }, "title": "GenerationConfigRoutingConfigManualRoutingMode", "type": "object" }, "GoogleSearch": { "additionalProperties": false, "description": "Tool to support Google Search in Model. Powered by Google.", "properties": {}, "title": "GoogleSearch", "type": "object" }, "GoogleSearchRetrieval": { "additionalProperties": false, "description": "Tool to retrieve public web data for grounding, powered by Google.", "properties": { "dynamicRetrievalConfig": { "anyOf": [ { "$ref": "#/$defs/DynamicRetrievalConfig" }, { "type": "null" } ], "default": null, "description": "Specifies the dynamic retrieval configuration for the given source." } }, "title": "GoogleSearchRetrieval", "type": "object" }, "HarmBlockMethod": { "description": "Optional.\n\nSpecify if the threshold is used for probability or severity score. If not\nspecified, the threshold is used for probability score.", "enum": [ "HARM_BLOCK_METHOD_UNSPECIFIED", "SEVERITY", "PROBABILITY" ], "title": "HarmBlockMethod", "type": "string" }, "HarmBlockThreshold": { "description": "Required. The harm block threshold.", "enum": [ "HARM_BLOCK_THRESHOLD_UNSPECIFIED", "BLOCK_LOW_AND_ABOVE", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_ONLY_HIGH", "BLOCK_NONE", "OFF" ], "title": "HarmBlockThreshold", "type": "string" }, "HarmCategory": { "description": "Required. Harm category.", "enum": [ "HARM_CATEGORY_UNSPECIFIED", "HARM_CATEGORY_HATE_SPEECH", "HARM_CATEGORY_DANGEROUS_CONTENT", "HARM_CATEGORY_HARASSMENT", "HARM_CATEGORY_SEXUALLY_EXPLICIT", "HARM_CATEGORY_CIVIC_INTEGRITY" ], "title": "HarmCategory", "type": "string" }, "HttpOptions": { "additionalProperties": false, "description": "HTTP options to be used in each of the requests.", "properties": { "baseUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The base URL for the AI platform service endpoint.", "title": "Baseurl" }, "apiVersion": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Specifies the version of the API to use.", "title": "Apiversion" }, "headers": { "anyOf": [ { "additionalProperties": { "type": "string" }, "type": "object" }, { "type": "null" } ], "default": null, "description": "Additional HTTP headers to be sent with the request.", "title": "Headers" }, "timeout": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Timeout for the request in milliseconds.", "title": "Timeout" } }, "title": "HttpOptions", "type": "object" }, "Language": { "description": "Required. Programming language of the `code`.", "enum": [ "LANGUAGE_UNSPECIFIED", "PYTHON" ], "title": "Language", "type": "string" }, "MediaResolution": { "description": "The media resolution to use.", "enum": [ "MEDIA_RESOLUTION_UNSPECIFIED", "MEDIA_RESOLUTION_LOW", "MEDIA_RESOLUTION_MEDIUM", "MEDIA_RESOLUTION_HIGH" ], "title": "MediaResolution", "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" }, "PrebuiltVoiceConfig": { "additionalProperties": false, "description": "The configuration for the prebuilt speaker to use.", "properties": { "voiceName": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The name of the prebuilt voice to use.\n ", "title": "Voicename" } }, "title": "PrebuiltVoiceConfig", "type": "object" }, "Retrieval": { "additionalProperties": false, "description": "Defines a retrieval tool that model can call to access external knowledge.", "properties": { "disableAttribution": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "Optional. Deprecated. This option is no longer supported.", "title": "Disableattribution" }, "vertexAiSearch": { "anyOf": [ { "$ref": "#/$defs/VertexAISearch" }, { "type": "null" } ], "default": null, "description": "Set to use data source powered by Vertex AI Search." }, "vertexRagStore": { "anyOf": [ { "$ref": "#/$defs/VertexRagStore" }, { "type": "null" } ], "default": null, "description": "Set to use data source powered by Vertex RAG store. User data is uploaded via the VertexRagDataService." } }, "title": "Retrieval", "type": "object" }, "SafetySetting": { "additionalProperties": false, "description": "Safety settings.", "properties": { "method": { "anyOf": [ { "$ref": "#/$defs/HarmBlockMethod" }, { "type": "null" } ], "default": null, "description": "Determines if the harm block method uses probability or probability\n and severity scores." }, "category": { "anyOf": [ { "$ref": "#/$defs/HarmCategory" }, { "type": "null" } ], "default": null, "description": "Required. Harm category." }, "threshold": { "anyOf": [ { "$ref": "#/$defs/HarmBlockThreshold" }, { "type": "null" } ], "default": null, "description": "Required. The harm block threshold." } }, "title": "SafetySetting", "type": "object" }, "Schema": { "additionalProperties": false, "description": "Schema that defines the format of input and output data.\n\nRepresents a select subset of an OpenAPI 3.0 schema object.", "properties": { "example": { "anyOf": [ {}, { "type": "null" } ], "default": null, "description": "Optional. Example of the object. Will only populated when the object is the root.", "title": "Example" }, "pattern": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. Pattern of the Type.STRING to restrict a string to a regular expression.", "title": "Pattern" }, "default": { "anyOf": [ {}, { "type": "null" } ], "default": null, "description": "Optional. Default value of the data.", "title": "Default" }, "maxLength": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Maximum length of the Type.STRING", "title": "Maxlength" }, "minLength": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING", "title": "Minlength" }, "minProperties": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Minimum number of the properties for Type.OBJECT.", "title": "Minproperties" }, "maxProperties": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Maximum number of the properties for Type.OBJECT.", "title": "Maxproperties" }, "anyOf": { "anyOf": [ { "items": { "$ref": "#/$defs/Schema" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. The value should be validated against any (one or more) of the subschemas in the list.", "title": "Anyof" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. The description of the data.", "title": "Description" }, "enum": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. Possible values of the element of primitive type with enum format. Examples: 1. We can define direction as : {type:STRING, format:enum, enum:[\"EAST\", NORTH\", \"SOUTH\", \"WEST\"]} 2. We can define apartment number as : {type:INTEGER, format:enum, enum:[\"101\", \"201\", \"301\"]}", "title": "Enum" }, "format": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. The format of the data. Supported formats: for NUMBER type: \"float\", \"double\" for INTEGER type: \"int32\", \"int64\" for STRING type: \"email\", \"byte\", etc", "title": "Format" }, "items": { "anyOf": [ { "$ref": "#/$defs/Schema" }, { "type": "null" } ], "default": null, "description": "Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY." }, "maxItems": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Maximum number of the elements for Type.ARRAY.", "title": "Maxitems" }, "maximum": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Optional. Maximum value of the Type.INTEGER and Type.NUMBER", "title": "Maximum" }, "minItems": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Minimum number of the elements for Type.ARRAY.", "title": "Minitems" }, "minimum": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and Type.NUMBER", "title": "Minimum" }, "nullable": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "Optional. Indicates if the value may be null.", "title": "Nullable" }, "properties": { "anyOf": [ { "additionalProperties": { "$ref": "#/$defs/Schema" }, "type": "object" }, { "type": "null" } ], "default": null, "description": "Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.", "title": "Properties" }, "propertyOrdering": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. The order of the properties. Not a standard field in open api spec. Only used to support the order of the properties.", "title": "Propertyordering" }, "required": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. Required properties of Type.OBJECT.", "title": "Required" }, "title": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. The title of the Schema.", "title": "Title" }, "type": { "anyOf": [ { "$ref": "#/$defs/Type" }, { "type": "null" } ], "default": null, "description": "Optional. The type of the data." } }, "title": "Schema", "type": "object" }, "SpeechConfig": { "additionalProperties": false, "description": "The speech generation configuration.", "properties": { "voiceConfig": { "anyOf": [ { "$ref": "#/$defs/VoiceConfig" }, { "type": "null" } ], "default": null, "description": "The configuration for the speaker to use.\n " } }, "title": "SpeechConfig", "type": "object" }, "ThinkingConfig": { "additionalProperties": false, "description": "The thinking features configuration.", "properties": { "includeThoughts": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "description": "Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available.\n ", "title": "Includethoughts" } }, "title": "ThinkingConfig", "type": "object" }, "Tool": { "additionalProperties": false, "description": "Tool details of a tool that the model may use to generate a response.", "properties": { "functionDeclarations": { "anyOf": [ { "items": { "$ref": "#/$defs/FunctionDeclaration" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "List of function declarations that the tool supports.", "title": "Functiondeclarations" }, "retrieval": { "anyOf": [ { "$ref": "#/$defs/Retrieval" }, { "type": "null" } ], "default": null, "description": "Optional. Retrieval tool type. System will always execute the provided retrieval tool(s) to get external knowledge to answer the prompt. Retrieval results are presented to the model for generation." }, "googleSearch": { "anyOf": [ { "$ref": "#/$defs/GoogleSearch" }, { "type": "null" } ], "default": null, "description": "Optional. Google Search tool type. Specialized retrieval tool\n that is powered by Google Search." }, "googleSearchRetrieval": { "anyOf": [ { "$ref": "#/$defs/GoogleSearchRetrieval" }, { "type": "null" } ], "default": null, "description": "Optional. GoogleSearchRetrieval tool type. Specialized retrieval tool that is powered by Google search." }, "codeExecution": { "anyOf": [ { "$ref": "#/$defs/ToolCodeExecution" }, { "type": "null" } ], "default": null, "description": "Optional. CodeExecution tool type. Enables the model to execute code as part of generation. This field is only used by the Gemini Developer API services." } }, "title": "Tool", "type": "object" }, "ToolCodeExecution": { "additionalProperties": false, "description": "Tool that executes code generated by the model, and automatically returns the result to the model.\n\nSee also [ExecutableCode]and [CodeExecutionResult] which are input and output\nto this tool.", "properties": {}, "title": "ToolCodeExecution", "type": "object" }, "ToolConfig": { "additionalProperties": false, "description": "Tool config.\n\nThis config is shared for all tools provided in the request.", "properties": { "functionCallingConfig": { "anyOf": [ { "$ref": "#/$defs/FunctionCallingConfig" }, { "type": "null" } ], "default": null, "description": "Optional. Function calling config." } }, "title": "ToolConfig", "type": "object" }, "Type": { "description": "Optional. The type of the data.", "enum": [ "TYPE_UNSPECIFIED", "STRING", "NUMBER", "INTEGER", "BOOLEAN", "ARRAY", "OBJECT" ], "title": "Type", "type": "string" }, "VertexAISearch": { "additionalProperties": false, "description": "Retrieve from Vertex AI Search datastore or engine for grounding.\n\ndatastore and engine are mutually exclusive. See\nhttps://cloud.google.com/products/agent-builder", "properties": { "datastore": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`", "title": "Datastore" }, "engine": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}`", "title": "Engine" } }, "title": "VertexAISearch", "type": "object" }, "VertexRagStore": { "additionalProperties": false, "description": "Retrieve from Vertex RAG Store for grounding.", "properties": { "ragCorpora": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. Deprecated. Please use rag_resources instead.", "title": "Ragcorpora" }, "ragResources": { "anyOf": [ { "items": { "$ref": "#/$defs/VertexRagStoreRagResource" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support.", "title": "Ragresources" }, "similarityTopK": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional. Number of top k results to return from the selected corpora.", "title": "Similaritytopk" }, "vectorDistanceThreshold": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Optional. Only return results with vector distance smaller than the threshold.", "title": "Vectordistancethreshold" } }, "title": "VertexRagStore", "type": "object" }, "VertexRagStoreRagResource": { "additionalProperties": false, "description": "The definition of the Rag resource.", "properties": { "ragCorpus": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`", "title": "Ragcorpus" }, "ragFileIds": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.", "title": "Ragfileids" } }, "title": "VertexRagStoreRagResource", "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" }, "VoiceConfig": { "additionalProperties": false, "description": "The configuration for the voice to use.", "properties": { "prebuiltVoiceConfig": { "anyOf": [ { "$ref": "#/$defs/PrebuiltVoiceConfig" }, { "type": "null" } ], "default": null, "description": "The configuration for the speaker to use.\n " } }, "title": "VoiceConfig", "type": "object" } }, "additionalProperties": false, "required": [ "name" ] }
- Fields:
after_model_callback (Optional[AfterModelCallback])
after_tool_callback (Optional[AfterToolCallback])
before_model_callback (Optional[BeforeModelCallback])
before_tool_callback (Optional[BeforeToolCallback])
code_executor (Optional[BaseCodeExecutor])
disallow_transfer_to_parent (bool)
disallow_transfer_to_peers (bool)
examples (Optional[ExamplesUnion])
generate_content_config (Optional[types.GenerateContentConfig])
global_instruction (Union[str, InstructionProvider])
include_contents (Literal['default', 'none'])
input_schema (Optional[type[BaseModel]])
instruction (Union[str, InstructionProvider])
model (Union[str, BaseLlm])
output_key (Optional[str])
output_schema (Optional[type[BaseModel]])
planner (Optional[BasePlanner])
tools (list[ToolUnion])
- Validators:
__model_validator_after
»all fields
__validate_generate_content_config
»generate_content_config
- field after_model_callback: Optional[AfterModelCallback] = None¶
Called after calling LLM.
- Parameters:
callback_context – CallbackContext,
llm_response – LlmResponse, the actual model response.
- Returns:
The content to return to the user. When present, the actual model response will be ignored and the provided content will be returned to user.
- Validated by:
__model_validator_after
- field after_tool_callback: Optional[AfterToolCallback] = None¶
Called after the tool is called.
- Parameters:
tool – The tool to be called.
args – The arguments to the tool.
tool_context – ToolContext,
tool_response – The response from the tool.
- Returns:
When present, the returned dict will be used as tool result.
- Validated by:
__model_validator_after
- field before_model_callback: Optional[BeforeModelCallback] = None¶
Called before calling the LLM. :param callback_context: CallbackContext, :param llm_request: LlmRequest, The raw model request. Callback can mutate the :param request.:
- Returns:
The content to return to the user. When present, the model call will be skipped and the provided content will be returned to user.
- Validated by:
__model_validator_after
- field before_tool_callback: Optional[BeforeToolCallback] = None¶
Called before the tool is called.
- Parameters:
tool – The tool to be called.
args – The arguments to the tool.
tool_context – ToolContext,
- Returns:
The tool response. When present, the returned tool response will be used and the framework will skip calling the actual tool.
- Validated by:
__model_validator_after
- field code_executor: Optional[BaseCodeExecutor] = None¶
Allow agent to execute code blocks from model responses using the provided CodeExecutor.
Check out available code executions in google.adk.code_executor package.
NOTE: to use model’s built-in code executor, don’t set this field, add google.adk.tools.built_in_code_execution to tools instead.
- Validated by:
__model_validator_after
- field disallow_transfer_to_parent: bool = False¶
Disallows LLM-controlled transferring to the parent agent.
- Validated by:
__model_validator_after
- field disallow_transfer_to_peers: bool = False¶
Disallows LLM-controlled transferring to the peer agents.
- Validated by:
__model_validator_after
- field examples: Optional[ExamplesUnion] = None¶
- Validated by:
__model_validator_after
- field generate_content_config: Optional[types.GenerateContentConfig] = None¶
The additional content generation configurations.
NOTE: not all fields are usable, e.g. tools must be configured via tools, thinking_config must be configured via planner in LlmAgent.
For example: use this config to adjust model temperature, configure safety settings, etc.
- Validated by:
__model_validator_after
__validate_generate_content_config
- field global_instruction: Union[str, InstructionProvider] = ''¶
Instructions for all the agents in the entire agent tree.
global_instruction ONLY takes effect in root agent.
For example: use global_instruction to make all agents have a stable identity or personality.
- Validated by:
__model_validator_after
- field include_contents: Literal['default', 'none'] = 'default'¶
Whether to include contents in the model request.
When set to ‘none’, the model request will not include any contents, such as user messages, tool results, etc.
- Validated by:
__model_validator_after
- field input_schema: Optional[type[BaseModel]] = None¶
The input schema when agent is used as a tool.
- Validated by:
__model_validator_after
- field instruction: Union[str, InstructionProvider] = ''¶
Instructions for the LLM model, guiding the agent’s behavior.
- Validated by:
__model_validator_after
- field model: Union[str, BaseLlm] = ''¶
The model to use for the agent.
When not set, the agent will inherit the model from its ancestor.
- Validated by:
__model_validator_after
- field output_key: Optional[str] = None¶
The key in session state to store the output of the agent.
Typically use cases: - Extracts agent reply for later use, such as in tools, callbacks, etc. - Connects agents to coordinate with each other.
- Validated by:
__model_validator_after
- field output_schema: Optional[type[BaseModel]] = None¶
The output schema when agent replies.
NOTE: when this is set, agent can ONLY reply and CANNOT use any tools, such as function tools, RAGs, agent transfer, etc.
- Validated by:
__model_validator_after
- field planner: Optional[BasePlanner] = None¶
Instructs the agent to make a plan and execute it step by step.
NOTE: to use model’s built-in thinking features, set the thinking_config field in google.adk.planners.built_in_planner.
- Validated by:
__model_validator_after
- field tools: list[ToolUnion] [Optional]¶
Tools available to this agent.
- Validated by:
__model_validator_after
- canonical_global_instruction(ctx)¶
The resolved self.instruction field to construct global instruction.
This method is only for use by Agent Development Kit.
- Return type:
str
- canonical_instruction(ctx)¶
The resolved self.instruction field to construct instruction for this agent.
This method is only for use by Agent Development Kit.
- Return type:
str
- pydantic model google.adk.agents.LoopAgent¶
Bases:
BaseAgent
A shell agent that run its sub-agents in a loop.
When sub-agent generates an event with escalate or max_iterations are reached, the loop agent will stop.
Show JSON schema
{ "title": "LoopAgent", "type": "object", "properties": { "name": { "title": "Name", "type": "string" }, "description": { "default": "", "title": "Description", "type": "string" }, "parent_agent": { "default": null, "title": "Parent Agent" }, "sub_agents": { "default": null, "title": "Sub Agents" }, "before_agent_callback": { "default": null, "title": "Before Agent Callback" }, "after_agent_callback": { "default": null, "title": "After Agent Callback" }, "max_iterations": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "title": "Max Iterations" } }, "additionalProperties": false, "required": [ "name" ] }
- Fields:
max_iterations (Optional[int])
- Validators:
- field max_iterations: Optional[int] = None¶
The maximum number of iterations to run the loop agent.
If not set, the loop agent will run indefinitely until a sub-agent escalates.
- pydantic model google.adk.agents.ParallelAgent¶
Bases:
BaseAgent
A shell agent that run its sub-agents in parallel in isolated manner.
This approach is beneficial for scenarios requiring multiple perspectives or attempts on a single task, such as:
Running different algorithms simultaneously.
Generating multiple responses for review by a subsequent evaluation agent.
Show JSON schema
{ "title": "ParallelAgent", "type": "object", "properties": { "name": { "title": "Name", "type": "string" }, "description": { "default": "", "title": "Description", "type": "string" }, "parent_agent": { "default": null, "title": "Parent Agent" }, "sub_agents": { "default": null, "title": "Sub Agents" }, "before_agent_callback": { "default": null, "title": "Before Agent Callback" }, "after_agent_callback": { "default": null, "title": "After Agent Callback" } }, "additionalProperties": false, "required": [ "name" ] }
- Fields:
- Validators:
- pydantic model google.adk.agents.SequentialAgent¶
Bases:
BaseAgent
A shell agent that run its sub-agents in sequence.
Show JSON schema
{ "title": "SequentialAgent", "type": "object", "properties": { "name": { "title": "Name", "type": "string" }, "description": { "default": "", "title": "Description", "type": "string" }, "parent_agent": { "default": null, "title": "Parent Agent" }, "sub_agents": { "default": null, "title": "Sub Agents" }, "before_agent_callback": { "default": null, "title": "Before Agent Callback" }, "after_agent_callback": { "default": null, "title": "After Agent Callback" } }, "additionalProperties": false, "required": [ "name" ] }
- Fields:
- Validators:
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).
Initializes the GcsArtifactService.
- Parameters:
bucket_name – The name of the bucket to use.
**kwargs – Keyword arguments to pass to the Google Cloud Storage client.
- 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": [ { "additionalProperties": true, "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": [ { "additionalProperties": true, "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
Abstract base class for all code executors.
The code executor allows the agent to execute code blocks from model responses and incorporate the execution results into the final response.
- optimize_data_file¶
If true, extract and process data files from the model request and attach them to the code executor. Supported data file MimeTypes are [text/csv]. Default to False.
- stateful¶
Whether the code executor is stateful. Default to False.
- error_retry_attempts¶
The number of attempts to retry on consecutive code execution errors. Default to 2.
- code_block_delimiters¶
The list of the enclosing delimiters to identify the code blocks.
- execution_result_delimiters¶
The delimiters to format the code execution result.
Show JSON schema
{ "title": "BaseCodeExecutor", "description": "Abstract base class for all code executors.\n\nThe code executor allows the agent to execute code blocks from model responses\nand incorporate the execution results into the final response.\n\nAttributes:\n optimize_data_file: If true, extract and process data files from the model\n request and attach them to the code executor. Supported data file\n MimeTypes are [text/csv]. Default to False.\n stateful: Whether the code executor is stateful. Default to False.\n error_retry_attempts: The number of attempts to retry on consecutive code\n execution errors. Default to 2.\n code_block_delimiters: The list of the enclosing delimiters to identify the\n code blocks.\n execution_result_delimiters: The delimiters to format the code execution\n result.", "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```')]¶ 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 code execution result.
- Return type:
CodeExecutionResult
- Parameters:
invocation_context – The invocation context of the code execution.
code_execution_input – The code execution input.
- Returns:
The code execution result.
- 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.
- Parameters:
input_files – The input files to add to the code executor context.
- add_processed_file_names(file_names)¶
Adds the processed file name to the session state.
- Parameters:
file_names – The processed file names to add 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)¶
Gets the error count from the session state.
- Return type:
int
- Parameters:
invocation_id – The invocation ID to get the error count for.
- Returns:
The error count for the given invocation ID.
- get_execution_id()¶
Gets the session ID for the code executor.
- Return type:
Optional
[str
]- Returns:
The session ID for the code executor context.
- get_input_files()¶
Gets the code executor input file names from the session state.
- Return type:
list
[File
]- Returns:
A list of input files in the code executor context.
- get_processed_file_names()¶
Gets the processed file names from the session state.
- Return type:
list
[str
]- Returns:
A list of processed file names in the code executor context.
- get_state_delta()¶
Gets the state delta to update in the persistent session state.
- Return type:
dict
[str
,Any
]- Returns:
The state delta to update in the persistent session state.
- increment_error_count(invocation_id)¶
Increments the error count from the session state.
- Parameters:
invocation_id – The invocation ID to increment the error count for.
- reset_error_count(invocation_id)¶
Resets the error count from the session state.
- Parameters:
invocation_id – The invocation ID to reset the error count for.
- set_execution_id(session_id)¶
Sets the session ID for the code executor.
- Parameters:
session_id – The session ID for the code executor.
- update_code_execution_result(invocation_id, code, result_stdout, result_stderr)¶
Updates the code execution result.
- Parameters:
invocation_id – The invocation ID to update the code execution result for.
code – The code to execute.
result_stdout – The standard output of the code execution.
result_stderr – The standard error of the code execution.
- pydantic model google.adk.code_executors.ContainerCodeExecutor¶
Bases:
BaseCodeExecutor
A code executor that uses a custom container to execute code.
- base_url¶
Optional. The base url of the user hosted Docker client.
- image¶
The tag of the predefined image or custom image to run on the container. Either docker_path or image must be set.
- docker_path¶
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.
Initializes the ContainerCodeExecutor.
- Parameters:
base_url – Optional. The base url of the user hosted Docker client.
image – The tag of the predefined image or custom image to run on the container. Either docker_path or image must be set.
docker_path – 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.
**data – The data to initialize the ContainerCodeExecutor.
Show JSON schema
{ "title": "ContainerCodeExecutor", "description": "A code executor that uses a custom container to execute code.\n\nAttributes:\n base_url: Optional. The base url of the user hosted Docker client.\n image: The tag of the predefined image or custom image to run on the\n container. Either docker_path or image must be set.\n docker_path: The path to the directory containing the Dockerfile. If set,\n build the image from the dockerfile path instead of using the predefined\n image. Either docker_path or image must be set.", "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 code and return the code execution result.
- Return type:
CodeExecutionResult
- Parameters:
invocation_context – The invocation context of the code execution.
code_execution_input – The code execution input.
- Returns:
The code execution result.
- 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 code executor that unsafely execute code in the current local context.
Initializes the UnsafeLocalCodeExecutor.
Show JSON schema
{ "title": "UnsafeLocalCodeExecutor", "description": "A code executor that unsafely execute code 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 code execution result.
- Return type:
CodeExecutionResult
- Parameters:
invocation_context – The invocation context of the code execution.
code_execution_input – The code execution input.
- Returns:
The code execution result.
- pydantic model google.adk.code_executors.VertexAiCodeExecutor¶
Bases:
BaseCodeExecutor
A code executor that uses Vertex Code Interpreter Extension to execute code.
- resource_name¶
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
Initializes the VertexAiCodeExecutor.
- Parameters:
resource_name – 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
**data – Additional keyword arguments to be passed to the base class.
Show JSON schema
{ "title": "VertexAiCodeExecutor", "description": "A code executor that uses Vertex Code Interpreter Extension to execute code.\n\nAttributes:\n resource_name: If set, load the existing resource name of the code\n interpreter extension instead of creating a new one. Format:\n projects/123/locations/us-central1/extensions/456", "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 code execution result.
- Return type:
CodeExecutionResult
- Parameters:
invocation_context – The invocation context of the code execution.
code_execution_input – The code execution input.
- Returns:
The code execution result.
- 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¶
- class google.adk.evaluation.AgentEvaluator¶
Bases:
object
An evaluator for Agents, mainly intented for helping with test cases.
- static evaluate(agent_module, eval_dataset_file_path_or_dir, num_runs=2, agent_name=None, initial_session_file=None)¶
Evaluates an Agent given eval data.
- Parameters:
agent_module – The path to python module that contains the definition of the agent. There is convention in place here, where the code is going to look for ‘root_agent’ in the loaded module.
eval_dataset – The eval data set. This can be either a string representing full path to the file containing eval dataset, or a directory that is recusively explored for all files that have a .test.json suffix.
num_runs – Number of times all entries in the eval dataset should be assessed.
agent_name – The name of the agent.
initial_session_file – File that contains initial session state that is needed by all the evals in the eval dataset.
- static find_config_for_test_file(test_file)¶
Find the test_config.json file in the same folder as the test file.
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": { "APIKey": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "apiKey" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "in": { "$ref": "#/$defs/APIKeyIn" }, "name": { "title": "Name", "type": "string" } }, "required": [ "in", "name" ], "title": "APIKey", "type": "object" }, "APIKeyIn": { "enum": [ "query", "header", "cookie" ], "title": "APIKeyIn", "type": "string" }, "AuthConfig": { "description": "The auth config sent by tool asking client to collect auth credentails and\n\nadk and client will help to fill in the response", "properties": { "auth_scheme": { "anyOf": [ { "$ref": "#/$defs/APIKey" }, { "$ref": "#/$defs/HTTPBase" }, { "$ref": "#/$defs/OAuth2" }, { "$ref": "#/$defs/OpenIdConnect" }, { "$ref": "#/$defs/HTTPBearer" }, { "$ref": "#/$defs/OpenIdConnectWithConfig" } ], "title": "Auth Scheme" }, "raw_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null }, "exchanged_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null } }, "required": [ "auth_scheme" ], "title": "AuthConfig", "type": "object" }, "AuthCredential": { "additionalProperties": true, "description": "Data class representing an authentication credential.\n\nTo exchange for the actual credential, please use\nCredentialExchanger.exchange_credential().\n\nExamples: API Key Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n api_key=\"1234\",\n)\n\nExample: HTTP Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"basic\",\n credentials=HttpCredentials(username=\"user\", password=\"password\"),\n ),\n)\n\nExample: OAuth2 Bearer Token in HTTP Header\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"bearer\",\n credentials=HttpCredentials(token=\"eyAkaknabna....\"),\n ),\n)\n\nExample: OAuth2 Auth with Authorization Code Flow\nAuthCredential(\n auth_type=AuthCredentialTypes.OAUTH2,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n ),\n)\n\nExample: OpenID Connect Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.OPEN_ID_CONNECT,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n redirect_uri=\"https://example.com\",\n scopes=[\"scope1\", \"scope2\"],\n ),\n)\n\nExample: Auth with resource reference\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n resource_ref=\"projects/1234/locations/us-central1/resources/resource1\",\n)", "properties": { "auth_type": { "$ref": "#/$defs/AuthCredentialTypes" }, "resource_ref": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Resource Ref" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Api Key" }, "http": { "anyOf": [ { "$ref": "#/$defs/HttpAuth" }, { "type": "null" } ], "default": null }, "service_account": { "anyOf": [ { "$ref": "#/$defs/ServiceAccount" }, { "type": "null" } ], "default": null }, "oauth2": { "anyOf": [ { "$ref": "#/$defs/OAuth2Auth" }, { "type": "null" } ], "default": null } }, "required": [ "auth_type" ], "title": "AuthCredential", "type": "object" }, "AuthCredentialTypes": { "description": "Represents the type of authentication credential.", "enum": [ "apiKey", "http", "oauth2", "openIdConnect", "serviceAccount" ], "title": "AuthCredentialTypes", "type": "string" }, "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": { "additionalProperties": true, "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": { "$ref": "#/$defs/AuthConfig" }, "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": [ { "additionalProperties": true, "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": [ { "additionalProperties": true, "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" }, "HTTPBase": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "title": "Scheme", "type": "string" } }, "required": [ "scheme" ], "title": "HTTPBase", "type": "object" }, "HTTPBearer": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "const": "bearer", "default": "bearer", "title": "Scheme", "type": "string" }, "bearerFormat": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Bearerformat" } }, "title": "HTTPBearer", "type": "object" }, "HttpAuth": { "additionalProperties": true, "description": "The credentials and metadata for HTTP authentication.", "properties": { "scheme": { "title": "Scheme", "type": "string" }, "credentials": { "$ref": "#/$defs/HttpCredentials" } }, "required": [ "scheme", "credentials" ], "title": "HttpAuth", "type": "object" }, "HttpCredentials": { "additionalProperties": true, "description": "Represents the secret token value for HTTP authentication, like user name, password, oauth token, etc.", "properties": { "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Username" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Password" }, "token": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "HttpCredentials", "type": "object" }, "Language": { "description": "Required. Programming language of the `code`.", "enum": [ "LANGUAGE_UNSPECIFIED", "PYTHON" ], "title": "Language", "type": "string" }, "OAuth2": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "oauth2" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "flows": { "$ref": "#/$defs/OAuthFlows" } }, "required": [ "flows" ], "title": "OAuth2", "type": "object" }, "OAuth2Auth": { "additionalProperties": true, "description": "Represents credential value and its metadata for a OAuth2 credential.", "properties": { "client_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Id" }, "client_secret": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Secret" }, "auth_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Uri" }, "state": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "State" }, "redirect_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Redirect Uri" }, "auth_response_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Response Uri" }, "auth_code": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Code" }, "token": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "OAuth2Auth", "type": "object" }, "OAuthFlowAuthorizationCode": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "authorizationUrl", "tokenUrl" ], "title": "OAuthFlowAuthorizationCode", "type": "object" }, "OAuthFlowClientCredentials": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowClientCredentials", "type": "object" }, "OAuthFlowImplicit": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" } }, "required": [ "authorizationUrl" ], "title": "OAuthFlowImplicit", "type": "object" }, "OAuthFlowPassword": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowPassword", "type": "object" }, "OAuthFlows": { "additionalProperties": true, "properties": { "implicit": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowImplicit" }, { "type": "null" } ], "default": null }, "password": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowPassword" }, { "type": "null" } ], "default": null }, "clientCredentials": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowClientCredentials" }, { "type": "null" } ], "default": null }, "authorizationCode": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowAuthorizationCode" }, { "type": "null" } ], "default": null } }, "title": "OAuthFlows", "type": "object" }, "OpenIdConnect": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "openIdConnectUrl": { "title": "Openidconnecturl", "type": "string" } }, "required": [ "openIdConnectUrl" ], "title": "OpenIdConnect", "type": "object" }, "OpenIdConnectWithConfig": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "authorization_endpoint": { "title": "Authorization Endpoint", "type": "string" }, "token_endpoint": { "title": "Token Endpoint", "type": "string" }, "userinfo_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Userinfo Endpoint" }, "revocation_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Revocation Endpoint" }, "token_endpoint_auth_methods_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Token Endpoint Auth Methods Supported" }, "grant_types_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Grant Types Supported" }, "scopes": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Scopes" } }, "required": [ "authorization_endpoint", "token_endpoint" ], "title": "OpenIdConnectWithConfig", "type": "object" }, "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" }, "SecuritySchemeType": { "enum": [ "apiKey", "http", "oauth2", "openIdConnect" ], "title": "SecuritySchemeType", "type": "string" }, "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" }, "ServiceAccount": { "additionalProperties": true, "description": "Represents Google Service Account configuration.", "properties": { "service_account_credential": { "anyOf": [ { "$ref": "#/$defs/ServiceAccountCredential" }, { "type": "null" } ], "default": null }, "scopes": { "items": { "type": "string" }, "title": "Scopes", "type": "array" }, "use_default_credential": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": false, "title": "Use Default Credential" } }, "required": [ "scopes" ], "title": "ServiceAccount", "type": "object" }, "ServiceAccountCredential": { "additionalProperties": true, "description": "Represents Google Service Account configuration.\n\nAttributes:\n type: The type should be \"service_account\".\n project_id: The project ID.\n private_key_id: The ID of the private key.\n private_key: The private key.\n client_email: The client email.\n client_id: The client ID.\n auth_uri: The authorization URI.\n token_uri: The token URI.\n auth_provider_x509_cert_url: URL for auth provider's X.509 cert.\n client_x509_cert_url: URL for the client's X.509 cert.\n universe_domain: The universe domain.\n\nExample:\n\n config = ServiceAccountCredential(\n type_=\"service_account\",\n project_id=\"your_project_id\",\n private_key_id=\"your_private_key_id\",\n private_key=\"-----BEGIN PRIVATE KEY-----...\",\n client_email=\"...@....iam.gserviceaccount.com\",\n client_id=\"your_client_id\",\n auth_uri=\"https://accounts.google.com/o/oauth2/auth\",\n token_uri=\"https://oauth2.googleapis.com/token\",\n auth_provider_x509_cert_url=\"https://www.googleapis.com/oauth2/v1/certs\",\n client_x509_cert_url=\"https://www.googleapis.com/robot/v1/metadata/x509/...\",\n universe_domain=\"googleapis.com\"\n )\n\n\n config = ServiceAccountConfig.model_construct(**{\n ...service account config dict\n })", "properties": { "type": { "default": "", "title": "Type", "type": "string" }, "project_id": { "title": "Project Id", "type": "string" }, "private_key_id": { "title": "Private Key Id", "type": "string" }, "private_key": { "title": "Private Key", "type": "string" }, "client_email": { "title": "Client Email", "type": "string" }, "client_id": { "title": "Client Id", "type": "string" }, "auth_uri": { "title": "Auth Uri", "type": "string" }, "token_uri": { "title": "Token Uri", "type": "string" }, "auth_provider_x509_cert_url": { "title": "Auth Provider X509 Cert Url", "type": "string" }, "client_x509_cert_url": { "title": "Client X509 Cert Url", "type": "string" }, "universe_domain": { "title": "Universe Domain", "type": "string" } }, "required": [ "project_id", "private_key_id", "private_key", "client_email", "client_id", "auth_uri", "token_uri", "auth_provider_x509_cert_url", "client_x509_cert_url", "universe_domain" ], "title": "ServiceAccountCredential", "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.
- 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": { "additionalProperties": true, "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": { "$ref": "#/$defs/AuthConfig" }, "title": "Requested Auth Configs", "type": "object" } }, "$defs": { "APIKey": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "apiKey" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "in": { "$ref": "#/$defs/APIKeyIn" }, "name": { "title": "Name", "type": "string" } }, "required": [ "in", "name" ], "title": "APIKey", "type": "object" }, "APIKeyIn": { "enum": [ "query", "header", "cookie" ], "title": "APIKeyIn", "type": "string" }, "AuthConfig": { "description": "The auth config sent by tool asking client to collect auth credentails and\n\nadk and client will help to fill in the response", "properties": { "auth_scheme": { "anyOf": [ { "$ref": "#/$defs/APIKey" }, { "$ref": "#/$defs/HTTPBase" }, { "$ref": "#/$defs/OAuth2" }, { "$ref": "#/$defs/OpenIdConnect" }, { "$ref": "#/$defs/HTTPBearer" }, { "$ref": "#/$defs/OpenIdConnectWithConfig" } ], "title": "Auth Scheme" }, "raw_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null }, "exchanged_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null } }, "required": [ "auth_scheme" ], "title": "AuthConfig", "type": "object" }, "AuthCredential": { "additionalProperties": true, "description": "Data class representing an authentication credential.\n\nTo exchange for the actual credential, please use\nCredentialExchanger.exchange_credential().\n\nExamples: API Key Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n api_key=\"1234\",\n)\n\nExample: HTTP Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"basic\",\n credentials=HttpCredentials(username=\"user\", password=\"password\"),\n ),\n)\n\nExample: OAuth2 Bearer Token in HTTP Header\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"bearer\",\n credentials=HttpCredentials(token=\"eyAkaknabna....\"),\n ),\n)\n\nExample: OAuth2 Auth with Authorization Code Flow\nAuthCredential(\n auth_type=AuthCredentialTypes.OAUTH2,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n ),\n)\n\nExample: OpenID Connect Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.OPEN_ID_CONNECT,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n redirect_uri=\"https://example.com\",\n scopes=[\"scope1\", \"scope2\"],\n ),\n)\n\nExample: Auth with resource reference\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n resource_ref=\"projects/1234/locations/us-central1/resources/resource1\",\n)", "properties": { "auth_type": { "$ref": "#/$defs/AuthCredentialTypes" }, "resource_ref": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Resource Ref" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Api Key" }, "http": { "anyOf": [ { "$ref": "#/$defs/HttpAuth" }, { "type": "null" } ], "default": null }, "service_account": { "anyOf": [ { "$ref": "#/$defs/ServiceAccount" }, { "type": "null" } ], "default": null }, "oauth2": { "anyOf": [ { "$ref": "#/$defs/OAuth2Auth" }, { "type": "null" } ], "default": null } }, "required": [ "auth_type" ], "title": "AuthCredential", "type": "object" }, "AuthCredentialTypes": { "description": "Represents the type of authentication credential.", "enum": [ "apiKey", "http", "oauth2", "openIdConnect", "serviceAccount" ], "title": "AuthCredentialTypes", "type": "string" }, "HTTPBase": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "title": "Scheme", "type": "string" } }, "required": [ "scheme" ], "title": "HTTPBase", "type": "object" }, "HTTPBearer": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "const": "bearer", "default": "bearer", "title": "Scheme", "type": "string" }, "bearerFormat": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Bearerformat" } }, "title": "HTTPBearer", "type": "object" }, "HttpAuth": { "additionalProperties": true, "description": "The credentials and metadata for HTTP authentication.", "properties": { "scheme": { "title": "Scheme", "type": "string" }, "credentials": { "$ref": "#/$defs/HttpCredentials" } }, "required": [ "scheme", "credentials" ], "title": "HttpAuth", "type": "object" }, "HttpCredentials": { "additionalProperties": true, "description": "Represents the secret token value for HTTP authentication, like user name, password, oauth token, etc.", "properties": { "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Username" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Password" }, "token": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "HttpCredentials", "type": "object" }, "OAuth2": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "oauth2" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "flows": { "$ref": "#/$defs/OAuthFlows" } }, "required": [ "flows" ], "title": "OAuth2", "type": "object" }, "OAuth2Auth": { "additionalProperties": true, "description": "Represents credential value and its metadata for a OAuth2 credential.", "properties": { "client_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Id" }, "client_secret": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Secret" }, "auth_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Uri" }, "state": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "State" }, "redirect_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Redirect Uri" }, "auth_response_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Response Uri" }, "auth_code": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Code" }, "token": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "OAuth2Auth", "type": "object" }, "OAuthFlowAuthorizationCode": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "authorizationUrl", "tokenUrl" ], "title": "OAuthFlowAuthorizationCode", "type": "object" }, "OAuthFlowClientCredentials": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowClientCredentials", "type": "object" }, "OAuthFlowImplicit": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" } }, "required": [ "authorizationUrl" ], "title": "OAuthFlowImplicit", "type": "object" }, "OAuthFlowPassword": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowPassword", "type": "object" }, "OAuthFlows": { "additionalProperties": true, "properties": { "implicit": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowImplicit" }, { "type": "null" } ], "default": null }, "password": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowPassword" }, { "type": "null" } ], "default": null }, "clientCredentials": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowClientCredentials" }, { "type": "null" } ], "default": null }, "authorizationCode": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowAuthorizationCode" }, { "type": "null" } ], "default": null } }, "title": "OAuthFlows", "type": "object" }, "OpenIdConnect": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "openIdConnectUrl": { "title": "Openidconnecturl", "type": "string" } }, "required": [ "openIdConnectUrl" ], "title": "OpenIdConnect", "type": "object" }, "OpenIdConnectWithConfig": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "authorization_endpoint": { "title": "Authorization Endpoint", "type": "string" }, "token_endpoint": { "title": "Token Endpoint", "type": "string" }, "userinfo_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Userinfo Endpoint" }, "revocation_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Revocation Endpoint" }, "token_endpoint_auth_methods_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Token Endpoint Auth Methods Supported" }, "grant_types_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Grant Types Supported" }, "scopes": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Scopes" } }, "required": [ "authorization_endpoint", "token_endpoint" ], "title": "OpenIdConnectWithConfig", "type": "object" }, "SecuritySchemeType": { "enum": [ "apiKey", "http", "oauth2", "openIdConnect" ], "title": "SecuritySchemeType", "type": "string" }, "ServiceAccount": { "additionalProperties": true, "description": "Represents Google Service Account configuration.", "properties": { "service_account_credential": { "anyOf": [ { "$ref": "#/$defs/ServiceAccountCredential" }, { "type": "null" } ], "default": null }, "scopes": { "items": { "type": "string" }, "title": "Scopes", "type": "array" }, "use_default_credential": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": false, "title": "Use Default Credential" } }, "required": [ "scopes" ], "title": "ServiceAccount", "type": "object" }, "ServiceAccountCredential": { "additionalProperties": true, "description": "Represents Google Service Account configuration.\n\nAttributes:\n type: The type should be \"service_account\".\n project_id: The project ID.\n private_key_id: The ID of the private key.\n private_key: The private key.\n client_email: The client email.\n client_id: The client ID.\n auth_uri: The authorization URI.\n token_uri: The token URI.\n auth_provider_x509_cert_url: URL for auth provider's X.509 cert.\n client_x509_cert_url: URL for the client's X.509 cert.\n universe_domain: The universe domain.\n\nExample:\n\n config = ServiceAccountCredential(\n type_=\"service_account\",\n project_id=\"your_project_id\",\n private_key_id=\"your_private_key_id\",\n private_key=\"-----BEGIN PRIVATE KEY-----...\",\n client_email=\"...@....iam.gserviceaccount.com\",\n client_id=\"your_client_id\",\n auth_uri=\"https://accounts.google.com/o/oauth2/auth\",\n token_uri=\"https://oauth2.googleapis.com/token\",\n auth_provider_x509_cert_url=\"https://www.googleapis.com/oauth2/v1/certs\",\n client_x509_cert_url=\"https://www.googleapis.com/robot/v1/metadata/x509/...\",\n universe_domain=\"googleapis.com\"\n )\n\n\n config = ServiceAccountConfig.model_construct(**{\n ...service account config dict\n })", "properties": { "type": { "default": "", "title": "Type", "type": "string" }, "project_id": { "title": "Project Id", "type": "string" }, "private_key_id": { "title": "Private Key Id", "type": "string" }, "private_key": { "title": "Private Key", "type": "string" }, "client_email": { "title": "Client Email", "type": "string" }, "client_id": { "title": "Client Id", "type": "string" }, "auth_uri": { "title": "Auth Uri", "type": "string" }, "token_uri": { "title": "Token Uri", "type": "string" }, "auth_provider_x509_cert_url": { "title": "Auth Provider X509 Cert Url", "type": "string" }, "client_x509_cert_url": { "title": "Client X509 Cert Url", "type": "string" }, "universe_domain": { "title": "Universe Domain", "type": "string" } }, "required": [ "project_id", "private_key_id", "private_key", "client_email", "client_id", "auth_uri", "token_uri", "auth_provider_x509_cert_url", "client_x509_cert_url", "universe_domain" ], "title": "ServiceAccountCredential", "type": "object" } }, "additionalProperties": false }
- Fields:
artifact_delta (dict[str, int])
escalate (bool | None)
requested_auth_configs (dict[str, google.adk.auth.auth_tool.AuthConfig])
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, AuthConfig] [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.
- 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": [ { "additionalProperties": true, "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": [ { "additionalProperties": true, "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}
.
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
- 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¶
Defines the interface to support a model.
- pydantic model google.adk.models.BaseLlm¶
Bases:
BaseModel
The BaseLLM class.
- model¶
The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.
- model_config¶
The model config
Show JSON schema
{ "title": "BaseLlm", "description": "The BaseLLM class.\n\nAttributes:\n model: The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.\n model_config: The model config", "type": "object", "properties": { "model": { "title": "Model", "type": "string" } }, "required": [ "model" ] }
- Fields:
model (str)
- field model: str [Required]¶
The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.
- connect(llm_request)¶
Creates a live connection to the LLM.
- Return type:
BaseLlmConnection
- Parameters:
llm_request – LlmRequest, the request to send to the LLM.
- Returns:
BaseLlmConnection, the connection to the LLM.
- abstract async generate_content_async(llm_request, stream=False)¶
Generates one content from the given contents and tools.
- Return type:
AsyncGenerator
[LlmResponse
,None
]- Parameters:
llm_request – LlmRequest, the request to send to the LLM.
stream – bool = False, whether to do streaming call.
- Yields:
a generator of types.Content.
For non-streaming call, it will only yield one Content.
For streaming call, it may yield more than one content, but all yielded contents should be treated as one content by merging the parts list.
- classmethod supported_models()¶
Returns a list of supported models in regex for LlmRegistry.
- Return type:
list
[str
]
- pydantic model google.adk.models.Gemini¶
Bases:
BaseLlm
Integration for Gemini models.
- model¶
The name of the Gemini model.
Show JSON schema
{ "title": "Gemini", "description": "Integration for Gemini models.\n\nAttributes:\n model: The name of the Gemini model.", "type": "object", "properties": { "model": { "default": "gemini-1.5-flash", "title": "Model", "type": "string" } } }
- Fields:
model (str)
- field model: str = 'gemini-1.5-flash'¶
The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.
- connect(llm_request)¶
Connects to the Gemini model and returns an llm connection.
- Return type:
BaseLlmConnection
- Parameters:
llm_request – LlmRequest, the request to send to the Gemini model.
- Yields:
BaseLlmConnection, the connection to the Gemini model.
- async generate_content_async(llm_request, stream=False)¶
Sends a request to the Gemini model.
- Return type:
AsyncGenerator
[LlmResponse
,None
]- Parameters:
llm_request – LlmRequest, the request to send to the Gemini model.
stream – bool = False, whether to do streaming call.
- Yields:
LlmResponse – The model response.
- static supported_models()¶
Provides the list of supported models.
- Return type:
list
[str
]- Returns:
A list of supported models.
- property api_client: Client¶
Provides the api client.
- Returns:
The api client.
- class google.adk.models.LLMRegistry¶
Bases:
object
Registry for LLMs.
- static new_llm(model)¶
Creates a new LLM instance.
- Return type:
- Parameters:
model – The model name.
- Returns:
The LLM instance.
- static register(llm_cls)¶
Registers a new LLM class.
- Parameters:
llm_cls – The class that implements the model.
google.adk.planners module¶
- class google.adk.planners.BasePlanner¶
Bases:
ABC
Abstract base class for all planners.
The planner allows the agent to generate plans for the queries to guide its action.
- abstract build_planning_instruction(readonly_context, llm_request)¶
Builds the system instruction to be appended to the LLM request for planning.
- Return type:
Optional
[str
]- Parameters:
readonly_context – The readonly context of the invocation.
llm_request – The LLM request. Readonly.
- Returns:
The planning system instruction, or None if no instruction is needed.
- abstract process_planning_response(callback_context, response_parts)¶
Processes the LLM response for planning.
- Return type:
Optional
[List
[Part
]]- Parameters:
callback_context – The callback context of the invocation.
response_parts – The LLM response parts. Readonly.
- Returns:
The processed response parts, or None if no processing is needed.
- class google.adk.planners.BuiltInPlanner(*, thinking_config)¶
Bases:
BasePlanner
The built-in planner that uses model’s built-in thinking features.
- thinking_config¶
Config for model built-in thinking features. An error will be returned if this field is set for models that don’t support thinking.
Initializes the built-in planner.
- Parameters:
thinking_config – Config for model built-in thinking features. An error will be returned if this field is set for models that don’t support thinking.
- apply_thinking_config(llm_request)¶
Applies the thinking config to the LLM request.
- Return type:
None
- Parameters:
llm_request – The LLM request to apply the thinking config to.
- build_planning_instruction(readonly_context, llm_request)¶
Builds the system instruction to be appended to the LLM request for planning.
- Return type:
Optional
[str
]- Parameters:
readonly_context – The readonly context of the invocation.
llm_request – The LLM request. Readonly.
- Returns:
The planning system instruction, or None if no instruction is needed.
- process_planning_response(callback_context, response_parts)¶
Processes the LLM response for planning.
- Return type:
Optional
[List
[Part
]]- Parameters:
callback_context – The callback context of the invocation.
response_parts – The LLM response parts. Readonly.
- Returns:
The processed response parts, or None if no processing is needed.
-
thinking_config:
ThinkingConfig
¶ Config for model built-in thinking features. An error will be returned if this field is set for models that don’t support thinking.
- class google.adk.planners.PlanReActPlanner¶
Bases:
BasePlanner
Plan-Re-Act planner that constraints the LLM response to generate a plan before any action/observation.
Note: this planner does not require the model to support buil-in thinking features or setting the thinking config.
- build_planning_instruction(readonly_context, llm_request)¶
Builds the system instruction to be appended to the LLM request for planning.
- Return type:
str
- Parameters:
readonly_context – The readonly context of the invocation.
llm_request – The LLM request. Readonly.
- Returns:
The planning system instruction, or None if no instruction is needed.
- process_planning_response(callback_context, response_parts)¶
Processes the LLM response for planning.
- Return type:
Optional
[List
[Part
]]- Parameters:
callback_context – The callback context of the invocation.
response_parts – The LLM response parts. Readonly.
- Returns:
The processed response parts, or None if no processing is needed.
google.adk.runners module¶
- class google.adk.runners.InMemoryRunner(agent, *, app_name='InMemoryRunner')¶
Bases:
Runner
An in-memory Runner for testing and development.
This runner uses in-memory implementations for artifact, session, and memory services, providing a lightweight and self-contained environment for agent execution.
- agent¶
The root agent to run.
- app_name¶
The application name of the runner. Defaults to ‘InMemoryRunner’.
Initializes the InMemoryRunner.
- Parameters:
agent – The root agent to run.
app_name – The application name of the runner. Defaults to ‘InMemoryRunner’.
- class google.adk.runners.Runner(*, app_name, agent, artifact_service=None, session_service, memory_service=None)¶
Bases:
object
The Runner class is used to run agents.
It manages the execution of an agent within a session, handling message processing, event generation, and interaction with various services like artifact storage, session management, and memory.
- app_name¶
The application name of the runner.
- agent¶
The root agent to run.
- artifact_service¶
The artifact service for the runner.
- session_service¶
The session service for the runner.
- memory_service¶
The memory service for the runner.
Initializes the Runner.
- Parameters:
app_name – The application name of the runner.
agent – The root agent to run.
artifact_service – The artifact service for the runner.
session_service – The session service for the runner.
memory_service – The memory service for the runner.
-
app_name:
str
¶ The app name of the runner.
-
artifact_service:
Optional
[BaseArtifactService
] = None¶ The artifact service for the runner.
- close_session(session)¶
Closes a session and adds it to the memory service (experimental feature).
- Parameters:
session – The session to close.
-
memory_service:
Optional
[BaseMemoryService
] = None¶ The memory service for the runner.
- run(*, user_id, session_id, new_message, run_config=RunConfig(speech_config=None, response_modalities=None, save_input_blobs_as_artifacts=False, support_cfc=False, streaming_mode=<StreamingMode.NONE: None>, output_audio_transcription=None, max_llm_calls=500))¶
Runs the agent.
NOTE: This sync interface is only for local testing and convenience purpose. Consider to use run_async for production usage.
- Return type:
Generator
[Event
,None
,None
]- Parameters:
user_id – The user ID of the session.
session_id – The session ID of the session.
new_message – A new message to append to the session.
run_config – The run config for the agent.
- Yields:
The events generated by the agent.
- async run_async(*, user_id, session_id, new_message, run_config=RunConfig(speech_config=None, response_modalities=None, save_input_blobs_as_artifacts=False, support_cfc=False, streaming_mode=<StreamingMode.NONE: None>, output_audio_transcription=None, max_llm_calls=500))¶
Main entry method to run the agent in this runner.
- Return type:
AsyncGenerator
[Event
,None
]- Parameters:
user_id – The user ID of the session.
session_id – The session ID of the session.
new_message – A new message to append to the session.
run_config – The run config for the agent.
- Yields:
The events generated by the agent.
- async run_live(*, session, live_request_queue, run_config=RunConfig(speech_config=None, response_modalities=None, save_input_blobs_as_artifacts=False, support_cfc=False, streaming_mode=<StreamingMode.NONE: None>, output_audio_transcription=None, max_llm_calls=500))¶
Runs the agent in live mode (experimental feature).
- Return type:
AsyncGenerator
[Event
,None
]- Parameters:
session – The session to use.
live_request_queue – The queue for live requests.
run_config – The run config for the agent.
- Yields:
The events generated by the agent.
-
session_service:
BaseSessionService
¶ The session service for the runner.
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.
- close_session(*, session)¶
Closes a session.
- abstract create_session(*, app_name, user_id, state=None, session_id=None)¶
Creates a new session.
- Return type:
- 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.
- create_session(*, app_name, user_id, state=None, session_id=None)¶
Creates a new session.
- Return type:
- 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.
- create_session(*, app_name, user_id, state=None, session_id=None)¶
Creates a new session.
- Return type:
- 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
- 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
- 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": { "additionalProperties": true, "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": { "APIKey": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "apiKey" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "in": { "$ref": "#/$defs/APIKeyIn" }, "name": { "title": "Name", "type": "string" } }, "required": [ "in", "name" ], "title": "APIKey", "type": "object" }, "APIKeyIn": { "enum": [ "query", "header", "cookie" ], "title": "APIKeyIn", "type": "string" }, "AuthConfig": { "description": "The auth config sent by tool asking client to collect auth credentails and\n\nadk and client will help to fill in the response", "properties": { "auth_scheme": { "anyOf": [ { "$ref": "#/$defs/APIKey" }, { "$ref": "#/$defs/HTTPBase" }, { "$ref": "#/$defs/OAuth2" }, { "$ref": "#/$defs/OpenIdConnect" }, { "$ref": "#/$defs/HTTPBearer" }, { "$ref": "#/$defs/OpenIdConnectWithConfig" } ], "title": "Auth Scheme" }, "raw_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null }, "exchanged_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null } }, "required": [ "auth_scheme" ], "title": "AuthConfig", "type": "object" }, "AuthCredential": { "additionalProperties": true, "description": "Data class representing an authentication credential.\n\nTo exchange for the actual credential, please use\nCredentialExchanger.exchange_credential().\n\nExamples: API Key Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n api_key=\"1234\",\n)\n\nExample: HTTP Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"basic\",\n credentials=HttpCredentials(username=\"user\", password=\"password\"),\n ),\n)\n\nExample: OAuth2 Bearer Token in HTTP Header\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"bearer\",\n credentials=HttpCredentials(token=\"eyAkaknabna....\"),\n ),\n)\n\nExample: OAuth2 Auth with Authorization Code Flow\nAuthCredential(\n auth_type=AuthCredentialTypes.OAUTH2,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n ),\n)\n\nExample: OpenID Connect Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.OPEN_ID_CONNECT,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n redirect_uri=\"https://example.com\",\n scopes=[\"scope1\", \"scope2\"],\n ),\n)\n\nExample: Auth with resource reference\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n resource_ref=\"projects/1234/locations/us-central1/resources/resource1\",\n)", "properties": { "auth_type": { "$ref": "#/$defs/AuthCredentialTypes" }, "resource_ref": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Resource Ref" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Api Key" }, "http": { "anyOf": [ { "$ref": "#/$defs/HttpAuth" }, { "type": "null" } ], "default": null }, "service_account": { "anyOf": [ { "$ref": "#/$defs/ServiceAccount" }, { "type": "null" } ], "default": null }, "oauth2": { "anyOf": [ { "$ref": "#/$defs/OAuth2Auth" }, { "type": "null" } ], "default": null } }, "required": [ "auth_type" ], "title": "AuthCredential", "type": "object" }, "AuthCredentialTypes": { "description": "Represents the type of authentication credential.", "enum": [ "apiKey", "http", "oauth2", "openIdConnect", "serviceAccount" ], "title": "AuthCredentialTypes", "type": "string" }, "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": { "additionalProperties": true, "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": { "$ref": "#/$defs/AuthConfig" }, "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": [ { "additionalProperties": true, "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": [ { "additionalProperties": true, "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" }, "HTTPBase": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "title": "Scheme", "type": "string" } }, "required": [ "scheme" ], "title": "HTTPBase", "type": "object" }, "HTTPBearer": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "const": "bearer", "default": "bearer", "title": "Scheme", "type": "string" }, "bearerFormat": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Bearerformat" } }, "title": "HTTPBearer", "type": "object" }, "HttpAuth": { "additionalProperties": true, "description": "The credentials and metadata for HTTP authentication.", "properties": { "scheme": { "title": "Scheme", "type": "string" }, "credentials": { "$ref": "#/$defs/HttpCredentials" } }, "required": [ "scheme", "credentials" ], "title": "HttpAuth", "type": "object" }, "HttpCredentials": { "additionalProperties": true, "description": "Represents the secret token value for HTTP authentication, like user name, password, oauth token, etc.", "properties": { "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Username" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Password" }, "token": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "HttpCredentials", "type": "object" }, "Language": { "description": "Required. Programming language of the `code`.", "enum": [ "LANGUAGE_UNSPECIFIED", "PYTHON" ], "title": "Language", "type": "string" }, "OAuth2": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "oauth2" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "flows": { "$ref": "#/$defs/OAuthFlows" } }, "required": [ "flows" ], "title": "OAuth2", "type": "object" }, "OAuth2Auth": { "additionalProperties": true, "description": "Represents credential value and its metadata for a OAuth2 credential.", "properties": { "client_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Id" }, "client_secret": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Secret" }, "auth_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Uri" }, "state": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "State" }, "redirect_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Redirect Uri" }, "auth_response_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Response Uri" }, "auth_code": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Code" }, "token": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "OAuth2Auth", "type": "object" }, "OAuthFlowAuthorizationCode": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "authorizationUrl", "tokenUrl" ], "title": "OAuthFlowAuthorizationCode", "type": "object" }, "OAuthFlowClientCredentials": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowClientCredentials", "type": "object" }, "OAuthFlowImplicit": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" } }, "required": [ "authorizationUrl" ], "title": "OAuthFlowImplicit", "type": "object" }, "OAuthFlowPassword": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowPassword", "type": "object" }, "OAuthFlows": { "additionalProperties": true, "properties": { "implicit": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowImplicit" }, { "type": "null" } ], "default": null }, "password": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowPassword" }, { "type": "null" } ], "default": null }, "clientCredentials": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowClientCredentials" }, { "type": "null" } ], "default": null }, "authorizationCode": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowAuthorizationCode" }, { "type": "null" } ], "default": null } }, "title": "OAuthFlows", "type": "object" }, "OpenIdConnect": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "openIdConnectUrl": { "title": "Openidconnecturl", "type": "string" } }, "required": [ "openIdConnectUrl" ], "title": "OpenIdConnect", "type": "object" }, "OpenIdConnectWithConfig": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "authorization_endpoint": { "title": "Authorization Endpoint", "type": "string" }, "token_endpoint": { "title": "Token Endpoint", "type": "string" }, "userinfo_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Userinfo Endpoint" }, "revocation_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Revocation Endpoint" }, "token_endpoint_auth_methods_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Token Endpoint Auth Methods Supported" }, "grant_types_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Grant Types Supported" }, "scopes": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Scopes" } }, "required": [ "authorization_endpoint", "token_endpoint" ], "title": "OpenIdConnectWithConfig", "type": "object" }, "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" }, "SecuritySchemeType": { "enum": [ "apiKey", "http", "oauth2", "openIdConnect" ], "title": "SecuritySchemeType", "type": "string" }, "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" }, "ServiceAccount": { "additionalProperties": true, "description": "Represents Google Service Account configuration.", "properties": { "service_account_credential": { "anyOf": [ { "$ref": "#/$defs/ServiceAccountCredential" }, { "type": "null" } ], "default": null }, "scopes": { "items": { "type": "string" }, "title": "Scopes", "type": "array" }, "use_default_credential": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": false, "title": "Use Default Credential" } }, "required": [ "scopes" ], "title": "ServiceAccount", "type": "object" }, "ServiceAccountCredential": { "additionalProperties": true, "description": "Represents Google Service Account configuration.\n\nAttributes:\n type: The type should be \"service_account\".\n project_id: The project ID.\n private_key_id: The ID of the private key.\n private_key: The private key.\n client_email: The client email.\n client_id: The client ID.\n auth_uri: The authorization URI.\n token_uri: The token URI.\n auth_provider_x509_cert_url: URL for auth provider's X.509 cert.\n client_x509_cert_url: URL for the client's X.509 cert.\n universe_domain: The universe domain.\n\nExample:\n\n config = ServiceAccountCredential(\n type_=\"service_account\",\n project_id=\"your_project_id\",\n private_key_id=\"your_private_key_id\",\n private_key=\"-----BEGIN PRIVATE KEY-----...\",\n client_email=\"...@....iam.gserviceaccount.com\",\n client_id=\"your_client_id\",\n auth_uri=\"https://accounts.google.com/o/oauth2/auth\",\n token_uri=\"https://oauth2.googleapis.com/token\",\n auth_provider_x509_cert_url=\"https://www.googleapis.com/oauth2/v1/certs\",\n client_x509_cert_url=\"https://www.googleapis.com/robot/v1/metadata/x509/...\",\n universe_domain=\"googleapis.com\"\n )\n\n\n config = ServiceAccountConfig.model_construct(**{\n ...service account config dict\n })", "properties": { "type": { "default": "", "title": "Type", "type": "string" }, "project_id": { "title": "Project Id", "type": "string" }, "private_key_id": { "title": "Private Key Id", "type": "string" }, "private_key": { "title": "Private Key", "type": "string" }, "client_email": { "title": "Client Email", "type": "string" }, "client_id": { "title": "Client Id", "type": "string" }, "auth_uri": { "title": "Auth Uri", "type": "string" }, "token_uri": { "title": "Token Uri", "type": "string" }, "auth_provider_x509_cert_url": { "title": "Auth Provider X509 Cert Url", "type": "string" }, "client_x509_cert_url": { "title": "Client X509 Cert Url", "type": "string" }, "universe_domain": { "title": "Universe Domain", "type": "string" } }, "required": [ "project_id", "private_key_id", "private_key", "client_email", "client_id", "auth_uri", "token_uri", "auth_provider_x509_cert_url", "client_x509_cert_url", "universe_domain" ], "title": "ServiceAccountCredential", "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.
- create_session(*, app_name, user_id, state=None, session_id=None)¶
Creates a new session.
- Return type:
- 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
- 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¶
- class google.adk.tools.APIHubToolset(*, apihub_resource_name, access_token=None, service_account_json=None, name='', description='', lazy_load_spec=False, auth_scheme=None, auth_credential=None, apihub_client=None)¶
Bases:
object
APIHubTool generates tools from a given API Hub resource.
Examples:
``` apihub_toolset = APIHubToolset(
apihub_resource_name=”projects/test-project/locations/us-central1/apis/test-api”, service_account_json=”…”,
)
# Get all available tools agent = LlmAgent(tools=apihub_toolset.get_tools())
# Get a specific tool agent = LlmAgent(tools=[
… apihub_toolset.get_tool(‘my_tool’),
])¶
- apihub_resource_name is the resource name from API Hub. It must include
API name, and can optionally include API version and spec name. - If apihub_resource_name includes a spec resource name, the content of that
spec will be used for generating the tools.
If apihub_resource_name includes only an api or a version name, the first spec of the first version of that API will be used.
Initializes the APIHubTool with the given parameters.
Examples: ``` apihub_toolset = APIHubToolset(
apihub_resource_name=”projects/test-project/locations/us-central1/apis/test-api”, service_account_json=”…”,
)
# Get all available tools agent = LlmAgent(tools=apihub_toolset.get_tools())
# Get a specific tool agent = LlmAgent(tools=[
… apihub_toolset.get_tool(‘my_tool’),
])¶
apihub_resource_name is the resource name from API Hub. It must include API name, and can optionally include API version and spec name. - If apihub_resource_name includes a spec resource name, the content of that
spec will be used for generating the tools.
If apihub_resource_name includes only an api or a version name, the first spec of the first version of that API will be used.
Example: * projects/xxx/locations/us-central1/apis/apiname/… * https://console.cloud.google.com/apigee/api-hub/apis/apiname?project=xxx
- param apihub_resource_name:
The resource name of the API in API Hub. Example: projects/test-project/locations/us-central1/apis/test-api.
- param access_token:
Google Access token. Generate with gcloud cli gcloud auth auth print-access-token. Used for fetching API Specs from API Hub.
- param service_account_json:
The service account config as a json string. Required if not using default service credential. It is used for creating the API Hub client and fetching the API Specs from API Hub.
- param apihub_client:
Optional custom API Hub client.
- param name:
Name of the toolset. Optional.
- param description:
Description of the toolset. Optional.
- param auth_scheme:
Auth scheme that applies to all the tool in the toolset.
- param auth_credential:
Auth credential that applies to all the tool in the toolset.
- param lazy_load_spec:
If True, the spec will be loaded lazily when needed. Otherwise, the spec will be loaded immediately and the tools will be generated during initialization.
- get_tool(name)¶
Retrieves a specific tool by its name.
- Return type:
Optional
[RestApiTool
]
Example:
` apihub_tool = apihub_toolset.get_tool('my_tool') `
- Parameters:
name – The name of the tool to retrieve.
- Returns:
The tool with the given name, or None if no such tool exists.
- get_tools()¶
Retrieves all available tools.
- Return type:
List
[RestApiTool
]- Returns:
A list of all available RestApiTool objects.
- pydantic model google.adk.tools.AuthToolArguments¶
Bases:
BaseModel
the arguments for the special long running function tool that is used to
request end user credentials.
Show JSON schema
{ "title": "AuthToolArguments", "description": "the arguments for the special long running function tool that is used to\n\nrequest end user credentials.", "type": "object", "properties": { "function_call_id": { "title": "Function Call Id", "type": "string" }, "auth_config": { "$ref": "#/$defs/AuthConfig" } }, "$defs": { "APIKey": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "apiKey" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "in": { "$ref": "#/$defs/APIKeyIn" }, "name": { "title": "Name", "type": "string" } }, "required": [ "in", "name" ], "title": "APIKey", "type": "object" }, "APIKeyIn": { "enum": [ "query", "header", "cookie" ], "title": "APIKeyIn", "type": "string" }, "AuthConfig": { "description": "The auth config sent by tool asking client to collect auth credentails and\n\nadk and client will help to fill in the response", "properties": { "auth_scheme": { "anyOf": [ { "$ref": "#/$defs/APIKey" }, { "$ref": "#/$defs/HTTPBase" }, { "$ref": "#/$defs/OAuth2" }, { "$ref": "#/$defs/OpenIdConnect" }, { "$ref": "#/$defs/HTTPBearer" }, { "$ref": "#/$defs/OpenIdConnectWithConfig" } ], "title": "Auth Scheme" }, "raw_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null }, "exchanged_auth_credential": { "$ref": "#/$defs/AuthCredential", "default": null } }, "required": [ "auth_scheme" ], "title": "AuthConfig", "type": "object" }, "AuthCredential": { "additionalProperties": true, "description": "Data class representing an authentication credential.\n\nTo exchange for the actual credential, please use\nCredentialExchanger.exchange_credential().\n\nExamples: API Key Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n api_key=\"1234\",\n)\n\nExample: HTTP Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"basic\",\n credentials=HttpCredentials(username=\"user\", password=\"password\"),\n ),\n)\n\nExample: OAuth2 Bearer Token in HTTP Header\nAuthCredential(\n auth_type=AuthCredentialTypes.HTTP,\n http=HttpAuth(\n scheme=\"bearer\",\n credentials=HttpCredentials(token=\"eyAkaknabna....\"),\n ),\n)\n\nExample: OAuth2 Auth with Authorization Code Flow\nAuthCredential(\n auth_type=AuthCredentialTypes.OAUTH2,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n ),\n)\n\nExample: OpenID Connect Auth\nAuthCredential(\n auth_type=AuthCredentialTypes.OPEN_ID_CONNECT,\n oauth2=OAuth2Auth(\n client_id=\"1234\",\n client_secret=\"secret\",\n redirect_uri=\"https://example.com\",\n scopes=[\"scope1\", \"scope2\"],\n ),\n)\n\nExample: Auth with resource reference\nAuthCredential(\n auth_type=AuthCredentialTypes.API_KEY,\n resource_ref=\"projects/1234/locations/us-central1/resources/resource1\",\n)", "properties": { "auth_type": { "$ref": "#/$defs/AuthCredentialTypes" }, "resource_ref": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Resource Ref" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Api Key" }, "http": { "anyOf": [ { "$ref": "#/$defs/HttpAuth" }, { "type": "null" } ], "default": null }, "service_account": { "anyOf": [ { "$ref": "#/$defs/ServiceAccount" }, { "type": "null" } ], "default": null }, "oauth2": { "anyOf": [ { "$ref": "#/$defs/OAuth2Auth" }, { "type": "null" } ], "default": null } }, "required": [ "auth_type" ], "title": "AuthCredential", "type": "object" }, "AuthCredentialTypes": { "description": "Represents the type of authentication credential.", "enum": [ "apiKey", "http", "oauth2", "openIdConnect", "serviceAccount" ], "title": "AuthCredentialTypes", "type": "string" }, "HTTPBase": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "title": "Scheme", "type": "string" } }, "required": [ "scheme" ], "title": "HTTPBase", "type": "object" }, "HTTPBearer": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "http" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "scheme": { "const": "bearer", "default": "bearer", "title": "Scheme", "type": "string" }, "bearerFormat": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Bearerformat" } }, "title": "HTTPBearer", "type": "object" }, "HttpAuth": { "additionalProperties": true, "description": "The credentials and metadata for HTTP authentication.", "properties": { "scheme": { "title": "Scheme", "type": "string" }, "credentials": { "$ref": "#/$defs/HttpCredentials" } }, "required": [ "scheme", "credentials" ], "title": "HttpAuth", "type": "object" }, "HttpCredentials": { "additionalProperties": true, "description": "Represents the secret token value for HTTP authentication, like user name, password, oauth token, etc.", "properties": { "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Username" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Password" }, "token": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "HttpCredentials", "type": "object" }, "OAuth2": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "oauth2" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "flows": { "$ref": "#/$defs/OAuthFlows" } }, "required": [ "flows" ], "title": "OAuth2", "type": "object" }, "OAuth2Auth": { "additionalProperties": true, "description": "Represents credential value and its metadata for a OAuth2 credential.", "properties": { "client_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Id" }, "client_secret": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Client Secret" }, "auth_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Uri" }, "state": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "State" }, "redirect_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Redirect Uri" }, "auth_response_uri": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Response Uri" }, "auth_code": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Auth Code" }, "token": { "anyOf": [ { "additionalProperties": true, "type": "object" }, { "type": "null" } ], "default": null, "title": "Token" } }, "title": "OAuth2Auth", "type": "object" }, "OAuthFlowAuthorizationCode": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "authorizationUrl", "tokenUrl" ], "title": "OAuthFlowAuthorizationCode", "type": "object" }, "OAuthFlowClientCredentials": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowClientCredentials", "type": "object" }, "OAuthFlowImplicit": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "authorizationUrl": { "title": "Authorizationurl", "type": "string" } }, "required": [ "authorizationUrl" ], "title": "OAuthFlowImplicit", "type": "object" }, "OAuthFlowPassword": { "additionalProperties": true, "properties": { "refreshUrl": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Refreshurl" }, "scopes": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Scopes", "type": "object" }, "tokenUrl": { "title": "Tokenurl", "type": "string" } }, "required": [ "tokenUrl" ], "title": "OAuthFlowPassword", "type": "object" }, "OAuthFlows": { "additionalProperties": true, "properties": { "implicit": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowImplicit" }, { "type": "null" } ], "default": null }, "password": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowPassword" }, { "type": "null" } ], "default": null }, "clientCredentials": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowClientCredentials" }, { "type": "null" } ], "default": null }, "authorizationCode": { "anyOf": [ { "$ref": "#/$defs/OAuthFlowAuthorizationCode" }, { "type": "null" } ], "default": null } }, "title": "OAuthFlows", "type": "object" }, "OpenIdConnect": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "openIdConnectUrl": { "title": "Openidconnecturl", "type": "string" } }, "required": [ "openIdConnectUrl" ], "title": "OpenIdConnect", "type": "object" }, "OpenIdConnectWithConfig": { "additionalProperties": true, "properties": { "type": { "$ref": "#/$defs/SecuritySchemeType", "default": "openIdConnect" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Description" }, "authorization_endpoint": { "title": "Authorization Endpoint", "type": "string" }, "token_endpoint": { "title": "Token Endpoint", "type": "string" }, "userinfo_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Userinfo Endpoint" }, "revocation_endpoint": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Revocation Endpoint" }, "token_endpoint_auth_methods_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Token Endpoint Auth Methods Supported" }, "grant_types_supported": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Grant Types Supported" }, "scopes": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Scopes" } }, "required": [ "authorization_endpoint", "token_endpoint" ], "title": "OpenIdConnectWithConfig", "type": "object" }, "SecuritySchemeType": { "enum": [ "apiKey", "http", "oauth2", "openIdConnect" ], "title": "SecuritySchemeType", "type": "string" }, "ServiceAccount": { "additionalProperties": true, "description": "Represents Google Service Account configuration.", "properties": { "service_account_credential": { "anyOf": [ { "$ref": "#/$defs/ServiceAccountCredential" }, { "type": "null" } ], "default": null }, "scopes": { "items": { "type": "string" }, "title": "Scopes", "type": "array" }, "use_default_credential": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": false, "title": "Use Default Credential" } }, "required": [ "scopes" ], "title": "ServiceAccount", "type": "object" }, "ServiceAccountCredential": { "additionalProperties": true, "description": "Represents Google Service Account configuration.\n\nAttributes:\n type: The type should be \"service_account\".\n project_id: The project ID.\n private_key_id: The ID of the private key.\n private_key: The private key.\n client_email: The client email.\n client_id: The client ID.\n auth_uri: The authorization URI.\n token_uri: The token URI.\n auth_provider_x509_cert_url: URL for auth provider's X.509 cert.\n client_x509_cert_url: URL for the client's X.509 cert.\n universe_domain: The universe domain.\n\nExample:\n\n config = ServiceAccountCredential(\n type_=\"service_account\",\n project_id=\"your_project_id\",\n private_key_id=\"your_private_key_id\",\n private_key=\"-----BEGIN PRIVATE KEY-----...\",\n client_email=\"...@....iam.gserviceaccount.com\",\n client_id=\"your_client_id\",\n auth_uri=\"https://accounts.google.com/o/oauth2/auth\",\n token_uri=\"https://oauth2.googleapis.com/token\",\n auth_provider_x509_cert_url=\"https://www.googleapis.com/oauth2/v1/certs\",\n client_x509_cert_url=\"https://www.googleapis.com/robot/v1/metadata/x509/...\",\n universe_domain=\"googleapis.com\"\n )\n\n\n config = ServiceAccountConfig.model_construct(**{\n ...service account config dict\n })", "properties": { "type": { "default": "", "title": "Type", "type": "string" }, "project_id": { "title": "Project Id", "type": "string" }, "private_key_id": { "title": "Private Key Id", "type": "string" }, "private_key": { "title": "Private Key", "type": "string" }, "client_email": { "title": "Client Email", "type": "string" }, "client_id": { "title": "Client Id", "type": "string" }, "auth_uri": { "title": "Auth Uri", "type": "string" }, "token_uri": { "title": "Token Uri", "type": "string" }, "auth_provider_x509_cert_url": { "title": "Auth Provider X509 Cert Url", "type": "string" }, "client_x509_cert_url": { "title": "Client X509 Cert Url", "type": "string" }, "universe_domain": { "title": "Universe Domain", "type": "string" } }, "required": [ "project_id", "private_key_id", "private_key", "client_email", "client_id", "auth_uri", "token_uri", "auth_provider_x509_cert_url", "client_x509_cert_url", "universe_domain" ], "title": "ServiceAccountCredential", "type": "object" } }, "required": [ "function_call_id", "auth_config" ] }
- Fields:
auth_config (google.adk.auth.auth_tool.AuthConfig)
function_call_id (str)
-
field auth_config:
AuthConfig
[Required]¶
-
field function_call_id:
str
[Required]¶
- class google.adk.tools.BaseTool(*, name, description, is_long_running=False)¶
Bases:
ABC
The base class for all tools.
-
description:
str
¶ The description of the tool.
-
is_long_running:
bool
= False¶ Whether the tool is a long running operation, which typically returns a resource id first and finishes the operation later.
-
name:
str
¶ The name of the tool.
- async process_llm_request(*, tool_context, llm_request)¶
Processes the outgoing LLM request for this tool.
Use cases: - Most common use case is adding this tool to the LLM request. - Some tools may just preprocess the LLM request before it’s sent out.
- Return type:
None
- Parameters:
tool_context – The context of the tool.
llm_request – The outgoing LLM request, mutable this method.
- async run_async(*, args, tool_context)¶
Runs the tool with the given arguments and context.
NOTE :rtype:
Any
Required if this tool needs to run at the client side.
Otherwise, can be skipped, e.g. for a built-in GoogleSearch tool for Gemini.
- Parameters:
args – The LLM-filled arguments.
ctx – The context of the tool.
- Returns:
The result of running the tool.
-
description:
- class google.adk.tools.ExampleTool(examples)¶
Bases:
BaseTool
A tool that adds (few-shot) examples to the LLM request.
- examples¶
The examples to add to the LLM request.
- async process_llm_request(*, tool_context, llm_request)¶
Processes the outgoing LLM request for this tool.
Use cases: - Most common use case is adding this tool to the LLM request. - Some tools may just preprocess the LLM request before it’s sent out.
- Return type:
None
- Parameters:
tool_context – The context of the tool.
llm_request – The outgoing LLM request, mutable this method.
- class google.adk.tools.FunctionTool(func)¶
Bases:
BaseTool
A tool that wraps a user-defined Python function.
- func¶
The function to wrap.
- async run_async(*, args, tool_context)¶
Runs the tool with the given arguments and context.
NOTE :rtype:
Any
Required if this tool needs to run at the client side.
Otherwise, can be skipped, e.g. for a built-in GoogleSearch tool for Gemini.
- Parameters:
args – The LLM-filled arguments.
ctx – The context of the tool.
- Returns:
The result of running the tool.
- class google.adk.tools.LongRunningFunctionTool(func)¶
Bases:
FunctionTool
A function tool that returns the result asynchronously.
This tool is used for long-running operations that may take a significant amount of time to complete. The framework will call the function. Once the function returns, the response will be returned asynchronously to the framework which is identified by the function_call_id.
Example:
`python tool = LongRunningFunctionTool(a_long_running_function) `
- is_long_running¶
Whether the tool is a long running operation.
- class google.adk.tools.ToolContext(invocation_context, *, function_call_id=None, event_actions=None)¶
Bases:
CallbackContext
The context of the tool.
This class provides the context for a tool invocation, including access to the invocation context, function call ID, event actions, and authentication response. It also provides methods for requesting credentials, retrieving authentication responses, listing artifacts, and searching memory.
- invocation_context¶
The invocation context of the tool.
- function_call_id¶
The function call id of the current tool call. This id was returned in the function call event from LLM to identify a function call. If LLM didn’t return this id, ADK will assign one to it. This id is used to map function call response to the original function call.
- event_actions¶
The event actions of the current tool call.
- property actions: EventActions¶
- get_auth_response(auth_config)¶
- Return type:
AuthCredential
- list_artifacts()¶
Lists the filenames of the artifacts attached to the current session.
- Return type:
list
[str
]
- request_credential(auth_config)¶
- Return type:
None
- search_memory(query)¶
Searches the memory of the current user.
- Return type:
SearchMemoryResponse
- class google.adk.tools.VertexAiSearchTool(*, data_store_id=None, search_engine_id=None)¶
Bases:
BaseTool
A built-in tool using Vertex AI Search.
- data_store_id¶
The Vertex AI search data store resource ID.
- search_engine_id¶
The Vertex AI search engine resource ID.
Initializes the Vertex AI Search tool.
- Parameters:
data_store_id – The Vertex AI search data store resource ID in the format of “projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}”.
search_engine_id – The Vertex AI search engine resource ID in the format of “projects/{project}/locations/{location}/collections/{collection}/engines/{engine}”.
- Raises:
ValueError – If both data_store_id and search_engine_id are not specified
or both are specified. –
- async process_llm_request(*, tool_context, llm_request)¶
Processes the outgoing LLM request for this tool.
Use cases: - Most common use case is adding this tool to the LLM request. - Some tools may just preprocess the LLM request before it’s sent out.
- Return type:
None
- Parameters:
tool_context – The context of the tool.
llm_request – The outgoing LLM request, mutable this method.
- google.adk.tools.exit_loop(tool_context)¶
Exits the loop.
Call this function only when you are instructed to do so.
- google.adk.tools.transfer_to_agent(agent_name, tool_context)¶
Transfer the question to another agent.