diff --git a/tests/unit/vertexai/genai/replays/test_append_agent_engine_a2a_task_events.py b/tests/unit/vertexai/genai/replays/test_append_agent_engine_a2a_task_events.py new file mode 100644 index 0000000000..b11cb325f8 --- /dev/null +++ b/tests/unit/vertexai/genai/replays/test_append_agent_engine_a2a_task_events.py @@ -0,0 +1,59 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from tests.unit.vertexai.genai.replays import pytest_helper +from vertexai._genai import types + + +def test_append_simple_a2a_task_events(client): + # Use the autopush environment. + client._api_client._http_options.base_url = ( + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com/" + ) + agent_engine = client.agent_engines.create() + assert isinstance(agent_engine, types.AgentEngine) + assert isinstance(agent_engine.api_resource, types.ReasoningEngine) + # Use the internal API version for internal API access. + client._api_client._http_options.api_version = "internal" + task = client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task123", + context_id="context123", + ) + assert isinstance(task, types.A2aTask) + + client.agent_engines.a2a_tasks.events.append( + name=task.name, + task_events=[ + types.TaskEvent( + event_data=types.TaskEventData( + metadata_change=types.TaskMetadataChange( + new_metadata={"key1": "value1"} + ) + ), + event_sequence_number=1, + ) + ], + ) + + # Clean up resources. + client.agent_engines.delete(name=agent_engine.api_resource.name, force=True) + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), +) diff --git a/tests/unit/vertexai/genai/replays/test_create_agent_engine_a2a_task.py b/tests/unit/vertexai/genai/replays/test_create_agent_engine_a2a_task.py new file mode 100644 index 0000000000..51ab2b1129 --- /dev/null +++ b/tests/unit/vertexai/genai/replays/test_create_agent_engine_a2a_task.py @@ -0,0 +1,50 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from tests.unit.vertexai.genai.replays import pytest_helper +from vertexai._genai import types + + +def test_create_simple_a2a_task(client): + # Use the autopush environment. + client._api_client._http_options.base_url = ( + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com/" + ) + agent_engine = client.agent_engines.create() + assert isinstance(agent_engine, types.AgentEngine) + assert isinstance(agent_engine.api_resource, types.ReasoningEngine) + # Use the internal API version for internal API access. + client._api_client._http_options.api_version = "internal" + + task = client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task123", + context_id="context123", + ) + + assert isinstance(task, types.A2aTask) + assert task.name == f"{agent_engine.api_resource.name}/a2aTasks/task123" + assert task.context_id == "context123" + assert task.state == types.State.SUBMITTED + + # Clean up resources. + client.agent_engines.delete(name=agent_engine.api_resource.name, force=True) + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), +) diff --git a/tests/unit/vertexai/genai/replays/test_get_agent_engine_a2a_task.py b/tests/unit/vertexai/genai/replays/test_get_agent_engine_a2a_task.py new file mode 100644 index 0000000000..bb291885af --- /dev/null +++ b/tests/unit/vertexai/genai/replays/test_get_agent_engine_a2a_task.py @@ -0,0 +1,54 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from tests.unit.vertexai.genai.replays import pytest_helper +from vertexai._genai import types + + +def test_get_a2a_task(client): + # Use the autopush environment. + client._api_client._http_options.base_url = ( + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com/" + ) + agent_engine = client.agent_engines.create() + assert isinstance(agent_engine, types.AgentEngine) + assert isinstance(agent_engine.api_resource, types.ReasoningEngine) + # Use the internal API version for internal API access. + client._api_client._http_options.api_version = "internal" + + created_task = client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task123", + context_id="context123", + ) + assert isinstance(created_task, types.A2aTask) + + task = client.agent_engines.a2a_tasks.get( + name=created_task.name, + ) + assert isinstance(task, types.A2aTask) + assert task.name == f"{agent_engine.api_resource.name}/a2aTasks/task123" + assert task.context_id == "context123" + assert task.state == types.State.SUBMITTED + + # Clean up resources. + client.agent_engines.delete(name=agent_engine.api_resource.name, force=True) + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), +) diff --git a/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_task_events.py b/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_task_events.py new file mode 100644 index 0000000000..650209d4bf --- /dev/null +++ b/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_task_events.py @@ -0,0 +1,91 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from tests.unit.vertexai.genai.replays import pytest_helper +from vertexai._genai import types + + +def test_list_simple_a2a_task_events(client): + # Use the autopush environment. + client._api_client._http_options.base_url = ( + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com/" + ) + agent_engine = client.agent_engines.create() + assert isinstance(agent_engine, types.AgentEngine) + assert isinstance(agent_engine.api_resource, types.ReasoningEngine) + # Use the internal API version for internal API access. + client._api_client._http_options.api_version = "internal" + task = client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task999", + context_id="context999", + ) + assert isinstance(task, types.A2aTask) + + events = list( + client.agent_engines.a2a_tasks.events.list( + name=task.name, + ) + ) + assert len(events) == 1 + assert events[0].event_data.state_change.new_state == "SUBMITTED" + + client.agent_engines.a2a_tasks.events.append( + name=task.name, + task_events=[ + types.TaskEvent( + event_data=types.TaskEventData( + metadata_change=types.TaskMetadataChange( + new_metadata={"key1": "value1"} + ) + ), + event_sequence_number=1, + ), + types.TaskEvent( + event_data=types.TaskEventData( + metadata_change=types.TaskMetadataChange( + new_metadata={"key2": "value2"} + ) + ), + event_sequence_number=2, + ), + ], + ) + + result = list( + client.agent_engines.a2a_tasks.events.list( + name=task.name, + config=types.ListAgentEngineTaskEventsConfig( + order_by="create_time desc", + ), + ) + ) + + assert len(result) == 3 + assert result[0].event_sequence_number == 2 + assert result[0].event_data.metadata_change.new_metadata == {"key2": "value2"} + assert result[1].event_sequence_number == 1 + assert result[1].event_data.metadata_change.new_metadata == {"key1": "value1"} + assert result[2].event_data.state_change.new_state == "SUBMITTED" + + # Clean up resources. + client.agent_engines.delete(name=agent_engine.api_resource.name, force=True) + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), +) diff --git a/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_tasks.py b/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_tasks.py new file mode 100644 index 0000000000..c884d04765 --- /dev/null +++ b/tests/unit/vertexai/genai/replays/test_list_agent_engine_a2a_tasks.py @@ -0,0 +1,68 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from tests.unit.vertexai.genai.replays import pytest_helper +from vertexai._genai import types + + +def test_list_a2a_tasks(client): + # Use the autopush environment. + client._api_client._http_options.base_url = ( + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com/" + ) + agent_engine = client.agent_engines.create() + assert isinstance(agent_engine, types.AgentEngine) + assert isinstance(agent_engine.api_resource, types.ReasoningEngine) + # Use the internal API version for internal API access. + client._api_client._http_options.api_version = "internal" + + assert not list( + client.agent_engines.a2a_tasks.list( + name=agent_engine.api_resource.name, + ) + ) + client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task123", + context_id="context123", + ) + client.agent_engines.a2a_tasks.create( + name=agent_engine.api_resource.name, + a2a_task_id="task456", + context_id="context456", + ) + a2a_tasks_list = client.agent_engines.a2a_tasks.list( + name=agent_engine.api_resource.name, + config=types.ListAgentEngineTasksConfig( + page_size=1, + order_by="create_time asc", + ), + ) + assert len(a2a_tasks_list) == 1 + assert isinstance(a2a_tasks_list[0], types.A2aTask) + assert a2a_tasks_list[0].name == ( + f"{agent_engine.api_resource.name}/a2aTasks/task123" + ) + assert a2a_tasks_list[0].context_id == "context123" + + # Clean up resources. + agent_engine.delete(force=True) + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), +) diff --git a/vertexai/_genai/a2a_task_events.py b/vertexai/_genai/a2a_task_events.py new file mode 100644 index 0000000000..10bb234204 --- /dev/null +++ b/vertexai/_genai/a2a_task_events.py @@ -0,0 +1,417 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +import functools +import json +import logging +from typing import Any, Iterator, Optional, Union +from urllib.parse import urlencode + +from google.genai import _api_module +from google.genai import _common +from google.genai._common import get_value_by_path as getv +from google.genai._common import set_value_by_path as setv +from google.genai.pagers import Pager + +from . import types + + +logger = logging.getLogger("vertexai_genai.a2ataskevents") + +logger.setLevel(logging.INFO) + + +def _AppendAgentEngineTaskEventRequestParameters_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + if getv(from_object, ["task_events"]) is not None: + setv( + to_object, + ["taskEvents"], + [item for item in getv(from_object, ["task_events"])], + ) + + if getv(from_object, ["config"]) is not None: + setv(to_object, ["config"], getv(from_object, ["config"])) + + return to_object + + +def _AppendAgentEngineTaskEventResponse_from_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + + return to_object + + +def _ListAgentEngineTaskEventsConfig_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + + if getv(from_object, ["page_size"]) is not None: + setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"])) + + if getv(from_object, ["page_token"]) is not None: + setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"])) + + if getv(from_object, ["filter"]) is not None: + setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"])) + + if getv(from_object, ["order_by"]) is not None: + setv(parent_object, ["_query", "orderBy"], getv(from_object, ["order_by"])) + + return to_object + + +def _ListAgentEngineTaskEventsRequestParameters_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + if getv(from_object, ["config"]) is not None: + setv( + to_object, + ["config"], + _ListAgentEngineTaskEventsConfig_to_vertex( + getv(from_object, ["config"]), to_object + ), + ) + + return to_object + + +class A2aTaskEvents(_api_module.BaseModule): + + def append( + self, + *, + name: str, + task_events: list[types.TaskEventOrDict], + config: Optional[types.AppendAgentEngineTaskEventConfigOrDict] = None, + ) -> types.AppendAgentEngineTaskEventResponse: + """ + Creates a new task in the Agent Engine. + + Args: + name (str): Required. The name of the Agent Engine to create the task under. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + config (CreateAgentEngineTaskConfig): + Optional. Additional configurations for creating the Agent Engine task. + + Returns: + AgentEngineTaskOperation: The operation for creating the Agent Engine task. + + """ + + parameter_model = types._AppendAgentEngineTaskEventRequestParameters( + name=name, + task_events=task_events, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _AppendAgentEngineTaskEventRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}:appendEvents".format_map(request_url_dict) + else: + path = "{name}:appendEvents" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("post", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + if self._api_client.vertexai: + response_dict = _AppendAgentEngineTaskEventResponse_from_vertex( + response_dict + ) + + return_value = types.AppendAgentEngineTaskEventResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + def _list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTaskEventsConfigOrDict] = None, + ) -> types.ListAgentEngineTaskEventsResponse: + """ + Lists Agent Engine tasks. + + Args: + name (str): Required. The name of the Agent Engine to list tasks for. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/a2aTasks/{a2a_task_id}/events`. + config (ListAgentEngineTaskEventsConfig): + Optional. Additional configurations for listing the Agent Engine tasks. + + Returns: + ListAgentEngineTaskEventsResponse: The requested Agent Engine tasks. + + """ + + parameter_model = types._ListAgentEngineTaskEventsRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _ListAgentEngineTaskEventsRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/events".format_map(request_url_dict) + else: + path = "{name}/events" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("get", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.ListAgentEngineTaskEventsResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + """Task events.""" + + def list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTaskEventsConfigOrDict] = None, + ) -> Iterator[types.TaskEvent]: + """Lists the A2A tasks of an Agent Engine. + + Args: + name (str): + Required. The name of the agent engine to list tasks for. + config (List): + Optional. The configuration for the tasks to list. + + Returns: + Iterable[TaskEvent]: An iterable of Task events. + """ + + return Pager( + "taskEvents", + functools.partial(self._list, name=name), + self._list(name=name, config=config), + config, + ) + + +class AsyncA2aTaskEvents(_api_module.BaseModule): + + async def append( + self, + *, + name: str, + task_events: list[types.TaskEventOrDict], + config: Optional[types.AppendAgentEngineTaskEventConfigOrDict] = None, + ) -> types.AppendAgentEngineTaskEventResponse: + """ + Creates a new task in the Agent Engine. + + Args: + name (str): Required. The name of the Agent Engine to create the task under. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + config (CreateAgentEngineTaskConfig): + Optional. Additional configurations for creating the Agent Engine task. + + Returns: + AgentEngineTaskOperation: The operation for creating the Agent Engine task. + + """ + + parameter_model = types._AppendAgentEngineTaskEventRequestParameters( + name=name, + task_events=task_events, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _AppendAgentEngineTaskEventRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}:appendEvents".format_map(request_url_dict) + else: + path = "{name}:appendEvents" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "post", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + if self._api_client.vertexai: + response_dict = _AppendAgentEngineTaskEventResponse_from_vertex( + response_dict + ) + + return_value = types.AppendAgentEngineTaskEventResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + async def _list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTaskEventsConfigOrDict] = None, + ) -> types.ListAgentEngineTaskEventsResponse: + """ + Lists Agent Engine tasks. + + Args: + name (str): Required. The name of the Agent Engine to list tasks for. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/a2aTasks/{a2a_task_id}/events`. + config (ListAgentEngineTaskEventsConfig): + Optional. Additional configurations for listing the Agent Engine tasks. + + Returns: + ListAgentEngineTaskEventsResponse: The requested Agent Engine tasks. + + """ + + parameter_model = types._ListAgentEngineTaskEventsRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _ListAgentEngineTaskEventsRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/events".format_map(request_url_dict) + else: + path = "{name}/events" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "get", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.ListAgentEngineTaskEventsResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value diff --git a/vertexai/_genai/a2a_tasks.py b/vertexai/_genai/a2a_tasks.py new file mode 100644 index 0000000000..9f3b077e84 --- /dev/null +++ b/vertexai/_genai/a2a_tasks.py @@ -0,0 +1,573 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +import functools +import importlib +import json +import logging +import typing +from typing import Any, Iterator, Optional, Union +from urllib.parse import urlencode + +from google.genai import _api_module +from google.genai import _common +from google.genai._common import get_value_by_path as getv +from google.genai._common import set_value_by_path as setv +from google.genai.pagers import Pager + +from . import types + +if typing.TYPE_CHECKING: + from . import a2a_task_events as a2a_task_events_module + + _ = a2a_task_events_module + + +logger = logging.getLogger("vertexai_genai.a2atasks") + +logger.setLevel(logging.INFO) + + +def _CreateAgentEngineTaskRequestParameters_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + if getv(from_object, ["a2a_task_id"]) is not None: + setv(to_object, ["_query", "a2a_task_id"], getv(from_object, ["a2a_task_id"])) + + if getv(from_object, ["context_id"]) is not None: + setv(to_object, ["contextId"], getv(from_object, ["context_id"])) + + if getv(from_object, ["config"]) is not None: + setv(to_object, ["config"], getv(from_object, ["config"])) + + return to_object + + +def _GetAgentEngineTaskRequestParameters_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + if getv(from_object, ["config"]) is not None: + setv(to_object, ["config"], getv(from_object, ["config"])) + + return to_object + + +def _ListAgentEngineTasksConfig_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + + if getv(from_object, ["page_size"]) is not None: + setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"])) + + if getv(from_object, ["page_token"]) is not None: + setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"])) + + if getv(from_object, ["filter"]) is not None: + setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"])) + + if getv(from_object, ["order_by"]) is not None: + setv(parent_object, ["_query", "orderBy"], getv(from_object, ["order_by"])) + + return to_object + + +def _ListAgentEngineTasksRequestParameters_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + if getv(from_object, ["config"]) is not None: + setv( + to_object, + ["config"], + _ListAgentEngineTasksConfig_to_vertex( + getv(from_object, ["config"]), to_object + ), + ) + + return to_object + + +class A2aTasks(_api_module.BaseModule): + + def get( + self, + *, + name: str, + config: Optional[types.GetAgentEngineTaskConfigOrDict] = None, + ) -> types.A2aTask: + """ + Gets an agent engine task. + + Args: + name (str): Required. The name of the Agent Engine task to get. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/a2aTasks/{task_id}`. + config (GetAgentEngineTaskConfig): + Optional. Additional configurations for getting the Agent Engine task. + + Returns: + AgentEngineTask: The requested Agent Engine task. + + """ + + parameter_model = types._GetAgentEngineTaskRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _GetAgentEngineTaskRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("get", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.A2aTask._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + def _list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTasksConfigOrDict] = None, + ) -> types.ListAgentEngineTasksResponse: + """ + Lists Agent Engine tasks. + + Args: + name (str): Required. The name of the Agent Engine to list tasks for. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + config (ListAgentEngineTasksConfig): + Optional. Additional configurations for listing the Agent Engine tasks. + + Returns: + ListAgentEngineTasksResponse: The requested Agent Engine tasks. + + """ + + parameter_model = types._ListAgentEngineTasksRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _ListAgentEngineTasksRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/a2aTasks".format_map(request_url_dict) + else: + path = "{name}/a2aTasks" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("get", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.ListAgentEngineTasksResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + def create( + self, + *, + name: str, + a2a_task_id: str, + context_id: str, + config: Optional[types.CreateAgentEngineTaskConfigOrDict] = None, + ) -> types.A2aTask: + """ + Creates a new task in the Agent Engine. + + Args: + name (str): Required. The name of the Agent Engine to create the task under. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + a2a_task_id (str): Required. The user ID of the task. + context_id (str): Required. The ID of the context to use for the task. + config (CreateAgentEngineTaskConfig): + Optional. Additional configurations for creating the Agent Engine task. + + Returns: + AgentEngineTaskOperation: The operation for creating the Agent Engine task. + + """ + + parameter_model = types._CreateAgentEngineTaskRequestParameters( + name=name, + a2a_task_id=a2a_task_id, + context_id=context_id, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _CreateAgentEngineTaskRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/a2aTasks".format_map(request_url_dict) + else: + path = "{name}/a2aTasks" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("post", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.A2aTask._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + _events = None + + def list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTasksConfigOrDict] = None, + ) -> Iterator[types.A2aTask]: + """Lists the A2A tasks of an Agent Engine. + + Args: + name (str): + Required. The name of the agent engine to list tasks for. + config (List): + Optional. The configuration for the tasks to list. + + Returns: + Iterable[A2aTask]: An iterable of A2A tasks. + """ + + return Pager( + "a2aTasks", + functools.partial(self._list, name=name), + self._list(name=name, config=config), + config, + ) + + @property + def events(self) -> "a2a_task_events_module.A2aTaskEvents": + if self._events is None: + try: + # We need to lazy load the events module to handle the + # possibility of ImportError when dependencies are not installed. + self._events = importlib.import_module(".a2a_task_events", __package__) + except ImportError as e: + raise ImportError( + "The 'agent_engines.a2a_tasks.events' module requires additional " + "packages. Please install them using pip install " + "google-cloud-aiplatform[agent_engines]" + ) from e + return self._events.A2aTaskEvents(self._api_client) # type: ignore[no-any-return] + + +class AsyncA2aTasks(_api_module.BaseModule): + + async def get( + self, + *, + name: str, + config: Optional[types.GetAgentEngineTaskConfigOrDict] = None, + ) -> types.A2aTask: + """ + Gets an agent engine task. + + Args: + name (str): Required. The name of the Agent Engine task to get. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/a2aTasks/{task_id}`. + config (GetAgentEngineTaskConfig): + Optional. Additional configurations for getting the Agent Engine task. + + Returns: + AgentEngineTask: The requested Agent Engine task. + + """ + + parameter_model = types._GetAgentEngineTaskRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _GetAgentEngineTaskRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "get", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.A2aTask._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + async def _list( + self, + *, + name: str, + config: Optional[types.ListAgentEngineTasksConfigOrDict] = None, + ) -> types.ListAgentEngineTasksResponse: + """ + Lists Agent Engine tasks. + + Args: + name (str): Required. The name of the Agent Engine to list tasks for. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + config (ListAgentEngineTasksConfig): + Optional. Additional configurations for listing the Agent Engine tasks. + + Returns: + ListAgentEngineTasksResponse: The requested Agent Engine tasks. + + """ + + parameter_model = types._ListAgentEngineTasksRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _ListAgentEngineTasksRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/a2aTasks".format_map(request_url_dict) + else: + path = "{name}/a2aTasks" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "get", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.ListAgentEngineTasksResponse._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value + + async def create( + self, + *, + name: str, + a2a_task_id: str, + context_id: str, + config: Optional[types.CreateAgentEngineTaskConfigOrDict] = None, + ) -> types.A2aTask: + """ + Creates a new task in the Agent Engine. + + Args: + name (str): Required. The name of the Agent Engine to create the task under. Format: + `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`. + a2a_task_id (str): Required. The user ID of the task. + context_id (str): Required. The ID of the context to use for the task. + config (CreateAgentEngineTaskConfig): + Optional. Additional configurations for creating the Agent Engine task. + + Returns: + AgentEngineTaskOperation: The operation for creating the Agent Engine task. + + """ + + parameter_model = types._CreateAgentEngineTaskRequestParameters( + name=name, + a2a_task_id=a2a_task_id, + context_id=context_id, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError("This method is only supported in the Vertex AI client.") + else: + request_dict = _CreateAgentEngineTaskRequestParameters_to_vertex( + parameter_model + ) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}/a2aTasks".format_map(request_url_dict) + else: + path = "{name}/a2aTasks" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "post", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.A2aTask._from_response( + response=response_dict, kwargs=parameter_model.model_dump() + ) + + self._api_client._verify_response(return_value) + return return_value diff --git a/vertexai/_genai/agent_engines.py b/vertexai/_genai/agent_engines.py index 92168e0865..7154c9c670 100644 --- a/vertexai/_genai/agent_engines.py +++ b/vertexai/_genai/agent_engines.py @@ -37,9 +37,11 @@ if typing.TYPE_CHECKING: from . import sessions as sessions_module from . import memories as memories_module + from . import a2a_tasks as a2a_tasks_module _ = sessions_module __ = memories_module + ___ = a2a_tasks_module logger = logging.getLogger("vertexai_genai.agentengines") @@ -706,10 +708,26 @@ def _update( self._api_client._verify_response(return_value) return return_value + _a2a_tasks = None _memories = None _sandboxes = None _sessions = None + @property + def a2a_tasks(self) -> "a2a_tasks_module.A2aTasks": + if self._a2a_tasks is None: + try: + # We need to lazy load the a2a_tasks module to handle the + # possibility of ImportError when dependencies are not installed. + self._a2a_tasks = importlib.import_module(".a2a_tasks", __package__) + except ImportError as e: + raise ImportError( + "The 'agent_engines.a2a_tasks' module requires additional " + "packages. Please install them using pip install " + "google-cloud-aiplatform[agent_engines]" + ) from e + return self._a2a_tasks.A2aTasks(self._api_client) # type: ignore[no-any-return] + @property def memories(self) -> "memories_module.Memories": if self._memories is None: diff --git a/vertexai/_genai/types/__init__.py b/vertexai/_genai/types/__init__.py index 8b02bc222c..3702b63a9b 100644 --- a/vertexai/_genai/types/__init__.py +++ b/vertexai/_genai/types/__init__.py @@ -23,12 +23,14 @@ from . import evals from . import prompts from .common import _AppendAgentEngineSessionEventRequestParameters +from .common import _AppendAgentEngineTaskEventRequestParameters from .common import _AssembleDatasetParameters from .common import _AssessDatasetParameters from .common import _CreateAgentEngineMemoryRequestParameters from .common import _CreateAgentEngineRequestParameters from .common import _CreateAgentEngineSandboxRequestParameters from .common import _CreateAgentEngineSessionRequestParameters +from .common import _CreateAgentEngineTaskRequestParameters from .common import _CreateDatasetParameters from .common import _CreateDatasetVersionParameters from .common import _CreateEvaluationItemParameters @@ -58,6 +60,7 @@ from .common import _GetAgentEngineSandboxRequestParameters from .common import _GetAgentEngineSessionOperationParameters from .common import _GetAgentEngineSessionRequestParameters +from .common import _GetAgentEngineTaskRequestParameters from .common import _GetCustomJobParameters from .common import _GetCustomJobParameters from .common import _GetDatasetOperationParameters @@ -74,6 +77,8 @@ from .common import _ListAgentEngineSandboxesRequestParameters from .common import _ListAgentEngineSessionEventsRequestParameters from .common import _ListAgentEngineSessionsRequestParameters +from .common import _ListAgentEngineTaskEventsRequestParameters +from .common import _ListAgentEngineTasksRequestParameters from .common import _ListDatasetsRequestParameters from .common import _ListDatasetVersionsRequestParameters from .common import _ListMultimodalDatasetsRequestParameters @@ -89,6 +94,9 @@ from .common import _UpdateAgentEngineSessionRequestParameters from .common import _UpdateDatasetParameters from .common import _UpdateMultimodalDatasetParameters +from .common import A2aTask +from .common import A2aTaskDict +from .common import A2aTaskOrDict from .common import AcceleratorType from .common import AgentEngine from .common import AgentEngineConfig @@ -130,6 +138,12 @@ from .common import AppendAgentEngineSessionEventResponse from .common import AppendAgentEngineSessionEventResponseDict from .common import AppendAgentEngineSessionEventResponseOrDict +from .common import AppendAgentEngineTaskEventConfig +from .common import AppendAgentEngineTaskEventConfigDict +from .common import AppendAgentEngineTaskEventConfigOrDict +from .common import AppendAgentEngineTaskEventResponse +from .common import AppendAgentEngineTaskEventResponseDict +from .common import AppendAgentEngineTaskEventResponseOrDict from .common import AssembleDataset from .common import AssembleDatasetConfig from .common import AssembleDatasetConfigDict @@ -169,6 +183,9 @@ from .common import BleuResults from .common import BleuResultsDict from .common import BleuResultsOrDict +from .common import Blob +from .common import BlobDict +from .common import BlobOrDict from .common import CandidateResponse from .common import CandidateResponseDict from .common import CandidateResponseOrDict @@ -177,6 +194,9 @@ from .common import Chunk from .common import ChunkDict from .common import ChunkOrDict +from .common import CodeExecutionResult +from .common import CodeExecutionResultDict +from .common import CodeExecutionResultOrDict from .common import CometResult from .common import CometResultDict from .common import CometResultOrDict @@ -202,6 +222,9 @@ from .common import CreateAgentEngineSessionConfig from .common import CreateAgentEngineSessionConfigDict from .common import CreateAgentEngineSessionConfigOrDict +from .common import CreateAgentEngineTaskConfig +from .common import CreateAgentEngineTaskConfigDict +from .common import CreateAgentEngineTaskConfigOrDict from .common import CreateDatasetConfig from .common import CreateDatasetConfigDict from .common import CreateDatasetConfigOrDict @@ -392,12 +415,24 @@ from .common import ExactMatchSpec from .common import ExactMatchSpecDict from .common import ExactMatchSpecOrDict +from .common import ExecutableCode +from .common import ExecutableCodeDict +from .common import ExecutableCodeOrDict from .common import ExecuteCodeAgentEngineSandboxConfig from .common import ExecuteCodeAgentEngineSandboxConfigDict from .common import ExecuteCodeAgentEngineSandboxConfigOrDict from .common import ExecuteSandboxEnvironmentResponse from .common import ExecuteSandboxEnvironmentResponseDict from .common import ExecuteSandboxEnvironmentResponseOrDict +from .common import FileData +from .common import FileDataDict +from .common import FileDataOrDict +from .common import FunctionCall +from .common import FunctionCallDict +from .common import FunctionCallOrDict +from .common import FunctionResponse +from .common import FunctionResponseDict +from .common import FunctionResponseOrDict from .common import GcsSource from .common import GcsSourceDict from .common import GcsSourceOrDict @@ -456,6 +491,9 @@ from .common import GetAgentEngineSessionConfig from .common import GetAgentEngineSessionConfigDict from .common import GetAgentEngineSessionConfigOrDict +from .common import GetAgentEngineTaskConfig +from .common import GetAgentEngineTaskConfigDict +from .common import GetAgentEngineTaskConfigOrDict from .common import GetDatasetOperationConfig from .common import GetDatasetOperationConfigDict from .common import GetDatasetOperationConfigOrDict @@ -508,6 +546,18 @@ from .common import ListAgentEngineSessionsConfig from .common import ListAgentEngineSessionsConfigDict from .common import ListAgentEngineSessionsConfigOrDict +from .common import ListAgentEngineTaskEventsConfig +from .common import ListAgentEngineTaskEventsConfigDict +from .common import ListAgentEngineTaskEventsConfigOrDict +from .common import ListAgentEngineTaskEventsResponse +from .common import ListAgentEngineTaskEventsResponseDict +from .common import ListAgentEngineTaskEventsResponseOrDict +from .common import ListAgentEngineTasksConfig +from .common import ListAgentEngineTasksConfigDict +from .common import ListAgentEngineTasksConfigOrDict +from .common import ListAgentEngineTasksResponse +from .common import ListAgentEngineTasksResponseDict +from .common import ListAgentEngineTasksResponseOrDict from .common import ListDatasetsResponse from .common import ListDatasetsResponseDict from .common import ListDatasetsResponseOrDict @@ -648,6 +698,7 @@ from .common import OptimizeResponseEndpointOrDict from .common import OptimizeResponseOrDict from .common import OptimizeTarget +from .common import Outcome from .common import PairwiseChoice from .common import PairwiseMetricInput from .common import PairwiseMetricInputDict @@ -659,6 +710,12 @@ from .common import PairwiseMetricResultDict from .common import PairwiseMetricResultOrDict from .common import ParsedResponseUnion +from .common import Part +from .common import PartDict +from .common import PartialArg +from .common import PartialArgDict +from .common import PartialArgOrDict +from .common import PartOrDict from .common import PointwiseMetricInput from .common import PointwiseMetricInputDict from .common import PointwiseMetricInputOrDict @@ -951,6 +1008,39 @@ from .common import SummaryMetric from .common import SummaryMetricDict from .common import SummaryMetricOrDict +from .common import TaskArtifact +from .common import TaskArtifactChange +from .common import TaskArtifactChangeDict +from .common import TaskArtifactChangeOrDict +from .common import TaskArtifactDict +from .common import TaskArtifactOrDict +from .common import TaskEvent +from .common import TaskEventData +from .common import TaskEventDataDict +from .common import TaskEventDataOrDict +from .common import TaskEventDict +from .common import TaskEventOrDict +from .common import TaskMessage +from .common import TaskMessageDict +from .common import TaskMessageOrDict +from .common import TaskMetadataChange +from .common import TaskMetadataChangeDict +from .common import TaskMetadataChangeOrDict +from .common import TaskOutput +from .common import TaskOutputChange +from .common import TaskOutputChangeDict +from .common import TaskOutputChangeOrDict +from .common import TaskOutputDict +from .common import TaskOutputOrDict +from .common import TaskStateChange +from .common import TaskStateChangeDict +from .common import TaskStateChangeOrDict +from .common import TaskStatusDetails +from .common import TaskStatusDetailsChange +from .common import TaskStatusDetailsChangeDict +from .common import TaskStatusDetailsChangeOrDict +from .common import TaskStatusDetailsDict +from .common import TaskStatusDetailsOrDict from .common import ToolCallValidInput from .common import ToolCallValidInputDict from .common import ToolCallValidInputOrDict @@ -1045,6 +1135,9 @@ from .common import VertexBaseConfig from .common import VertexBaseConfigDict from .common import VertexBaseConfigOrDict +from .common import VideoMetadata +from .common import VideoMetadataDict +from .common import VideoMetadataOrDict from .common import WinRateStats from .common import WinRateStatsDict from .common import WinRateStatsOrDict @@ -1053,6 +1146,93 @@ from .common import WorkerPoolSpecOrDict __all__ = [ + "GetAgentEngineTaskConfig", + "GetAgentEngineTaskConfigDict", + "GetAgentEngineTaskConfigOrDict", + "CodeExecutionResult", + "CodeExecutionResultDict", + "CodeExecutionResultOrDict", + "ExecutableCode", + "ExecutableCodeDict", + "ExecutableCodeOrDict", + "FileData", + "FileDataDict", + "FileDataOrDict", + "PartialArg", + "PartialArgDict", + "PartialArgOrDict", + "FunctionCall", + "FunctionCallDict", + "FunctionCallOrDict", + "FunctionResponse", + "FunctionResponseDict", + "FunctionResponseOrDict", + "Blob", + "BlobDict", + "BlobOrDict", + "VideoMetadata", + "VideoMetadataDict", + "VideoMetadataOrDict", + "Part", + "PartDict", + "PartOrDict", + "TaskArtifact", + "TaskArtifactDict", + "TaskArtifactOrDict", + "TaskOutput", + "TaskOutputDict", + "TaskOutputOrDict", + "TaskMessage", + "TaskMessageDict", + "TaskMessageOrDict", + "TaskStatusDetails", + "TaskStatusDetailsDict", + "TaskStatusDetailsOrDict", + "A2aTask", + "A2aTaskDict", + "A2aTaskOrDict", + "ListAgentEngineTasksConfig", + "ListAgentEngineTasksConfigDict", + "ListAgentEngineTasksConfigOrDict", + "ListAgentEngineTasksResponse", + "ListAgentEngineTasksResponseDict", + "ListAgentEngineTasksResponseOrDict", + "CreateAgentEngineTaskConfig", + "CreateAgentEngineTaskConfigDict", + "CreateAgentEngineTaskConfigOrDict", + "TaskMetadataChange", + "TaskMetadataChangeDict", + "TaskMetadataChangeOrDict", + "TaskArtifactChange", + "TaskArtifactChangeDict", + "TaskArtifactChangeOrDict", + "TaskOutputChange", + "TaskOutputChangeDict", + "TaskOutputChangeOrDict", + "TaskStateChange", + "TaskStateChangeDict", + "TaskStateChangeOrDict", + "TaskStatusDetailsChange", + "TaskStatusDetailsChangeDict", + "TaskStatusDetailsChangeOrDict", + "TaskEventData", + "TaskEventDataDict", + "TaskEventDataOrDict", + "TaskEvent", + "TaskEventDict", + "TaskEventOrDict", + "AppendAgentEngineTaskEventConfig", + "AppendAgentEngineTaskEventConfigDict", + "AppendAgentEngineTaskEventConfigOrDict", + "AppendAgentEngineTaskEventResponse", + "AppendAgentEngineTaskEventResponseDict", + "AppendAgentEngineTaskEventResponseOrDict", + "ListAgentEngineTaskEventsConfig", + "ListAgentEngineTaskEventsConfigDict", + "ListAgentEngineTaskEventsConfigOrDict", + "ListAgentEngineTaskEventsResponse", + "ListAgentEngineTaskEventsResponseDict", + "ListAgentEngineTaskEventsResponseOrDict", "CreateEvaluationItemConfig", "CreateEvaluationItemConfigDict", "CreateEvaluationItemConfigOrDict", @@ -1950,6 +2130,9 @@ "OptimizeJobConfig", "OptimizeJobConfigDict", "OptimizeJobConfigOrDict", + "State", + "Outcome", + "Language", "PairwiseChoice", "Strategy", "AcceleratorType", @@ -1959,9 +2142,7 @@ "AgentServerMode", "ManagedTopicEnum", "Operator", - "Language", "MachineConfig", - "State", "EvaluationItemType", "SamplingMethod", "RubricContentType", @@ -1993,6 +2174,11 @@ "MessageDict", "Importance", "ParsedResponseUnion", + "_GetAgentEngineTaskRequestParameters", + "_ListAgentEngineTasksRequestParameters", + "_CreateAgentEngineTaskRequestParameters", + "_AppendAgentEngineTaskEventRequestParameters", + "_ListAgentEngineTaskEventsRequestParameters", "_CreateEvaluationItemParameters", "_CreateEvaluationRunParameters", "_CreateEvaluationSetParameters", diff --git a/vertexai/_genai/types/common.py b/vertexai/_genai/types/common.py index cbe817f42e..55d0f3dbb3 100644 --- a/vertexai/_genai/types/common.py +++ b/vertexai/_genai/types/common.py @@ -91,6 +91,53 @@ def _camel_key_to_snake(message: Any) -> Any: MetricSubclass = TypeVar("MetricSubclass", bound="Metric") +class State(_common.CaseInSensitiveEnum): + """Output only. The state of the task. The state of a new task is SUBMITTED by default. The state of a task can only be updated via AppendA2aTaskEvents API.""" + + STATE_UNSPECIFIED = "STATE_UNSPECIFIED" + """Task state unspecified. Default value if not set.""" + SUBMITTED = "SUBMITTED" + """Task is submitted and waiting to be processed.""" + WORKING = "WORKING" + """Task is actively being processed.""" + COMPLETED = "COMPLETED" + """Task is finished.""" + CANCELLED = "CANCELLED" + """Task is cancelled.""" + FAILED = "FAILED" + """Task has failed.""" + REJECTED = "REJECTED" + """Task is rejected by the system.""" + INPUT_REQUIRED = "INPUT_REQUIRED" + """Task requires input from the user.""" + AUTH_REQUIRED = "AUTH_REQUIRED" + """Task requires auth (e.g. OAuth) from the user.""" + PAUSED = "PAUSED" + """Task is paused.""" + + +class Outcome(_common.CaseInSensitiveEnum): + """Outcome of the code execution.""" + + OUTCOME_UNSPECIFIED = "OUTCOME_UNSPECIFIED" + """Unspecified status. This value should not be used.""" + OUTCOME_OK = "OUTCOME_OK" + """Code execution completed successfully.""" + OUTCOME_FAILED = "OUTCOME_FAILED" + """Code execution finished but with a failure. `stderr` should contain the reason.""" + OUTCOME_DEADLINE_EXCEEDED = "OUTCOME_DEADLINE_EXCEEDED" + """Code execution ran for too long, and was cancelled. There may or may not be a partial output present.""" + + +class Language(_common.CaseInSensitiveEnum): + """Programming language of the `code`.""" + + LANGUAGE_UNSPECIFIED = "LANGUAGE_UNSPECIFIED" + """Unspecified language. This value should not be used.""" + PYTHON = "PYTHON" + """Python >= 3.10, with numpy and simpy available.""" + + class PairwiseChoice(_common.CaseInSensitiveEnum): """Output only. Pairwise metric choice.""" @@ -256,17 +303,6 @@ class Operator(_common.CaseInSensitiveEnum): """Less than.""" -class Language(_common.CaseInSensitiveEnum): - """The coding language supported in this environment.""" - - LANGUAGE_UNSPECIFIED = "LANGUAGE_UNSPECIFIED" - """The default value. This value is unused.""" - LANGUAGE_PYTHON = "LANGUAGE_PYTHON" - """The coding language is Python.""" - LANGUAGE_JAVASCRIPT = "LANGUAGE_JAVASCRIPT" - """The coding language is JavaScript.""" - - class MachineConfig(_common.CaseInSensitiveEnum): """The machine config of the code execution environment.""" @@ -276,23 +312,6 @@ class MachineConfig(_common.CaseInSensitiveEnum): """The default value: milligcu 4000, memory 4 Gib""" -class State(_common.CaseInSensitiveEnum): - """Output only. The runtime state of the SandboxEnvironment.""" - - STATE_UNSPECIFIED = "STATE_UNSPECIFIED" - """The default value. This value is unused.""" - STATE_PROVISIONING = "STATE_PROVISIONING" - """Runtime resources are being allocated for the sandbox environment.""" - STATE_RUNNING = "STATE_RUNNING" - """Sandbox runtime is ready for serving.""" - STATE_DEPROVISIONING = "STATE_DEPROVISIONING" - """Sandbox runtime is halted, performing tear down tasks.""" - STATE_TERMINATED = "STATE_TERMINATED" - """Sandbox has terminated with underlying runtime failure.""" - STATE_DELETED = "STATE_DELETED" - """Sandbox runtime has been deleted.""" - - class EvaluationItemType(_common.CaseInSensitiveEnum): """The type of the EvaluationItem.""" @@ -420,6 +439,1144 @@ class OptimizationMethod(_common.CaseInSensitiveEnum): """The data driven prompt optimizer designer for prompts from Android core API.""" +class GetAgentEngineTaskConfig(_common.BaseModel): + """Config for getting an Agent Engine Task.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class GetAgentEngineTaskConfigDict(TypedDict, total=False): + """Config for getting an Agent Engine Task.""" + + http_options: Optional[genai_types.HttpOptionsDict] + """Used to override HTTP request options.""" + + +GetAgentEngineTaskConfigOrDict = Union[ + GetAgentEngineTaskConfig, GetAgentEngineTaskConfigDict +] + + +class _GetAgentEngineTaskRequestParameters(_common.BaseModel): + """Parameters for getting an agent engine task.""" + + name: Optional[str] = Field( + default=None, description="""Name of the agent engine task.""" + ) + config: Optional[GetAgentEngineTaskConfig] = Field(default=None, description="""""") + + +class _GetAgentEngineTaskRequestParametersDict(TypedDict, total=False): + """Parameters for getting an agent engine task.""" + + name: Optional[str] + """Name of the agent engine task.""" + + config: Optional[GetAgentEngineTaskConfigDict] + """""" + + +_GetAgentEngineTaskRequestParametersOrDict = Union[ + _GetAgentEngineTaskRequestParameters, _GetAgentEngineTaskRequestParametersDict +] + + +class CodeExecutionResult(_common.BaseModel): + """Result of executing the [ExecutableCode]. Only generated when using the [CodeExecution] tool, and always follows a `part` containing the [ExecutableCode].""" + + outcome: Optional[Outcome] = Field( + default=None, description="""Required. Outcome of the code execution.""" + ) + output: Optional[str] = Field( + default=None, + description="""Optional. Contains stdout when code execution is successful, stderr or other description otherwise.""", + ) + + +class CodeExecutionResultDict(TypedDict, total=False): + """Result of executing the [ExecutableCode]. Only generated when using the [CodeExecution] tool, and always follows a `part` containing the [ExecutableCode].""" + + outcome: Optional[Outcome] + """Required. Outcome of the code execution.""" + + output: Optional[str] + """Optional. Contains stdout when code execution is successful, stderr or other description otherwise.""" + + +CodeExecutionResultOrDict = Union[CodeExecutionResult, CodeExecutionResultDict] + + +class ExecutableCode(_common.BaseModel): + """Code generated by the model that is meant to be executed, and the result returned to the model. Generated when using the [CodeExecution] tool, in which the code will be automatically executed, and a corresponding [CodeExecutionResult] will also be generated.""" + + code: Optional[str] = Field( + default=None, description="""Required. The code to be executed.""" + ) + language: Optional[Language] = Field( + default=None, description="""Required. Programming language of the `code`.""" + ) + + +class ExecutableCodeDict(TypedDict, total=False): + """Code generated by the model that is meant to be executed, and the result returned to the model. Generated when using the [CodeExecution] tool, in which the code will be automatically executed, and a corresponding [CodeExecutionResult] will also be generated.""" + + code: Optional[str] + """Required. The code to be executed.""" + + language: Optional[Language] + """Required. Programming language of the `code`.""" + + +ExecutableCodeOrDict = Union[ExecutableCode, ExecutableCodeDict] + + +class FileData(_common.BaseModel): + """URI based data.""" + + display_name: Optional[str] = Field( + default=None, + description="""Optional. Display name of the file data. Used to provide a label or filename to distinguish file datas. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.""", + ) + file_uri: Optional[str] = Field(default=None, description="""Required. URI.""") + mime_type: Optional[str] = Field( + default=None, + description="""Required. The IANA standard MIME type of the source data.""", + ) + + +class FileDataDict(TypedDict, total=False): + """URI based data.""" + + display_name: Optional[str] + """Optional. Display name of the file data. Used to provide a label or filename to distinguish file datas. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.""" + + file_uri: Optional[str] + """Required. URI.""" + + mime_type: Optional[str] + """Required. The IANA standard MIME type of the source data.""" + + +FileDataOrDict = Union[FileData, FileDataDict] + + +class PartialArg(_common.BaseModel): + """Partial argument value of the function call.""" + + null_value: Optional[Literal["NULL_VALUE"]] = Field( + default=None, description="""Optional. Represents a null value.""" + ) + number_value: Optional[float] = Field( + default=None, description="""Optional. Represents a double value.""" + ) + string_value: Optional[str] = Field( + default=None, description="""Optional. Represents a string value.""" + ) + bool_value: Optional[bool] = Field( + default=None, description="""Optional. Represents a boolean value.""" + ) + json_path: Optional[str] = Field( + default=None, + description="""Required. A JSON Path (RFC 9535) to the argument being streamed. https://datatracker.ietf.org/doc/html/rfc9535. e.g. "$.foo.bar[0].data".""", + ) + will_continue: Optional[bool] = Field( + default=None, + description="""Optional. Whether this is not the last part of the same json_path. If true, another PartialArg message for the current json_path is expected to follow.""", + ) + + +class PartialArgDict(TypedDict, total=False): + """Partial argument value of the function call.""" + + null_value: Optional[Literal["NULL_VALUE"]] + """Optional. Represents a null value.""" + + number_value: Optional[float] + """Optional. Represents a double value.""" + + string_value: Optional[str] + """Optional. Represents a string value.""" + + bool_value: Optional[bool] + """Optional. Represents a boolean value.""" + + json_path: Optional[str] + """Required. A JSON Path (RFC 9535) to the argument being streamed. https://datatracker.ietf.org/doc/html/rfc9535. e.g. "$.foo.bar[0].data".""" + + will_continue: Optional[bool] + """Optional. Whether this is not the last part of the same json_path. If true, another PartialArg message for the current json_path is expected to follow.""" + + +PartialArgOrDict = Union[PartialArg, PartialArgDict] + + +class FunctionCall(_common.BaseModel): + """A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing the parameters and their values.""" + + args: Optional[dict[str, Any]] = Field( + default=None, + description="""Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.""", + ) + id: Optional[str] = Field( + default=None, + description="""Optional. The unique id of the function call. If populated, the client to execute the `function_call` and return the response with the matching `id`.""", + ) + name: Optional[str] = Field( + default=None, + description="""Optional. The name of the function to call. Matches [FunctionDeclaration.name].""", + ) + partial_args: Optional[list[PartialArg]] = Field( + default=None, + description="""Optional. The partial argument value of the function call. If provided, represents the arguments/fields that are streamed incrementally.""", + ) + will_continue: Optional[bool] = Field( + default=None, + description="""Optional. Whether this is the last part of the FunctionCall. If true, another partial message for the current FunctionCall is expected to follow.""", + ) + + +class FunctionCallDict(TypedDict, total=False): + """A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing the parameters and their values.""" + + args: Optional[dict[str, Any]] + """Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.""" + + id: Optional[str] + """Optional. The unique id of the function call. If populated, the client to execute the `function_call` and return the response with the matching `id`.""" + + name: Optional[str] + """Optional. The name of the function to call. Matches [FunctionDeclaration.name].""" + + partial_args: Optional[list[PartialArgDict]] + """Optional. The partial argument value of the function call. If provided, represents the arguments/fields that are streamed incrementally.""" + + will_continue: Optional[bool] + """Optional. Whether this is the last part of the FunctionCall. If true, another partial message for the current FunctionCall is expected to follow.""" + + +FunctionCallOrDict = Union[FunctionCall, FunctionCallDict] + + +class FunctionResponse(_common.BaseModel): + """The result output from a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall] made based on model prediction.""" + + id: Optional[str] = Field( + default=None, + description="""Optional. The id of the function call this response is for. Populated by the client to match the corresponding function call `id`.""", + ) + name: Optional[str] = Field( + default=None, + description="""Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].""", + ) + response: Optional[dict[str, Any]] = Field( + default=None, + 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.""", + ) + + +class FunctionResponseDict(TypedDict, total=False): + """The result output from a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall] made based on model prediction.""" + + id: Optional[str] + """Optional. The id of the function call this response is for. Populated by the client to match the corresponding function call `id`.""" + + name: Optional[str] + """Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].""" + + response: Optional[dict[str, Any]] + """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.""" + + +FunctionResponseOrDict = Union[FunctionResponse, FunctionResponseDict] + + +class Blob(_common.BaseModel): + """Content blob.""" + + data: Optional[bytes] = Field(default=None, description="""Required. Raw bytes.""") + display_name: Optional[str] = Field( + default=None, + description="""Optional. Display name of the blob. Used to provide a label or filename to distinguish blobs. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.""", + ) + mime_type: Optional[str] = Field( + default=None, + description="""Required. The IANA standard MIME type of the source data.""", + ) + + +class BlobDict(TypedDict, total=False): + """Content blob.""" + + data: Optional[bytes] + """Required. Raw bytes.""" + + display_name: Optional[str] + """Optional. Display name of the blob. Used to provide a label or filename to distinguish blobs. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.""" + + mime_type: Optional[str] + """Required. The IANA standard MIME type of the source data.""" + + +BlobOrDict = Union[Blob, BlobDict] + + +class VideoMetadata(_common.BaseModel): + """Metadata describes the input video content.""" + + end_offset: Optional[str] = Field( + default=None, description="""Optional. The end offset of the video.""" + ) + fps: Optional[float] = Field( + default=None, + description="""Optional. The frame rate of the video sent to the model. If not specified, the default value will be 1.0. The fps range is (0.0, 24.0].""", + ) + start_offset: Optional[str] = Field( + default=None, description="""Optional. The start offset of the video.""" + ) + + +class VideoMetadataDict(TypedDict, total=False): + """Metadata describes the input video content.""" + + end_offset: Optional[str] + """Optional. The end offset of the video.""" + + fps: Optional[float] + """Optional. The frame rate of the video sent to the model. If not specified, the default value will be 1.0. The fps range is (0.0, 24.0].""" + + start_offset: Optional[str] + """Optional. The start offset of the video.""" + + +VideoMetadataOrDict = Union[VideoMetadata, VideoMetadataDict] + + +class Part(_common.BaseModel): + """A datatype containing media that is part of a multi-part `Content` message. A `Part` consists of data which has an associated datatype. A `Part` can only contain one of the accepted types in `Part.data`. A `Part` must have a fixed IANA MIME type identifying the type and subtype of the media if `inline_data` or `file_data` field is filled with raw bytes.""" + + code_execution_result: Optional[CodeExecutionResult] = Field( + default=None, + description="""Optional. Result of executing the [ExecutableCode].""", + ) + executable_code: Optional[ExecutableCode] = Field( + default=None, + description="""Optional. Code generated by the model that is meant to be executed.""", + ) + file_data: Optional[FileData] = Field( + default=None, description="""Optional. URI based data.""" + ) + function_call: Optional[FunctionCall] = Field( + default=None, + description="""Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values.""", + ) + function_response: Optional[FunctionResponse] = Field( + default=None, + 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.""", + ) + inline_data: Optional[Blob] = Field( + default=None, description="""Optional. Inlined bytes data.""" + ) + text: Optional[str] = Field( + default=None, description="""Optional. Text part (can be code).""" + ) + thought: Optional[bool] = Field( + default=None, + description="""Optional. Indicates if the part is thought from the model.""", + ) + thought_signature: Optional[bytes] = Field( + default=None, + description="""Optional. An opaque signature for the thought so it can be reused in subsequent requests.""", + ) + video_metadata: Optional[VideoMetadata] = Field( + default=None, + description="""Optional. Video metadata. The metadata should only be specified while the video data is presented in inline_data or file_data.""", + ) + + +class PartDict(TypedDict, total=False): + """A datatype containing media that is part of a multi-part `Content` message. A `Part` consists of data which has an associated datatype. A `Part` can only contain one of the accepted types in `Part.data`. A `Part` must have a fixed IANA MIME type identifying the type and subtype of the media if `inline_data` or `file_data` field is filled with raw bytes.""" + + code_execution_result: Optional[CodeExecutionResultDict] + """Optional. Result of executing the [ExecutableCode].""" + + executable_code: Optional[ExecutableCodeDict] + """Optional. Code generated by the model that is meant to be executed.""" + + file_data: Optional[FileDataDict] + """Optional. URI based data.""" + + function_call: Optional[FunctionCallDict] + """Optional. A predicted [FunctionCall] returned from the model that contains a string representing the [FunctionDeclaration.name] with the parameters and their values.""" + + function_response: Optional[FunctionResponseDict] + """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.""" + + inline_data: Optional[BlobDict] + """Optional. Inlined bytes data.""" + + text: Optional[str] + """Optional. Text part (can be code).""" + + thought: Optional[bool] + """Optional. Indicates if the part is thought from the model.""" + + thought_signature: Optional[bytes] + """Optional. An opaque signature for the thought so it can be reused in subsequent requests.""" + + video_metadata: Optional[VideoMetadataDict] + """Optional. Video metadata. The metadata should only be specified while the video data is presented in inline_data or file_data.""" + + +PartOrDict = Union[Part, PartDict] + + +class TaskArtifact(_common.BaseModel): + """Represents a single artifact produced by a task. sample: artifacts: { artifact_id: "image-12345" name: "Generated Sunset Image" description: "A beautiful sunset over the mountains, generated by the user's request." parts: { inline_data: { mime_type: "image/png" data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAA=" } } }""" + + artifact_id: Optional[str] = Field( + default=None, + description="""Required. The unique identifier of the artifact within the task. This id is provided by the creator of the artifact.""", + ) + description: Optional[str] = Field( + default=None, + description="""Optional. A human readable description of the artifact.""", + ) + display_name: Optional[str] = Field( + default=None, + description="""Optional. The human-readable name of the artifact provided by the creator.""", + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Optional. Additional metadata for the artifact. For A2A, the URIs of the extensions that were used to produce this artifact will be stored here.""", + ) + parts: Optional[list[Part]] = Field( + default=None, description="""Required. The content of the artifact.""" + ) + + +class TaskArtifactDict(TypedDict, total=False): + """Represents a single artifact produced by a task. sample: artifacts: { artifact_id: "image-12345" name: "Generated Sunset Image" description: "A beautiful sunset over the mountains, generated by the user's request." parts: { inline_data: { mime_type: "image/png" data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAA=" } } }""" + + artifact_id: Optional[str] + """Required. The unique identifier of the artifact within the task. This id is provided by the creator of the artifact.""" + + description: Optional[str] + """Optional. A human readable description of the artifact.""" + + display_name: Optional[str] + """Optional. The human-readable name of the artifact provided by the creator.""" + + metadata: Optional[dict[str, Any]] + """Optional. Additional metadata for the artifact. For A2A, the URIs of the extensions that were used to produce this artifact will be stored here.""" + + parts: Optional[list[PartDict]] + """Required. The content of the artifact.""" + + +TaskArtifactOrDict = Union[TaskArtifact, TaskArtifactDict] + + +class TaskOutput(_common.BaseModel): + """Represents the final output of a task.""" + + artifacts: Optional[list[TaskArtifact]] = Field( + default=None, + description="""Optional. A list of artifacts (files, data) produced by the task.""", + ) + + +class TaskOutputDict(TypedDict, total=False): + """Represents the final output of a task.""" + + artifacts: Optional[list[TaskArtifactDict]] + """Optional. A list of artifacts (files, data) produced by the task.""" + + +TaskOutputOrDict = Union[TaskOutput, TaskOutputDict] + + +class TaskMessage(_common.BaseModel): + """Represents a single message in a conversation, compliant with the A2A specification.""" + + message_id: Optional[str] = Field( + default=None, description="""Required. The unique identifier of the message.""" + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Optional. A2A message may have extension_uris or reference_task_ids. They will be stored under metadata.""", + ) + parts: Optional[list[Part]] = Field( + default=None, description="""Required. The parts of the message.""" + ) + role: Optional[str] = Field( + default=None, + description="""Required. The role of the sender of the message. e.g. "user", "agent".""", + ) + + +class TaskMessageDict(TypedDict, total=False): + """Represents a single message in a conversation, compliant with the A2A specification.""" + + message_id: Optional[str] + """Required. The unique identifier of the message.""" + + metadata: Optional[dict[str, Any]] + """Optional. A2A message may have extension_uris or reference_task_ids. They will be stored under metadata.""" + + parts: Optional[list[PartDict]] + """Required. The parts of the message.""" + + role: Optional[str] + """Required. The role of the sender of the message. e.g. "user", "agent".""" + + +TaskMessageOrDict = Union[TaskMessage, TaskMessageDict] + + +class TaskStatusDetails(_common.BaseModel): + """Represents the additional status details of a task.""" + + task_message: Optional[TaskMessage] = Field( + default=None, + description="""Optional. The message associated with the single-turn interaction between the user and the agent or agent and agent.""", + ) + + +class TaskStatusDetailsDict(TypedDict, total=False): + """Represents the additional status details of a task.""" + + task_message: Optional[TaskMessageDict] + """Optional. The message associated with the single-turn interaction between the user and the agent or agent and agent.""" + + +TaskStatusDetailsOrDict = Union[TaskStatusDetails, TaskStatusDetailsDict] + + +class A2aTask(_common.BaseModel): + """A task.""" + + context_id: Optional[str] = Field( + default=None, + description="""Optional. A generic identifier for grouping related tasks (e.g., session_id, workflow_id).""", + ) + create_time: Optional[datetime.datetime] = Field( + default=None, description="""Output only. The creation timestamp of the task.""" + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, description="""Optional. Arbitrary, user-defined metadata.""" + ) + name: Optional[str] = Field( + default=None, + description="""Identifier. The resource name of the task. Format: `projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/a2aTasks/{a2a_task}`""", + ) + next_event_sequence_number: Optional[int] = Field( + default=None, + description="""Output only. The next event sequence number to be appended to the task. This value starts at 1 and is guaranteed to be monotonically increasing.""", + ) + output: Optional[TaskOutput] = Field( + default=None, description="""Optional. The final output of the task.""" + ) + state: Optional[State] = Field( + default=None, + description="""Output only. The state of the task. The state of a new task is SUBMITTED by default. The state of a task can only be updated via AppendA2aTaskEvents API.""", + ) + status_details: Optional[TaskStatusDetails] = Field( + default=None, description="""Optional. The status details of the task.""" + ) + update_time: Optional[datetime.datetime] = Field( + default=None, + description="""Output only. The last update timestamp of the task.""", + ) + + +class A2aTaskDict(TypedDict, total=False): + """A task.""" + + context_id: Optional[str] + """Optional. A generic identifier for grouping related tasks (e.g., session_id, workflow_id).""" + + create_time: Optional[datetime.datetime] + """Output only. The creation timestamp of the task.""" + + metadata: Optional[dict[str, Any]] + """Optional. Arbitrary, user-defined metadata.""" + + name: Optional[str] + """Identifier. The resource name of the task. Format: `projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/a2aTasks/{a2a_task}`""" + + next_event_sequence_number: Optional[int] + """Output only. The next event sequence number to be appended to the task. This value starts at 1 and is guaranteed to be monotonically increasing.""" + + output: Optional[TaskOutputDict] + """Optional. The final output of the task.""" + + state: Optional[State] + """Output only. The state of the task. The state of a new task is SUBMITTED by default. The state of a task can only be updated via AppendA2aTaskEvents API.""" + + status_details: Optional[TaskStatusDetailsDict] + """Optional. The status details of the task.""" + + update_time: Optional[datetime.datetime] + """Output only. The last update timestamp of the task.""" + + +A2aTaskOrDict = Union[A2aTask, A2aTaskDict] + + +class ListAgentEngineTasksConfig(_common.BaseModel): + """Config for listing agent engine tasks.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + page_size: Optional[int] = Field(default=None, description="""""") + page_token: Optional[str] = Field(default=None, description="""""") + filter: Optional[str] = Field( + default=None, + description="""An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported.""", + ) + order_by: Optional[str] = Field( + default=None, + description="""A comma-separated list of fields to order by, sorted in ascending order. + Use "desc" after a field name for descending. + If this field is omitted, the default ordering is `create_time` descending. + More detail in [AIP-132](https://google.aip.dev/132). + + Supported fields: + * `create_time` + * `update_time` + + Example: `create_time desc`.""", + ) + + +class ListAgentEngineTasksConfigDict(TypedDict, total=False): + """Config for listing agent engine tasks.""" + + http_options: Optional[genai_types.HttpOptionsDict] + """Used to override HTTP request options.""" + + page_size: Optional[int] + """""" + + page_token: Optional[str] + """""" + + filter: Optional[str] + """An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported.""" + + order_by: Optional[str] + """A comma-separated list of fields to order by, sorted in ascending order. + Use "desc" after a field name for descending. + If this field is omitted, the default ordering is `create_time` descending. + More detail in [AIP-132](https://google.aip.dev/132). + + Supported fields: + * `create_time` + * `update_time` + + Example: `create_time desc`.""" + + +ListAgentEngineTasksConfigOrDict = Union[ + ListAgentEngineTasksConfig, ListAgentEngineTasksConfigDict +] + + +class _ListAgentEngineTasksRequestParameters(_common.BaseModel): + """Parameters for listing agent engines.""" + + name: Optional[str] = Field( + default=None, description="""Name of the agent engine.""" + ) + config: Optional[ListAgentEngineTasksConfig] = Field( + default=None, description="""""" + ) + + +class _ListAgentEngineTasksRequestParametersDict(TypedDict, total=False): + """Parameters for listing agent engines.""" + + name: Optional[str] + """Name of the agent engine.""" + + config: Optional[ListAgentEngineTasksConfigDict] + """""" + + +_ListAgentEngineTasksRequestParametersOrDict = Union[ + _ListAgentEngineTasksRequestParameters, _ListAgentEngineTasksRequestParametersDict +] + + +class ListAgentEngineTasksResponse(_common.BaseModel): + """Response for listing agent engine tasks.""" + + sdk_http_response: Optional[genai_types.HttpResponse] = Field( + default=None, description="""Used to retain the full HTTP response.""" + ) + next_page_token: Optional[str] = Field(default=None, description="""""") + a2aTasks: Optional[list[A2aTask]] = Field( + default=None, description="""List of agent engine tasks.""" + ) + + +class ListAgentEngineTasksResponseDict(TypedDict, total=False): + """Response for listing agent engine tasks.""" + + sdk_http_response: Optional[genai_types.HttpResponseDict] + """Used to retain the full HTTP response.""" + + next_page_token: Optional[str] + """""" + + a2aTasks: Optional[list[A2aTaskDict]] + """List of agent engine tasks.""" + + +ListAgentEngineTasksResponseOrDict = Union[ + ListAgentEngineTasksResponse, ListAgentEngineTasksResponseDict +] + + +class CreateAgentEngineTaskConfig(_common.BaseModel): + """Config for creating a Session.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class CreateAgentEngineTaskConfigDict(TypedDict, total=False): + """Config for creating a Session.""" + + http_options: Optional[genai_types.HttpOptionsDict] + """Used to override HTTP request options.""" + + +CreateAgentEngineTaskConfigOrDict = Union[ + CreateAgentEngineTaskConfig, CreateAgentEngineTaskConfigDict +] + + +class _CreateAgentEngineTaskRequestParameters(_common.BaseModel): + """Parameters for creating Agent Engine Tasks.""" + + name: Optional[str] = Field( + default=None, + description="""Name of the agent engine to create the task under.""", + ) + a2a_task_id: Optional[str] = Field( + default=None, description="""The ID of the task.""" + ) + context_id: Optional[str] = Field( + default=None, description="""The context id of the task to create.""" + ) + config: Optional[CreateAgentEngineTaskConfig] = Field( + default=None, description="""""" + ) + + +class _CreateAgentEngineTaskRequestParametersDict(TypedDict, total=False): + """Parameters for creating Agent Engine Tasks.""" + + name: Optional[str] + """Name of the agent engine to create the task under.""" + + a2a_task_id: Optional[str] + """The ID of the task.""" + + context_id: Optional[str] + """The context id of the task to create.""" + + config: Optional[CreateAgentEngineTaskConfigDict] + """""" + + +_CreateAgentEngineTaskRequestParametersOrDict = Union[ + _CreateAgentEngineTaskRequestParameters, _CreateAgentEngineTaskRequestParametersDict +] + + +class TaskMetadataChange(_common.BaseModel): + """An event representing a change to the task's top-level metadata. example: metadata_change: { new_metadata: { "name": "My task", } update_mask: { paths: "name" } }""" + + new_metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Required. The complete state of the metadata object *after* the change.""", + ) + update_mask: Optional[str] = Field( + default=None, + description="""Optional. A field mask indicating which paths in the Struct were changed. If not set, all fields will be updated. go/aip-internal/cloud-standard/2412""", + ) + + +class TaskMetadataChangeDict(TypedDict, total=False): + """An event representing a change to the task's top-level metadata. example: metadata_change: { new_metadata: { "name": "My task", } update_mask: { paths: "name" } }""" + + new_metadata: Optional[dict[str, Any]] + """Required. The complete state of the metadata object *after* the change.""" + + update_mask: Optional[str] + """Optional. A field mask indicating which paths in the Struct were changed. If not set, all fields will be updated. go/aip-internal/cloud-standard/2412""" + + +TaskMetadataChangeOrDict = Union[TaskMetadataChange, TaskMetadataChangeDict] + + +class TaskArtifactChange(_common.BaseModel): + """Describes changes to the artifact list.""" + + added_artifacts: Optional[list[TaskArtifact]] = Field( + default=None, + description="""Optional. A list of brand-new artifacts created in this event.""", + ) + deleted_artifact_ids: Optional[list[str]] = Field( + default=None, + description="""Optional. A list of artifact IDs that were removed in this event.""", + ) + updated_artifacts: Optional[list[TaskArtifact]] = Field( + default=None, + description="""Optional. A list of existing artifacts that were modified in this event.""", + ) + + +class TaskArtifactChangeDict(TypedDict, total=False): + """Describes changes to the artifact list.""" + + added_artifacts: Optional[list[TaskArtifactDict]] + """Optional. A list of brand-new artifacts created in this event.""" + + deleted_artifact_ids: Optional[list[str]] + """Optional. A list of artifact IDs that were removed in this event.""" + + updated_artifacts: Optional[list[TaskArtifactDict]] + """Optional. A list of existing artifacts that were modified in this event.""" + + +TaskArtifactChangeOrDict = Union[TaskArtifactChange, TaskArtifactChangeDict] + + +class TaskOutputChange(_common.BaseModel): + """An event representing a change to the task's outputs.""" + + task_artifact_change: Optional[TaskArtifactChange] = Field( + default=None, + description="""Required. A granular change to the list of artifacts.""", + ) + + +class TaskOutputChangeDict(TypedDict, total=False): + """An event representing a change to the task's outputs.""" + + task_artifact_change: Optional[TaskArtifactChangeDict] + """Required. A granular change to the list of artifacts.""" + + +TaskOutputChangeOrDict = Union[TaskOutputChange, TaskOutputChangeDict] + + +class TaskStateChange(_common.BaseModel): + """A message representing a change in a task's state.""" + + new_state: Optional[State] = Field( + default=None, description="""Required. The new state of the task.""" + ) + + +class TaskStateChangeDict(TypedDict, total=False): + """A message representing a change in a task's state.""" + + new_state: Optional[State] + """Required. The new state of the task.""" + + +TaskStateChangeOrDict = Union[TaskStateChange, TaskStateChangeDict] + + +class TaskStatusDetailsChange(_common.BaseModel): + """Represents a change to the task's status details.""" + + new_task_status: Optional[TaskStatusDetails] = Field( + default=None, + description="""Required. The complete state of the task's status *after* the change.""", + ) + + +class TaskStatusDetailsChangeDict(TypedDict, total=False): + """Represents a change to the task's status details.""" + + new_task_status: Optional[TaskStatusDetailsDict] + """Required. The complete state of the task's status *after* the change.""" + + +TaskStatusDetailsChangeOrDict = Union[ + TaskStatusDetailsChange, TaskStatusDetailsChangeDict +] + + +class TaskEventData(_common.BaseModel): + """Data for a TaskEvent.""" + + metadata_change: Optional[TaskMetadataChange] = Field( + default=None, description="""Optional. A change to the task's metadata.""" + ) + output_change: Optional[TaskOutputChange] = Field( + default=None, description="""Optional. A change to the task's final outputs.""" + ) + state_change: Optional[TaskStateChange] = Field( + default=None, description="""Optional. A change in the task's state.""" + ) + status_details_change: Optional[TaskStatusDetailsChange] = Field( + default=None, + description="""Optional. A change to the framework-specific status details.""", + ) + + +class TaskEventDataDict(TypedDict, total=False): + """Data for a TaskEvent.""" + + metadata_change: Optional[TaskMetadataChangeDict] + """Optional. A change to the task's metadata.""" + + output_change: Optional[TaskOutputChangeDict] + """Optional. A change to the task's final outputs.""" + + state_change: Optional[TaskStateChangeDict] + """Optional. A change in the task's state.""" + + status_details_change: Optional[TaskStatusDetailsChangeDict] + """Optional. A change to the framework-specific status details.""" + + +TaskEventDataOrDict = Union[TaskEventData, TaskEventDataDict] + + +class TaskEvent(_common.BaseModel): + """A task event.""" + + create_time: Optional[datetime.datetime] = Field( + default=None, description="""Output only. The create time of the event.""" + ) + event_data: Optional[TaskEventData] = Field( + default=None, description="""Required. The delta associated with the event.""" + ) + event_sequence_number: Optional[int] = Field( + default=None, + description="""Required. The sequence number of the event. This is used to uniquely identify the event within the task and order events chronologically. This is a id generated by the SDK.""", + ) + + +class TaskEventDict(TypedDict, total=False): + """A task event.""" + + create_time: Optional[datetime.datetime] + """Output only. The create time of the event.""" + + event_data: Optional[TaskEventDataDict] + """Required. The delta associated with the event.""" + + event_sequence_number: Optional[int] + """Required. The sequence number of the event. This is used to uniquely identify the event within the task and order events chronologically. This is a id generated by the SDK.""" + + +TaskEventOrDict = Union[TaskEvent, TaskEventDict] + + +class AppendAgentEngineTaskEventConfig(_common.BaseModel): + """Config for creating a Session.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class AppendAgentEngineTaskEventConfigDict(TypedDict, total=False): + """Config for creating a Session.""" + + http_options: Optional[genai_types.HttpOptionsDict] + """Used to override HTTP request options.""" + + +AppendAgentEngineTaskEventConfigOrDict = Union[ + AppendAgentEngineTaskEventConfig, AppendAgentEngineTaskEventConfigDict +] + + +class _AppendAgentEngineTaskEventRequestParameters(_common.BaseModel): + """Parameters for creating Agent Engine Tasks.""" + + name: Optional[str] = Field( + default=None, + description="""Name of the agent the task append the event under.""", + ) + task_events: Optional[list[TaskEvent]] = Field( + default=None, description="""The events to append to the task.""" + ) + config: Optional[AppendAgentEngineTaskEventConfig] = Field( + default=None, description="""""" + ) + + +class _AppendAgentEngineTaskEventRequestParametersDict(TypedDict, total=False): + """Parameters for creating Agent Engine Tasks.""" + + name: Optional[str] + """Name of the agent the task append the event under.""" + + task_events: Optional[list[TaskEventDict]] + """The events to append to the task.""" + + config: Optional[AppendAgentEngineTaskEventConfigDict] + """""" + + +_AppendAgentEngineTaskEventRequestParametersOrDict = Union[ + _AppendAgentEngineTaskEventRequestParameters, + _AppendAgentEngineTaskEventRequestParametersDict, +] + + +class AppendAgentEngineTaskEventResponse(_common.BaseModel): + """Response for appending Agent Engine Task Events.""" + + pass + + +class AppendAgentEngineTaskEventResponseDict(TypedDict, total=False): + """Response for appending Agent Engine Task Events.""" + + pass + + +AppendAgentEngineTaskEventResponseOrDict = Union[ + AppendAgentEngineTaskEventResponse, AppendAgentEngineTaskEventResponseDict +] + + +class ListAgentEngineTaskEventsConfig(_common.BaseModel): + """Config for listing agent engine tasks.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + page_size: Optional[int] = Field(default=None, description="""""") + page_token: Optional[str] = Field(default=None, description="""""") + filter: Optional[str] = Field( + default=None, + description="""An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported.""", + ) + order_by: Optional[str] = Field( + default=None, + description="""A comma-separated list of fields to order by, sorted in ascending order. + Use "desc" after a field name for descending. + If this field is omitted, the default ordering is `create_time` descending. + More detail in [AIP-132](https://google.aip.dev/132). + + Supported fields: + * `create_time` + * `update_time` + + Example: `create_time desc`.""", + ) + + +class ListAgentEngineTaskEventsConfigDict(TypedDict, total=False): + """Config for listing agent engine tasks.""" + + http_options: Optional[genai_types.HttpOptionsDict] + """Used to override HTTP request options.""" + + page_size: Optional[int] + """""" + + page_token: Optional[str] + """""" + + filter: Optional[str] + """An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported.""" + + order_by: Optional[str] + """A comma-separated list of fields to order by, sorted in ascending order. + Use "desc" after a field name for descending. + If this field is omitted, the default ordering is `create_time` descending. + More detail in [AIP-132](https://google.aip.dev/132). + + Supported fields: + * `create_time` + * `update_time` + + Example: `create_time desc`.""" + + +ListAgentEngineTaskEventsConfigOrDict = Union[ + ListAgentEngineTaskEventsConfig, ListAgentEngineTaskEventsConfigDict +] + + +class _ListAgentEngineTaskEventsRequestParameters(_common.BaseModel): + """Parameters for listing agent engines.""" + + name: Optional[str] = Field( + default=None, description="""Name of the agent engine.""" + ) + config: Optional[ListAgentEngineTaskEventsConfig] = Field( + default=None, description="""""" + ) + + +class _ListAgentEngineTaskEventsRequestParametersDict(TypedDict, total=False): + """Parameters for listing agent engines.""" + + name: Optional[str] + """Name of the agent engine.""" + + config: Optional[ListAgentEngineTaskEventsConfigDict] + """""" + + +_ListAgentEngineTaskEventsRequestParametersOrDict = Union[ + _ListAgentEngineTaskEventsRequestParameters, + _ListAgentEngineTaskEventsRequestParametersDict, +] + + +class ListAgentEngineTaskEventsResponse(_common.BaseModel): + """Response for listing agent engine tasks.""" + + sdk_http_response: Optional[genai_types.HttpResponse] = Field( + default=None, description="""Used to retain the full HTTP response.""" + ) + next_page_token: Optional[str] = Field(default=None, description="""""") + taskEvents: Optional[list[TaskEvent]] = Field( + default=None, description="""List of agent engine tasks.""" + ) + + +class ListAgentEngineTaskEventsResponseDict(TypedDict, total=False): + """Response for listing agent engine tasks.""" + + sdk_http_response: Optional[genai_types.HttpResponseDict] + """Used to retain the full HTTP response.""" + + next_page_token: Optional[str] + """""" + + taskEvents: Optional[list[TaskEventDict]] + """List of agent engine tasks.""" + + +ListAgentEngineTaskEventsResponseOrDict = Union[ + ListAgentEngineTaskEventsResponse, ListAgentEngineTaskEventsResponseDict +] + + class CreateEvaluationItemConfig(_common.BaseModel): """Config to create an evaluation item."""