子模块¶
google.adk.agents 模块¶
- pydantic model google.adk.agents.BaseAgent¶
基类:
BaseModelAgent Development Kit中所有智能体的基类。
显示JSON架构
{ "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¶
智能体运行后调用的回调函数签名。
- Parameters:
callback_context – 必须命名为'callback_context'(强制要求)。
- Returns:
返回给用户的内容。设置后,将跳过智能体运行,并将提供的内容作为智能体响应附加到事件历史记录中。
- field before_agent_callback: Optional[BeforeAgentCallback] = None¶
在智能体运行前调用的回调函数签名。
- Parameters:
callback_context – 必须命名为'callback_context'(强制要求)。
- Returns:
返回给用户的内容。当设置此项时,将跳过智能体运行流程,直接向用户返回提供的预设内容。
- field description: str = ''¶
关于智能体能力的描述。
模型使用这个来决定是否将控制权委托给智能体。简洁的一行描述就足够且更受推荐。
- field name: str [Required]¶
智能体的名称。
智能体名称必须是一个Python标识符,并且在智能体树中保持唯一。 智能体名称不能使用"user",因为该名称被保留用于终端用户的输入。
- Validated by:
__validate_name
- field parent_agent: Optional[BaseAgent] = None¶
该智能体的父级智能体。
请注意,一个智能体只能作为子智能体添加一次。
如果你想将一个智能体作为子智能体添加两次,可以考虑创建两个配置相同但名称不同的智能体实例,然后将它们添加到智能体树中。
- field sub_agents: list[BaseAgent] [Optional]¶
该智能体的子智能体。
- find_agent(name)¶
在此智能体及其后代中查找具有给定名称的智能体。
- Return type:
可选[BaseAgent]- Parameters:
name – 要查找的智能体名称。
- Returns:
匹配名称的智能体,如果未找到则返回None。
- find_sub_agent(name)¶
在该智能体的后代中查找具有给定名称的智能体。
- Return type:
可选[BaseAgent]- Parameters:
name – 要查找的智能体名称。
- Returns:
匹配名称的智能体,如果未找到则返回None。
- model_post_init(_BaseAgent__context)¶
重写此方法以在__init__和model_construct之后执行额外的初始化。 如果您想进行一些需要整个模型初始化后才能完成的验证,这会很有用。
- Return type:
None
- final async run_async(parent_context)¶
通过基于文本的对话运行智能体的入口方法。
- Return type:
AsyncGenerator[Event,None]- Parameters:
parent_context – InvocationContext,父级智能体的调用上下文。
- Yields:
事件 – 由智能体生成的事件。
- pydantic model google.adk.agents.LlmAgent¶
基类:
BaseAgent基于LLM的智能体。
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])工具 (列表[工具联合类型])
- Validators:
__model_validator_after»所有 字段__validate_generate_content_config»generate_content_config
- field after_model_callback: Optional[AfterModelCallback] = None¶
在调用LLM之后调用。
- Parameters:
callback_context – CallbackContext,
llm_response – LlmResponse,实际模型响应。
- Returns:
返回给用户的内容。当存在时,实际模型响应将被忽略,并提供的内容将返回给用户。
- Validated by:
__model_validator_after
- field after_tool_callback: Optional[AfterToolCallback] = None¶
在工具被调用后执行。
- Parameters:
tool – 要调用的工具。
args – 工具的输入参数。
tool_context – ToolContext,
tool_response – 来自工具的响应。
- Returns:
如果存在,返回的字典将被用作工具结果。
- Validated by:
__model_validator_after
- field before_model_callback: Optional[BeforeModelCallback] = None¶
在调用LLM之前调用。 :param callback_context: CallbackContext, :param llm_request: LlmRequest, 原始模型请求。回调可以改变 :param request.:
- Returns:
返回给用户的内容。当存在此内容时,将跳过模型调用,并将提供的内容返回给用户。
- Validated by:
__model_validator_after
- field before_tool_callback: Optional[BeforeToolCallback] = None¶
在工具被调用之前调用。
- Parameters:
tool – 要调用的工具。
args – 工具的输入参数。
tool_context – ToolContext,
- Returns:
工具响应。当存在时,将使用返回的工具响应,框架将跳过调用实际工具。
- Validated by:
__model_validator_after
- field code_executor: Optional[BaseCodeExecutor] = None¶
允许智能体使用提供的CodeExecutor执行模型响应中的代码块。
查看google.adk.code_executor包中可用的代码执行功能。
注意:要使用模型内置的代码执行器,请不要设置此字段,改为添加google.adk.tools.built_in_code_execution到工具中。
- Validated by:
__model_validator_after
- field disallow_transfer_to_parent: bool = False¶
禁止LLM控制的转移到父智能体。
- Validated by:
__model_validator_after
- field disallow_transfer_to_peers: bool = False¶
禁止由LLM控制的向对等智能体的转移。
- Validated by:
__model_validator_after
- field examples: Optional[ExamplesUnion] = None¶
- Validated by:
__model_validator_after
- field generate_content_config: Optional[types.GenerateContentConfig] = None¶
额外的内容生成配置。
注意:并非所有字段都可用,例如工具必须通过tools配置, thinking_config必须通过LlmAgent中的planner进行配置。
例如:使用此配置来调整模型温度、配置安全设置等。
- Validated by:
__model_validator_after__validate_generate_content_config
- field global_instruction: Union[str, InstructionProvider] = ''¶
整个智能体树中所有智能体的使用说明。
全局指令仅在根智能体中生效。
例如:使用global_instruction可以让所有智能体保持稳定的身份或个性。
- Validated by:
__model_validator_after
- field include_contents: Literal['default', 'none'] = 'default'¶
是否在模型请求中包含内容。
当设置为'none'时,模型请求将不包含任何内容,例如用户消息、工具结果等。
- Validated by:
__model_validator_after
- field input_schema: Optional[type[BaseModel]] = None¶
当智能体作为工具使用时的输入模式。
- Validated by:
__model_validator_after
- field instruction: Union[str, InstructionProvider] = ''¶
指导LLM模型的指令,用于引导智能体的行为。
- Validated by:
__model_validator_after
- field model: Union[str, BaseLlm] = ''¶
用于智能体的模型。
如果未设置,智能体将从其父级继承模型。
- Validated by:
__model_validator_after
- field output_key: Optional[str] = None¶
会话状态中用于存储智能体输出的键。
典型用例: - 提取智能体回复以供后续使用,例如在工具、回调等场景中。 - 连接智能体以实现相互协作。
- Validated by:
__model_validator_after
- field output_schema: Optional[type[BaseModel]] = None¶
智能体回复时的输出模式。
注意:当设置此项时,智能体只能回复而不能使用任何工具,例如函数工具、RAGs、智能体转移等。
- Validated by:
__model_validator_after
- field planner: Optional[BasePlanner] = None¶
指示智能体制定计划并逐步执行。
注意:要使用模型内置的思考功能,请在google.adk.planners.built_in_planner中设置thinking_config字段。
- Validated by:
__model_validator_after
- field tools: list[ToolUnion] [Optional]¶
该智能体可用的工具。
- Validated by:
__model_validator_after
- canonical_global_instruction(ctx)¶
解析后的self.instruction字段用于构建全局指令。
此方法仅供Agent Development Kit使用。
- Return type:
str
- canonical_instruction(ctx)¶
用于构建该智能体指令的已解析self.instruction字段。
此方法仅供Agent Development Kit使用。
- Return type:
str
- pydantic model google.adk.agents.LoopAgent¶
基类:
BaseAgent一个在循环中运行其子智能体的shell智能体。
当子智能体生成带有升级事件或达到最大迭代次数时,循环智能体将停止。
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¶
运行循环智能体的最大迭代次数。
如果未设置,循环智能体将无限期运行,直到子智能体升级。
- pydantic model google.adk.agents.ParallelAgent¶
基类:
BaseAgent一个以隔离方式并行运行其子智能体的shell智能体。
这种方法适用于需要从多个角度或尝试完成单一任务的场景,例如:
同时运行不同的算法。
生成多个响应供后续评估智能体审查。
显示JSON结构
{ "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¶
基类:
BaseAgent一个按顺序运行其子智能体的shell智能体。
显示JSON架构
{ "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 模块¶
- class google.adk.artifacts.BaseArtifactService¶
基类:
ABC用于智能体服务的抽象基类。
- abstract delete_artifact(*, app_name, user_id, session_id, filename)¶
删除一个构件。
- Return type:
None- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- abstract list_artifact_keys(*, app_name, user_id, session_id)¶
列出会话中的所有工件文件名。
- Return type:
list[str]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
- Returns:
会话中所有工件文件名的列表。
- abstract list_versions(*, app_name, user_id, session_id, filename)¶
列出某个工件的所有版本。
- Return type:
list[int]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- Returns:
列出该工件的所有可用版本。
- abstract load_artifact(*, app_name, user_id, session_id, filename, version=None)¶
从智能体服务存储中获取一个构件。
该制品是一个由应用名称、用户ID、会话ID和文件名标识的文件。
- Return type:
可选[部分]- Parameters:
app_name – 应用程序名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
version – 工件的版本号。如果为None,将返回最新版本。
- Returns:
如果未找到,则返回该制品或None。
- abstract save_artifact(*, app_name, user_id, session_id, filename, artifact)¶
将制品保存到制品服务存储中。
该工件是一个由应用名称、用户ID、会话ID和文件名标识的文件。保存工件后,会返回一个修订ID用于标识该工件的版本。
- Return type:
int- Parameters:
app_name – 应用名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
artifact – 要保存的工件。
- Returns:
修订ID。工件的第一个版本修订ID为0。 每次成功保存后,该值会递增1。
- class google.adk.artifacts.GcsArtifactService(bucket_name, **kwargs)¶
-
一个使用Google云存储(GCS)实现的工件服务。
初始化GcsArtifactService。
- Parameters:
bucket_name – 要使用的存储桶名称。
**kwargs – 传递给Google Cloud Storage客户端的关键字参数。
- delete_artifact(*, app_name, user_id, session_id, filename)¶
删除一个构件。
- Return type:
None- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- list_artifact_keys(*, app_name, user_id, session_id)¶
列出会话中的所有工件文件名。
- Return type:
list[str]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
- Returns:
会话中所有工件文件名的列表。
- list_versions(*, app_name, user_id, session_id, filename)¶
列出某个工件的所有版本。
- Return type:
list[int]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- Returns:
列出该工件的所有可用版本。
- load_artifact(*, app_name, user_id, session_id, filename, version=None)¶
从智能体服务存储中获取一个构件。
该制品是一个由应用名称、用户ID、会话ID和文件名标识的文件。
- Return type:
可选[部分]- Parameters:
app_name – 应用程序名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
version – 工件的版本号。如果为None,将返回最新版本。
- Returns:
如果未找到,则返回该制品或None。
- save_artifact(*, app_name, user_id, session_id, filename, artifact)¶
将制品保存到制品服务存储中。
该工件是一个由应用名称、用户ID、会话ID和文件名标识的文件。保存工件后,会返回一个修订ID用于标识该工件的版本。
- Return type:
int- Parameters:
app_name – 应用程序名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
artifact – 要保存的工件。
- Returns:
修订ID。工件的第一个版本修订ID为0。 每次成功保存后,该值会递增1。
- pydantic model google.adk.artifacts.InMemoryArtifactService¶
基类:
BaseArtifactService,BaseModel工件服务的内存实现。
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)¶
删除一个构件。
- Return type:
None- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- list_artifact_keys(*, app_name, user_id, session_id)¶
列出会话中的所有工件文件名。
- Return type:
list[str]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
- Returns:
会话中所有工件文件名的列表。
- list_versions(*, app_name, user_id, session_id, filename)¶
列出某个工件的所有版本。
- Return type:
list[int]- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
session_id – 会话的ID。
filename – 工件文件的名称。
- Returns:
列出该工件的所有可用版本。
- load_artifact(*, app_name, user_id, session_id, filename, version=None)¶
从智能体服务存储中获取一个构件。
该制品是一个由应用名称、用户ID、会话ID和文件名标识的文件。
- Return type:
可选[部分]- Parameters:
app_name – 应用名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
version – 工件的版本号。如果为None,将返回最新版本。
- Returns:
如果未找到,则返回该制品或None。
- save_artifact(*, app_name, user_id, session_id, filename, artifact)¶
将制品保存到制品服务存储中。
该工件是一个由应用名称、用户ID、会话ID和文件名标识的文件。保存工件后,会返回一个修订ID用于标识该工件的版本。
- Return type:
int- Parameters:
app_name – 应用名称。
user_id – 用户ID。
session_id – 会话ID。
filename – 该制品的文件名。
artifact – 要保存的工件。
- Returns:
修订ID。工件的第一个版本修订ID为0。 每次成功保存后,该值会递增1。
google.adk.code_executors 模块¶
- pydantic model google.adk.code_executors.BaseCodeExecutor¶
基类:
BaseModel所有代码执行器的抽象基类。
代码执行器允许智能体执行来自模型响应的代码块,并将执行结果整合到最终响应中。
- optimize_data_file¶
如果为true,则从模型请求中提取并处理数据文件,并将其附加到代码执行器。支持的数据文件MimeTypes为[text/csv]。默认为False。
- stateful¶
代码执行器是否是有状态的。默认为False。
- error_retry_attempts¶
在连续代码执行错误时重试的次数。默认为2。
- code_block_delimiters¶
用于识别代码块的包围分隔符列表。
- execution_result_delimiters¶
用于格式化代码执行结果的分隔符。
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```')]¶ 用于识别以下格式的代码块:
`python print("hello") `
-
field error_retry_attempts:
int= 2¶ 在连续代码执行错误时重试的次数。默认为2。
-
field execution_result_delimiters:
tuple[str,str] = ('```tool_output\n', '\n```')¶ 用于格式化代码执行结果的分隔符。
-
field optimize_data_file:
bool= False¶ 如果为true,则从模型请求中提取并处理数据文件,并将其附加到代码执行器。支持的数据文件MimeTypes为[text/csv]。
默认为False。
-
field stateful:
bool= False¶ 代码执行器是否是有状态的。默认为False。
- abstract execute_code(invocation_context, code_execution_input)¶
执行代码并返回代码执行结果。
- Return type:
CodeExecutionResult- Parameters:
invocation_context - 代码执行的调用上下文。
code_execution_input – 代码执行输入。
- Returns:
代码执行结果。
- class google.adk.code_executors.CodeExecutorContext(session_state)¶
基类:
object用于配置代码执行器的持久化上下文。
初始化代码执行器上下文。
- Parameters:
session_state – 用于获取代码执行器上下文的会话状态。
- add_input_files(input_files)¶
将输入文件添加到代码执行器上下文中。
- Parameters:
input_files – 要添加到代码执行器上下文中的输入文件。
- add_processed_file_names(file_names)¶
将处理后的文件名添加到会话状态中。
- Parameters:
file_names – 要添加到会话状态的已处理文件名。
- clear_input_files()¶
将输入文件和处理后的文件名移除到代码执行器上下文中。
- get_error_count(invocation_id)¶
从会话状态获取错误计数。
- Return type:
int- Parameters:
invocation_id – 要获取错误次数的调用ID。
- Returns:
给定调用ID的错误计数。
- get_execution_id()¶
获取代码执行器的会话ID。
- Return type:
可选[str]- Returns:
代码执行器上下文的会话ID。
- get_input_files()¶
从会话状态中获取代码执行器的输入文件名。
- Return type:
list[File]- Returns:
代码执行器上下文中的输入文件列表。
- get_processed_file_names()¶
从会话状态中获取已处理的文件名。
- Return type:
list[str]- Returns:
代码执行上下文中已处理的文件名列表。
- get_state_delta()¶
获取要在持久会话状态中更新的状态增量。
- Return type:
dict[str,Any]- Returns:
要在持久会话状态中更新的状态增量。
- increment_error_count(invocation_id)¶
增加会话状态中的错误计数。
- Parameters:
invocation_id – 用于增加错误计数的调用ID。
- reset_error_count(invocation_id)¶
重置会话状态中的错误计数。
- Parameters:
invocation_id – 用于重置错误计数的调用ID。
- set_execution_id(session_id)¶
为代码执行器设置会话ID。
- Parameters:
session_id – 代码执行器的会话ID。
- update_code_execution_result(invocation_id, code, result_stdout, result_stderr)¶
更新代码执行结果。
- Parameters:
invocation_id – 用于更新代码执行结果的调用ID。
code – 要执行的代码。
result_stdout – 代码执行的标准输出。
result_stderr – 代码执行的标准错误输出。
- pydantic model google.adk.code_executors.ContainerCodeExecutor¶
基类:
BaseCodeExecutor一个使用自定义容器来执行代码的代码执行器。
- base_url¶
可选。用户托管的Docker客户端的基础URL。
- image¶
要在容器上运行的预定义镜像或自定义镜像的标签。必须设置docker_path或image其中之一。
- docker_path¶
包含Dockerfile的目录路径。如果设置了该参数,将从dockerfile路径构建镜像,而不是使用预定义的镜像。必须设置docker_path或image其中一项。
初始化ContainerCodeExecutor。
- Parameters:
base_url – 可选。用户托管的Docker客户端的基础URL。
image – 容器上运行的预定义镜像或自定义镜像的标签。必须设置 docker_path 或 image 其中之一。
docker_path – 包含Dockerfile的目录路径。如果设置此项,将从dockerfile路径构建镜像,而非使用预定义的镜像。必须设置docker_path或image其中一项。
**data – 用于初始化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¶ 可选。用户托管的Docker客户端的基础URL。
-
field docker_path:
str= None¶ 包含Dockerfile的目录路径。 如果设置此项,将从dockerfile路径构建镜像,而非使用预定义的镜像。必须设置docker_path或image其中一项。
-
field image:
str= None¶ 容器上运行的预定义镜像或自定义镜像的标签。 必须设置 docker_path 或 image 其中之一。
-
field optimize_data_file:
bool= False¶ 如果为true,则从模型请求中提取并处理数据文件,并将其附加到代码执行器。支持的数据文件MimeTypes为[text/csv]。
默认为False。
-
field stateful:
bool= False¶ 代码执行器是否是有状态的。默认为False。
- execute_code(invocation_context, code_execution_input)¶
执行代码并返回代码执行结果。
- Return type:
CodeExecutionResult- Parameters:
invocation_context - 代码执行的调用上下文。
code_execution_input – 代码执行输入。
- Returns:
代码执行结果。
- model_post_init(context, /)¶
此函数旨在模拟BaseModel方法的行为,用于初始化私有属性。
它接受context作为参数,因为这是pydantic-core在调用时传递的内容。
- Return type:
None- Parameters:
self – BaseModel实例。
context – 上下文。
- pydantic model google.adk.code_executors.UnsafeLocalCodeExecutor¶
基类:
BaseCodeExecutor一个在当前本地上下文中不安全执行代码的代码执行器。
初始化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¶ 如果为true,则从模型请求中提取并处理数据文件,并将其附加到代码执行器。支持的数据文件MimeTypes为[text/csv]。
默认为False。
-
field stateful:
bool= False¶ 代码执行器是否是有状态的。默认为False。
- execute_code(invocation_context, code_execution_input)¶
执行代码并返回代码执行结果。
- Return type:
CodeExecutionResult- Parameters:
invocation_context - 代码执行的调用上下文。
code_execution_input – 代码执行输入。
- Returns:
代码执行结果。
- pydantic model google.adk.code_executors.VertexAiCodeExecutor¶
基类:
BaseCodeExecutor一个使用Vertex代码解释器扩展来执行代码的代码执行器。
- resource_name¶
如果设置此项,将加载代码解释器扩展的现有资源名称,而不是创建新资源。格式:projects/123/locations/us-central1/extensions/456
初始化VertexAiCodeExecutor。
- Parameters:
resource_name – 如果设置,则加载现有代码解释器扩展的资源名称,而不是创建新的。格式:projects/123/locations/us-central1/extensions/456
**data – 传递给基类的额外关键字参数。
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¶ 如果设置此项,将加载代码解释器扩展的现有资源名称,而不是创建新的资源。 格式:projects/123/locations/us-central1/extensions/456
- execute_code(invocation_context, code_execution_input)¶
执行代码并返回代码执行结果。
- Return type:
CodeExecutionResult- Parameters:
invocation_context - 代码执行的调用上下文。
code_execution_input – 代码执行输入。
- Returns:
代码执行结果。
- model_post_init(context, /)¶
此函数旨在模拟BaseModel方法的行为,用于初始化私有属性。
它接受context作为参数,因为这是pydantic-core在调用时传递的内容。
- Return type:
None- Parameters:
self – BaseModel实例。
context – 上下文。
google.adk.evaluation 模块¶
- class google.adk.evaluation.AgentEvaluator¶
基类:
object一个用于评估智能体的工具,主要用于帮助测试用例。
- static evaluate(agent_module, eval_dataset_file_path_or_dir, num_runs=2, agent_name=None, initial_session_file=None)¶
根据评估数据评估智能体。
- Parameters:
agent_module – 指向包含智能体定义的python模块的路径。这里有一个约定,代码会在加载的模块中寻找'root_agent'。
eval_dataset – 评估数据集。这可以是一个表示包含评估数据集文件的完整路径的字符串,也可以是一个递归搜索所有具有.test.json后缀文件的目录。
num_runs – 评估数据集中所有条目需要被评估的次数。
agent_name – 智能体的名称。
initial_session_file – 包含评估数据集中所有评估所需的初始会话状态的文件。
- static find_config_for_test_file(test_file)¶
在测试文件所在的同一文件夹中找到test_config.json文件。
google.adk.events 模块¶
- pydantic model google.adk.events.Event¶
基类:
LlmResponse表示智能体与用户之间对话中的一个事件。
用于存储对话内容,以及智能体采取的操作,如函数调用等。
- invocation_id¶
事件的调用ID。
- author¶
“user” 或智能体的名称,表示是谁向会话添加了该事件。
- actions¶
智能体采取的行动。
- long_running_tool_ids¶
长时间运行函数调用的ID。
- branch¶
事件的分支。
- id¶
事件的唯一标识符。
- timestamp¶
事件的时间戳。
- is_final_response¶
该事件是否为智能体的最终响应。
- get_function_calls¶
返回事件中的函数调用。
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]¶
智能体采取的行动。
- field author: str [Required]¶
'user' 或智能体名称,表示谁向会话添加了该事件。
- field branch: Optional[str] = None¶
事件的分支。
格式类似于agent_1.agent_2.agent_3,其中agent_1是agent_2的父级,agent_2是agent_3的父级。
当多个子智能体不应看到其同级智能体的对话历史时,会使用Branch。
- field id: str = ''¶
事件的唯一标识符。
- field invocation_id: str = ''¶
事件的调用ID。
- field long_running_tool_ids: Optional[set[str]] = None¶
长时间运行函数调用的ID集合。 智能体客户端将通过此字段了解哪些函数调用是长时间运行的。 仅对函数调用事件有效
- field timestamp: float [Optional]¶
事件的时间戳。
- get_function_calls()¶
返回事件中的函数调用。
- Return type:
list[FunctionCall]
- get_function_responses()¶
返回事件中的函数响应。
- Return type:
list[FunctionResponse]
- has_trailing_code_exeuction_result()¶
返回事件是否具有后续代码执行结果。
- Return type:
bool
- is_final_response()¶
返回该事件是否为智能体的最终响应。
- Return type:
bool
- model_post_init(_Event__context)¶
事件的后初始化逻辑。
- static new_id()¶
- pydantic model google.adk.events.EventActions¶
基类:
BaseModel表示附加到事件上的操作。
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]¶
表示该事件正在更新一个工件。key是文件名,value是版本号。
- field escalate: Optional[bool] = None¶
智能体正在升级到更高层级的智能体。
- field requested_auth_configs: dict[str, AuthConfig] [Optional]¶
仅当工具响应指示工具请求euc时才会设置。 字典键是函数调用ID,因为一个函数调用响应(来自模型) 可能对应多个函数调用。 字典值是所需的授权配置。
- field skip_summarization: Optional[bool] = None¶
如果为true,则不会调用模型来汇总函数响应。
仅用于function_response事件。
- field state_delta: dict[str, object] [Optional]¶
表示该事件正在用给定的增量更新状态。
- field transfer_to_agent: Optional[str] = None¶
如果设置,事件将转移到指定的智能体。
google.adk.examples 模块¶
- class google.adk.examples.BaseExampleProvider¶
基类:
ABC示例提供者的基类。
该类定义了为给定查询提供示例的接口。
- pydantic model google.adk.examples.Example¶
基类:
BaseModel一个少样本示例。
- input¶
示例的输入内容。
- output¶
示例的预期输出内容。
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)¶
-
提供来自Vertex示例库的示例。
初始化VertexAiExampleStore。
- Parameters:
examples_store_name – 顶点示例存储的资源名称,格式为
projects/{project}/locations/{location}/exampleStores/{example_store}。
google.adk.memory 模块¶
- class google.adk.memory.BaseMemoryService¶
基类:
ABC内存服务的基类。
该服务提供将会话数据导入内存的功能,以便这些内存可用于用户查询。
- abstract add_session_to_memory(session)¶
向记忆服务添加一个会话。
一个会话在其生命周期内可能会被多次添加。
- Parameters:
session – 要添加的会话。
- abstract search_memory(*, app_name, user_id, query)¶
搜索匹配查询的会话。
- Return type:
SearchMemoryResponse- Parameters:
app_name – 应用程序的名称。
user_id – 用户ID。
query – 要搜索的查询。
- Returns:
包含匹配记忆的SearchMemoryResponse。
- class google.adk.memory.InMemoryMemoryService¶
-
仅用于原型设计的临时内存服务。
使用关键词匹配而非语义搜索。
- add_session_to_memory(session)¶
向记忆服务添加一个会话。
一个会话在其生命周期内可能会被多次添加。
- Parameters:
session – 要添加的会话。
- search_memory(*, app_name, user_id, query)¶
仅用于原型设计目的。
- Return type:
SearchMemoryResponse
- class google.adk.memory.VertexAiRagMemoryService(rag_corpus=None, similarity_top_k=None, vector_distance_threshold=10)¶
-
一种使用Vertex AI RAG进行存储和检索的记忆服务。
初始化一个VertexAiRagMemoryService。
- Parameters:
rag_corpus – 要使用的Vertex AI RAG语料库名称。格式:
projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}或{rag_corpus_id}similarity_top_k – 要检索的上下文数量。
vector_distance_threshold – 仅返回向量距离小于阈值的上下文。
- add_session_to_memory(session)¶
向记忆服务添加一个会话。
一个会话在其生命周期内可能会被多次添加。
- Parameters:
session – 要添加的会话。
- search_memory(*, app_name, user_id, query)¶
使用rag.retrieval_query搜索匹配查询的会话。
- Return type:
SearchMemoryResponse
google.adk.models 模块¶
定义支持模型的接口。
- pydantic model google.adk.models.BaseLlm¶
基类:
BaseModelBaseLLM类。
- model¶
LLM的名称,例如gemini-1.5-flash或gemini-1.5-flash-001。
- model_config¶
模型配置
显示JSON架构
{ "title": "BaseLlm", "description": "BaseLLM类。\n\n属性:\n model: LLM的名称,例如gemini-1.5-flash或gemini-1.5-flash-001。\n model_config: 模型配置", "type": "object", "properties": { "model": { "title": "Model", "type": "string" } }, "required": [ "model" ] }
- Fields:
model (str)
- field model: str [Required]¶
LLM的名称,例如 gemini-1.5-flash 或 gemini-1.5-flash-001。
- connect(llm_request)¶
创建一个与LLM的实时连接。
- Return type:
BaseLlmConnection- Parameters:
llm_request – LlmRequest,发送给大语言模型的请求。
- Returns:
BaseLlmConnection,连接到大语言模型。
- abstract async generate_content_async(llm_request, stream=False)¶
根据给定的内容和工具生成一个内容。
- Return type:
AsyncGenerator[LlmResponse,None]- Parameters:
llm_request – LlmRequest,发送给LLM的请求。
stream – bool = False, 是否进行流式调用。
- Yields:
一个类型内容的生成器。
对于非流式调用,它只会生成一个Content。
对于流式调用,它可能会产生多个内容,但所有产生的内容应被视为一个内容,通过合并各部分列表来处理。
- classmethod supported_models()¶
返回LlmRegistry支持的正则表达式模型列表。
- Return type:
list[str]
- pydantic model google.adk.models.Gemini¶
基类:
BaseLlmGemini模型的集成。
- model¶
Gemini模型的名称。
显示JSON架构
{ "title": "Gemini", "description": "Gemini模型的集成。\n\n属性:\n model: Gemini模型的名称。", "type": "object", "properties": { "model": { "default": "gemini-1.5-flash", "title": "Model", "type": "string" } } }
- Fields:
model (str)
- field model: str = 'gemini-1.5-flash'¶
LLM的名称,例如 gemini-1.5-flash 或 gemini-1.5-flash-001。
- connect(llm_request)¶
连接到Gemini模型并返回一个llm连接。
- Return type:
BaseLlmConnection- Parameters:
llm_request – LlmRequest,发送给Gemini模型的请求。
- Yields:
BaseLlmConnection,连接到Gemini模型的连接。
- async generate_content_async(llm_request, stream=False)¶
向Gemini模型发送请求。
- Return type:
AsyncGenerator[LlmResponse,None]- Parameters:
llm_request – LlmRequest,发送给Gemini模型的请求。
stream – bool = False, 是否进行流式调用。
- Yields:
LlmResponse – 模型响应。
- static supported_models()¶
提供支持的模型列表。
- Return type:
list[str]- Returns:
支持的模型列表。
- property api_client: Client¶
提供API客户端。
- Returns:
API客户端。
google.adk.planners 模块¶
- class google.adk.planners.BasePlanner¶
基类:
ABC所有规划器的抽象基类。
规划器允许智能体为查询生成计划,以指导其行动。
- abstract build_planning_instruction(readonly_context, llm_request)¶
构建要附加到LLM请求中以进行规划的系统指令。
- Return type:
可选[str]- Parameters:
readonly_context – 调用的只读上下文。
llm_request – LLM请求。只读。
- Returns:
规划系统指令,如果不需要指令则为None。
- abstract process_planning_response(callback_context, response_parts)¶
处理LLM响应的规划过程。
- Return type:
可选[列表[部分]]- Parameters:
callback_context – 调用的回调上下文。
response_parts – LLM响应部分。只读。
- Returns:
处理后的响应部分,如果不需要处理则为None。
- class google.adk.planners.BuiltInPlanner(*, thinking_config)¶
基类:
BasePlanner内置规划器,利用模型自带的思维功能。
- thinking_config¶
配置模型内置的思考功能。如果为不支持思考的模型设置此字段,将返回错误。
初始化内置规划器。
- Parameters:
thinking_config – 用于模型内置思考功能的配置。如果为不支持思考的模型设置此字段,将返回错误。
- apply_thinking_config(llm_request)¶
将思考配置应用到LLM请求中。
- Return type:
None- Parameters:
llm_request – 要应用思维配置的LLM请求。
- build_planning_instruction(readonly_context, llm_request)¶
构建要附加到LLM请求中以进行规划的系统指令。
- Return type:
可选[str]- Parameters:
readonly_context – 调用的只读上下文。
llm_request – LLM请求。只读。
- Returns:
规划系统指令,如果不需要指令则为None。
- process_planning_response(callback_context, response_parts)¶
处理LLM响应的规划过程。
- Return type:
可选[列表[部分]]- Parameters:
callback_context – 调用的回调上下文。
response_parts – LLM响应部分。只读。
- Returns:
处理后的响应部分,如果不需要处理则为None。
-
thinking_config:
ThinkingConfig¶ 配置模型内置的思考功能。如果为不支持思考的模型设置此字段,将返回错误。
- class google.adk.planners.PlanReActPlanner¶
基类:
BasePlannerPlan-Re-Act规划器,用于约束LLM在采取任何行动/观察之前生成计划。
注意:该规划器不需要模型支持内置思考功能或设置思考配置。
- build_planning_instruction(readonly_context, llm_request)¶
构建要附加到LLM请求中以进行规划的系统指令。
- Return type:
str- Parameters:
readonly_context – 调用的只读上下文。
llm_request – LLM请求。只读。
- Returns:
规划系统指令,如果不需要指令则为None。
- process_planning_response(callback_context, response_parts)¶
处理LLM响应的规划过程。
- Return type:
可选[列表[部分]]- Parameters:
callback_context – 调用的回调上下文。
response_parts – LLM响应部分。只读。
- Returns:
处理后的响应部分,如果不需要处理则为None。
google.adk.runners 模块¶
- class google.adk.runners.InMemoryRunner(agent, *, app_name='InMemoryRunner')¶
基类:
Runner用于测试和开发的内存运行器。
该运行器使用内存实现来处理工件、会话和记忆服务,为智能体执行提供了一个轻量级且自包含的环境。
- agent¶
要运行的根智能体。
- app_name¶
运行器的应用名称。默认为'InMemoryRunner'。
初始化InMemoryRunner。
- Parameters:
agent – 要运行的根智能体。
app_name – 运行器的应用名称。默认为'InMemoryRunner'。
- class google.adk.runners.Runner(*, app_name, agent, artifact_service=None, session_service, memory_service=None)¶
基类:
objectRunner类用于运行智能体。
它管理智能体在会话中的执行,处理消息传递、事件生成以及与各类服务的交互,如工件存储、会话管理和记忆功能。
- app_name¶
运行器的应用名称。
- agent¶
要运行的根智能体。
- artifact_service¶
运行器的构件服务。
- session_service¶
运行器的会话服务。
- memory_service¶
运行器的内存服务。
初始化运行器。
- Parameters:
app_name – 运行器的应用名称。
agent – 要运行的根智能体。
artifact_service – 运行器的工件服务。
session_service – 运行器的会话服务。
memory_service – 运行器的内存服务。
-
app_name:
str¶ 运行器的应用名称。
-
artifact_service:
Optional[BaseArtifactService] = None¶ 运行器的构件服务。
- close_session(session)¶
关闭会话并将其添加到记忆服务中(实验性功能)。
- Parameters:
session – 要关闭的会话。
-
memory_service:
Optional[BaseMemoryService] = None¶ 运行器的内存服务。
- 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))¶
运行智能体。
注意:此同步接口仅用于本地测试和便利目的。建议在生产环境中使用run_async。
- Return type:
Generator[Event,None,None]- Parameters:
user_id – 会话的用户ID。
session_id – 会话的会话ID。
new_message – 要追加到会话的新消息。
run_config – 智能体的运行配置。
- Yields:
由智能体生成的事件。
- 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))¶
在此运行器中运行智能体的主要入口方法。
- Return type:
AsyncGenerator[Event,None]- Parameters:
user_id – 会话的用户ID。
session_id – 会话的会话ID。
new_message – 要追加到会话的新消息。
run_config – 智能体的运行配置。
- Yields:
由智能体生成的事件。
- 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))¶
以实时模式运行智能体(实验性功能)。
- Return type:
AsyncGenerator[Event,None]- Parameters:
session – 要使用的会话。
live_request_queue – 实时请求队列。
run_config – 智能体的运行配置。
- Yields:
由智能体生成的事件。
-
session_service:
BaseSessionService¶ 运行器的会话服务。
google.adk.sessions 模块¶
- class google.adk.sessions.BaseSessionService¶
基类:
ABC会话服务的基类。
该服务提供了一套用于管理会话和事件的方法。
- close_session(*, session)¶
关闭一个会话。
- abstract create_session(*, app_name, user_id, state=None, session_id=None)¶
创建一个新会话。
- Return type:
- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
state – 会话的初始状态。
session_id – 客户端提供的会话ID。如果未提供,将使用生成的ID。
- Returns:
新创建的会话实例。
- Return type:
会话
- abstract delete_session(*, app_name, user_id, session_id)¶
删除一个会话。
- Return type:
None
- abstract list_events(*, app_name, user_id, session_id)¶
列出会话中的事件。
- Return type:
ListEventsResponse
- abstract list_sessions(*, app_name, user_id)¶
列出所有会话。
- Return type:
ListSessionsResponse
- class google.adk.sessions.DatabaseSessionService(db_url)¶
-
一个使用数据库进行存储的会话服务。
- Parameters:
db_url – 要连接的数据库URL。
- create_session(*, app_name, user_id, state=None, session_id=None)¶
创建一个新会话。
- Return type:
- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
state – 会话的初始状态。
session_id – 客户端提供的会话ID。如果未提供,将使用生成的ID。
- Returns:
新创建的会话实例。
- Return type:
会话
- delete_session(app_name, user_id, session_id)¶
删除一个会话。
- Return type:
None
- list_events(*, app_name, user_id, session_id)¶
列出会话中的事件。
- Return type:
ListEventsResponse
- list_sessions(*, app_name, user_id)¶
列出所有会话。
- Return type:
ListSessionsResponse
- class google.adk.sessions.InMemorySessionService¶
-
会话服务的内存实现。
- create_session(*, app_name, user_id, state=None, session_id=None)¶
创建一个新会话。
- Return type:
- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
state – 会话的初始状态。
session_id – 客户端提供的会话ID。如果未提供,将使用生成的ID。
- Returns:
新创建的会话实例。
- Return type:
会话
- delete_session(*, app_name, user_id, session_id)¶
删除一个会话。
- Return type:
None
- list_events(*, app_name, user_id, session_id)¶
列出会话中的事件。
- Return type:
ListEventsResponse
- list_sessions(*, app_name, user_id)¶
列出所有会话。
- Return type:
ListSessionsResponse
- pydantic model google.adk.sessions.Session¶
基类:
BaseModel表示用户与智能体之间的一系列交互。
- id¶
会话的唯一标识符。
- app_name¶
应用程序的名称。
- user_id¶
用户的ID。
- state¶
会话的状态。
- events¶
会话中的事件,例如用户输入、模型响应、函数调用/响应等。
- last_update_time¶
会话的最后更新时间。
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]¶ 应用程序的名称。
-
field id:
str[Required]¶ 会话的唯一标识符。
-
field last_update_time:
float= 0.0¶ 会话的最后更新时间。
-
field state:
dict[str,Any] [Optional]¶ 会话的状态。
-
field user_id:
str[Required]¶ 用户的ID。
- class google.adk.sessions.State(value, delta)¶
基类:
object一个状态字典,用于维护当前值和待提交的增量。
- Parameters:
value – 状态字典的当前值。
delta – 尚未提交的当前值的增量变化。
- APP_PREFIX = 'app:'¶
- TEMP_PREFIX = 'temp:'¶
- USER_PREFIX = 'user:'¶
- get(key, default=None)¶
返回给定键对应的状态字典值。
- Return type:
Any
- has_delta()¶
状态是否有待处理的增量。
- Return type:
bool
- to_dict()¶
返回状态字典。
- Return type:
dict[str,Any]
- update(delta)¶
使用给定的增量更新状态字典。
- class google.adk.sessions.VertexAiSessionService(project=None, location=None)¶
-
连接到托管的Vertex AI会话服务。
- create_session(*, app_name, user_id, state=None, session_id=None)¶
创建一个新会话。
- Return type:
- Parameters:
app_name – 应用程序的名称。
user_id – 用户的ID。
state – 会话的初始状态。
session_id – 客户端提供的会话ID。如果未提供,将使用生成的ID。
- Returns:
新创建的会话实例。
- Return type:
会话
- delete_session(*, app_name, user_id, session_id)¶
删除一个会话。
- Return type:
None
- list_events(*, app_name, user_id, session_id)¶
列出会话中的事件。
- Return type:
ListEventsResponse
- list_sessions(*, app_name, user_id)¶
列出所有会话。
- Return type:
ListSessionsResponse
google.adk.tools 模块¶
- 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)¶
基类:
objectAPIHubTool 根据给定的 API Hub 资源生成工具。
示例:
``` apihub_toolset = APIHubToolset(
apihub_resource_name=”projects/test-project/locations/us-central1/apis/test-api”, service_account_json=”…”,
)
# 获取所有可用工具 agent = LlmAgent(tools=apihub_toolset.get_tools())
# 获取特定工具 agent = LlmAgent(tools=[
… apihub_toolset.get_tool(‘my_tool’),
])¶
- apihub_resource_name is the resource name from API Hub. It must include
API名称,可以选择性地包含API版本和规范名称。 - 如果apihub_resource_name包含规范资源名称,则该内容
spec将用于生成工具。
如果apihub_resource_name仅包含API或版本名称,则将使用该API第一个版本的第一个规范。
使用给定的参数初始化APIHubTool。
示例: ``` apihub_toolset = APIHubToolset(
apihub_resource_name=”projects/test-project/locations/us-central1/apis/test-api”, service_account_json=”…”,
)
# 获取所有可用工具 agent = LlmAgent(tools=apihub_toolset.get_tools())
# 获取特定工具 agent = LlmAgent(tools=[
… apihub_toolset.get_tool(‘my_tool’),
])¶
apihub_resource_name 是来自API Hub的资源名称。它必须包含 API名称,并且可以选择性地包含API版本和规范名称。 - 如果apihub_resource_name包含规范资源名称,则该内容
spec将用于生成工具。
如果apihub_resource_name仅包含API或版本名称,则将使用该API第一个版本的第一个规范。
示例: * projects/xxx/locations/us-central1/apis/apiname/… * https://console.cloud.google.com/apigee/api-hub/apis/apiname?project=xxx
- param apihub_resource_name:
API在API Hub中的资源名称。 示例:projects/test-project/locations/us-central1/apis/test-api。
- param access_token:
Google访问令牌。使用gcloud命令行工具gcloud auth auth print-access-token生成。用于从API Hub获取API规范。
- param service_account_json:
服务账户配置以JSON字符串形式提供。 如果未使用默认服务凭证则为必填项。它用于创建API Hub客户端并从API Hub获取API规范。
- param apihub_client:
可选的定制API Hub客户端。
- param name:
工具集的名称。可选。
- param description:
工具集的描述。可选。
- param auth_scheme:
适用于工具集中所有工具的认证方案。
- param auth_credential:
适用于工具集中所有工具的认证凭证。
- param lazy_load_spec:
如果为True,规范将在需要时延迟加载。 否则,规范将立即加载,工具将在初始化期间生成。
- get_tool(name)¶
根据名称检索特定工具。
- Return type:
可选[RestApiTool]
示例:
` apihub_tool = apihub_toolset.get_tool('my_tool') `- Parameters:
name – 要检索的工具名称。
- Returns:
返回指定名称的工具,如果不存在则返回None。
- get_tools()¶
检索所有可用的工具。
- Return type:
List[RestApiTool]- Returns:
所有可用的RestApiTool对象列表。
- pydantic model google.adk.tools.AuthToolArguments¶
基类:
BaseModel特殊长时间运行函数工具所使用的参数
请求终端用户凭证。
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)¶
基类:
ABC所有工具的基础类。
-
description:
str¶ 该工具的说明。
-
is_long_running:
bool= False¶ 该工具是否为长时间运行的操作,通常先返回一个资源ID,稍后再完成操作。
-
name:
str¶ 工具的名称。
- async process_llm_request(*, tool_context, llm_request)¶
处理该工具发出的LLM请求。
使用场景: - 最常见的用途是将此工具添加到LLM请求中。 - 某些工具可能只是在LLM请求发出前进行预处理。
- Return type:
None- Parameters:
tool_context – 工具的上下文。
llm_request – 外发的LLM请求,此方法可修改。
- async run_async(*, args, tool_context)¶
使用给定的参数和上下文运行该工具。
注意 :rtype:
Any如果此工具需要在客户端运行,则为必填项。
否则可以跳过,例如对于Gemini内置的GoogleSearch工具。
- Parameters:
args – 由LLM填充的参数。
ctx – 工具的上下文。
- Returns:
运行该工具的结果。
-
description:
- class google.adk.tools.ExampleTool(examples)¶
基类:
BaseTool一个向LLM请求添加(少量示例)示例的工具。
- examples¶
要添加到LLM请求中的示例。
- async process_llm_request(*, tool_context, llm_request)¶
处理该工具发出的LLM请求。
使用场景: - 最常见的用途是将此工具添加到LLM请求中。 - 某些工具可能只是在LLM请求发出前进行预处理。
- Return type:
None- Parameters:
tool_context – 工具的上下文。
llm_request – 外发的LLM请求,该方法可修改此请求。
- class google.adk.tools.FunctionTool(func)¶
基类:
BaseTool一个封装用户自定义Python函数的工具。
- func¶
要包装的函数。
- async run_async(*, args, tool_context)¶
使用给定的参数和上下文运行该工具。
注意 :rtype:
Any如果此工具需要在客户端运行,则为必填项。
否则可以跳过,例如对于Gemini内置的GoogleSearch工具。
- Parameters:
args – 由LLM填充的参数。
ctx – 工具的上下文。
- Returns:
运行该工具的结果。
- class google.adk.tools.LongRunningFunctionTool(func)¶
基础类:
FunctionTool一个异步返回结果的函数工具。
该工具用于执行可能需要较长时间才能完成的长时间运行操作。框架将调用该函数。一旦函数返回,响应将异步返回给框架,由function_call_id标识。
示例:
`python tool = LongRunningFunctionTool(a_long_running_function) `- is_long_running¶
该工具是否为长期运行的操作。
- class google.adk.tools.ToolContext(invocation_context, *, function_call_id=None, event_actions=None)¶
基类:
CallbackContext该工具的上下文。
该类提供了工具调用的上下文环境,包括访问调用上下文、函数调用ID、事件操作和认证响应。它还提供了请求凭证、获取认证响应、列出工件和搜索内存的方法。
- invocation_context¶
工具的调用上下文。
- function_call_id¶
当前工具调用的函数调用ID。该ID由LLM在函数调用事件中返回,用于标识一个函数调用。如果LLM未返回此ID,ADK将为其分配一个。该ID用于将函数调用响应映射到原始函数调用。
- event_actions¶
当前工具调用的事件操作。
- get_auth_response(auth_config)¶
- Return type:
AuthCredential
- list_artifacts()¶
列出附加到当前会话的工件文件名。
- Return type:
list[str]
- request_credential(auth_config)¶
- Return type:
None
- search_memory(query)¶
搜索当前用户的记忆。
- Return type:
SearchMemoryResponse
- class google.adk.tools.VertexAiSearchTool(*, data_store_id=None, search_engine_id=None)¶
基类:
BaseTool一个使用Vertex AI搜索的内置工具。
- data_store_id¶
Vertex AI搜索数据存储资源的ID。
- search_engine_id¶
Vertex AI搜索引擎资源ID。
初始化Vertex AI搜索工具。
- Parameters:
data_store_id – Vertex AI 搜索数据存储资源的 ID,格式为 "projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}"。
search_engine_id – Vertex AI搜索引擎资源ID,格式为"projects/{project}/locations/{location}/collections/{collection}/engines/{engine}"。
- Raises:
ValueError - 如果既未指定data_store_id也未指定search_engine_id
或两者都指定了。 –
- async process_llm_request(*, tool_context, llm_request)¶
处理该工具发出的LLM请求。
使用场景: - 最常见的用途是将此工具添加到LLM请求中。 - 某些工具可能只是在LLM请求发出前进行预处理。
- Return type:
None- Parameters:
tool_context – 工具的上下文。
llm_request – 外发的LLM请求,此方法可修改。
- google.adk.tools.exit_loop(tool_context)¶
退出循环。
仅在收到指示时调用此函数。
- google.adk.tools.transfer_to_agent(agent_name, tool_context)¶
将问题转交给另一个智能体。