Skip to content

Commit 908e8b0

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: add more fields to the GenAI client for the Agent Engine Task Store Service
PiperOrigin-RevId: 874762764
1 parent 7c661d7 commit 908e8b0

10 files changed

Lines changed: 2818 additions & 30 deletions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_append_simple_a2a_task_events(client):
22+
# Use the autopush environment.
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com/"
25+
)
26+
agent_engine = client.agent_engines.create()
27+
assert isinstance(agent_engine, types.AgentEngine)
28+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
29+
# Use the internal API version for internal API access.
30+
client._api_client._http_options.api_version = "internal"
31+
task = client.agent_engines.a2a_tasks.create(
32+
name=agent_engine.api_resource.name,
33+
a2a_task_id="task123",
34+
config=types.CreateAgentEngineTaskConfig(context_id="context123"),
35+
)
36+
assert isinstance(task, types.A2aTask)
37+
38+
client.agent_engines.a2a_tasks.events.append(
39+
name=task.name,
40+
task_events=[
41+
types.TaskEvent(
42+
event_data=types.TaskEventData(
43+
metadata_change=types.TaskMetadataChange(
44+
new_metadata={"key1": "value1"}
45+
)
46+
),
47+
event_sequence_number=1,
48+
)
49+
],
50+
)
51+
52+
# Clean up resources.
53+
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
54+
55+
56+
pytestmark = pytest_helper.setup(
57+
file=__file__,
58+
globals_for_file=globals(),
59+
)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_create_simple_a2a_task(client):
22+
# Use the autopush environment.
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com/"
25+
)
26+
agent_engine = client.agent_engines.create()
27+
assert isinstance(agent_engine, types.AgentEngine)
28+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
29+
# Use the internal API version for internal API access.
30+
client._api_client._http_options.api_version = "internal"
31+
32+
task = client.agent_engines.a2a_tasks.create(
33+
name=agent_engine.api_resource.name,
34+
a2a_task_id="task123",
35+
config=types.CreateAgentEngineTaskConfig(
36+
context_id="context123",
37+
metadata={
38+
"key": "value",
39+
"key2": [{"key3": "value3", "key4": "value4"}],
40+
},
41+
state=types.A2aTaskState.STATE_UNSPECIFIED,
42+
status_details=types.TaskStatusDetails(
43+
task_message=types.TaskMessage(
44+
role="user",
45+
message_id="message123",
46+
parts=[
47+
types.Part(
48+
text="hello123",
49+
)
50+
],
51+
metadata={
52+
"key42": "value42",
53+
},
54+
),
55+
),
56+
output=types.TaskOutput(
57+
artifacts=[
58+
types.TaskArtifact(
59+
artifact_id="artifact123",
60+
display_name="display_name123",
61+
description="description123",
62+
parts=[
63+
types.Part(
64+
text="hello456",
65+
)
66+
],
67+
)
68+
],
69+
),
70+
),
71+
)
72+
73+
assert isinstance(task, types.A2aTask)
74+
assert task.name == f"{agent_engine.api_resource.name}/a2aTasks/task123"
75+
assert task.context_id == "context123"
76+
assert task.state == types.State.SUBMITTED
77+
assert task.status_details.task_message.role == "user"
78+
assert task.status_details.task_message.message_id == "message123"
79+
assert task.status_details.task_message.parts[0].text == "hello123"
80+
assert task.status_details.task_message.metadata["key42"] == "value42"
81+
assert task.output.artifacts[0].artifact_id == "artifact123"
82+
assert task.output.artifacts[0].display_name == "display_name123"
83+
assert task.output.artifacts[0].description == "description123"
84+
assert task.output.artifacts[0].parts[0].text == "hello456"
85+
assert task.metadata == {
86+
"key": "value",
87+
"key2": [{"key3": "value3", "key4": "value4"}],
88+
}
89+
90+
# Clean up resources.
91+
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
92+
93+
94+
pytestmark = pytest_helper.setup(
95+
file=__file__,
96+
globals_for_file=globals(),
97+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_get_a2a_task(client):
22+
# Use the autopush environment.
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com/"
25+
)
26+
agent_engine = client.agent_engines.create()
27+
assert isinstance(agent_engine, types.AgentEngine)
28+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
29+
# Use the internal API version for internal API access.
30+
client._api_client._http_options.api_version = "internal"
31+
32+
created_task = client.agent_engines.a2a_tasks.create(
33+
name=agent_engine.api_resource.name,
34+
a2a_task_id="task123",
35+
config=types.CreateAgentEngineTaskConfig(context_id="context123"),
36+
)
37+
assert isinstance(created_task, types.A2aTask)
38+
39+
task = client.agent_engines.a2a_tasks.get(
40+
name=created_task.name,
41+
)
42+
assert isinstance(task, types.A2aTask)
43+
assert task.name == f"{agent_engine.api_resource.name}/a2aTasks/task123"
44+
assert task.context_id == "context123"
45+
assert task.state == types.State.SUBMITTED
46+
47+
# Clean up resources.
48+
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
49+
50+
51+
pytestmark = pytest_helper.setup(
52+
file=__file__,
53+
globals_for_file=globals(),
54+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_list_simple_a2a_task_events(client):
22+
# Use the autopush environment.
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com/"
25+
)
26+
agent_engine = client.agent_engines.create()
27+
assert isinstance(agent_engine, types.AgentEngine)
28+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
29+
# Use the internal API version for internal API access.
30+
client._api_client._http_options.api_version = "internal"
31+
task = client.agent_engines.a2a_tasks.create(
32+
name=agent_engine.api_resource.name,
33+
a2a_task_id="task999",
34+
config=types.CreateAgentEngineTaskConfig(context_id="context999"),
35+
)
36+
assert isinstance(task, types.A2aTask)
37+
38+
events = list(
39+
client.agent_engines.a2a_tasks.events.list(
40+
name=task.name,
41+
)
42+
)
43+
assert len(events) == 1
44+
assert events[0].event_data.state_change.new_state == "SUBMITTED"
45+
46+
client.agent_engines.a2a_tasks.events.append(
47+
name=task.name,
48+
task_events=[
49+
types.TaskEvent(
50+
event_data=types.TaskEventData(
51+
metadata_change=types.TaskMetadataChange(
52+
new_metadata={"key1": "value1"}
53+
)
54+
),
55+
event_sequence_number=1,
56+
),
57+
types.TaskEvent(
58+
event_data=types.TaskEventData(
59+
metadata_change=types.TaskMetadataChange(
60+
new_metadata={"key2": "value2"}
61+
)
62+
),
63+
event_sequence_number=2,
64+
),
65+
],
66+
)
67+
68+
result = list(
69+
client.agent_engines.a2a_tasks.events.list(
70+
name=task.name,
71+
config=types.ListAgentEngineTaskEventsConfig(
72+
order_by="create_time desc",
73+
),
74+
)
75+
)
76+
77+
assert len(result) == 3
78+
assert result[0].event_sequence_number == 2
79+
assert result[0].event_data.metadata_change.new_metadata == {"key2": "value2"}
80+
assert result[1].event_sequence_number == 1
81+
assert result[1].event_data.metadata_change.new_metadata == {"key1": "value1"}
82+
assert result[2].event_data.state_change.new_state == "SUBMITTED"
83+
84+
# Clean up resources.
85+
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
86+
87+
88+
pytestmark = pytest_helper.setup(
89+
file=__file__,
90+
globals_for_file=globals(),
91+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_list_a2a_tasks(client):
22+
# Use the autopush environment.
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com/"
25+
)
26+
agent_engine = client.agent_engines.create()
27+
assert isinstance(agent_engine, types.AgentEngine)
28+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
29+
# Use the internal API version for internal API access.
30+
client._api_client._http_options.api_version = "internal"
31+
32+
assert not list(
33+
client.agent_engines.a2a_tasks.list(
34+
name=agent_engine.api_resource.name,
35+
)
36+
)
37+
client.agent_engines.a2a_tasks.create(
38+
name=agent_engine.api_resource.name,
39+
a2a_task_id="task123",
40+
config=types.CreateAgentEngineTaskConfig(context_id="context123"),
41+
)
42+
client.agent_engines.a2a_tasks.create(
43+
name=agent_engine.api_resource.name,
44+
a2a_task_id="task456",
45+
config=types.CreateAgentEngineTaskConfig(context_id="context456"),
46+
)
47+
a2a_tasks_list = client.agent_engines.a2a_tasks.list(
48+
name=agent_engine.api_resource.name,
49+
config=types.ListAgentEngineTasksConfig(
50+
page_size=1,
51+
order_by="create_time asc",
52+
),
53+
)
54+
assert len(a2a_tasks_list) == 1
55+
assert isinstance(a2a_tasks_list[0], types.A2aTask)
56+
assert a2a_tasks_list[0].name == (
57+
f"{agent_engine.api_resource.name}/a2aTasks/task123"
58+
)
59+
assert a2a_tasks_list[0].context_id == "context123"
60+
61+
# Clean up resources.
62+
agent_engine.delete(force=True)
63+
64+
65+
pytestmark = pytest_helper.setup(
66+
file=__file__,
67+
globals_for_file=globals(),
68+
)

0 commit comments

Comments
 (0)