Skip to content

Commit 8f28c40

Browse files
shawn-yang-googlecopybara-github
authored andcommitted
feat: GenAI SDK client - Agent Engine Session SDK
PiperOrigin-RevId: 789182389
1 parent 58880be commit 8f28c40

File tree

6 files changed

+1923
-38
lines changed

6 files changed

+1923
-38
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 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_session(client):
22+
agent_engine = client.agent_engines.create()
23+
assert isinstance(agent_engine, types.AgentEngine)
24+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
25+
26+
operation = client.agent_engines.create_session(
27+
name=agent_engine.api_resource.name,
28+
user_id="test-user-123",
29+
config=types.CreateAgentEngineSessionConfig(
30+
display_name="my_session",
31+
session_state={"foo": "bar"},
32+
),
33+
)
34+
assert isinstance(operation, types.AgentEngineSessionOperation)
35+
assert operation.response.display_name == "my_session"
36+
assert operation.response.session_state == {"foo": "bar"}
37+
assert operation.response.user_id == "test-user-123"
38+
assert operation.response.name.startswith(agent_engine.api_resource.name)
39+
40+
41+
pytestmark = pytest_helper.setup(
42+
file=__file__,
43+
globals_for_file=globals(),
44+
test_method="agent_engines.create_session",
45+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2025 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_delete_session(client):
22+
agent_engine = client.agent_engines.create()
23+
operation = client.agent_engines.create_session(
24+
name=agent_engine.api_resource.name,
25+
user_id="test-user-123",
26+
)
27+
session = operation.response
28+
operation = client.agent_engines.delete_session(name=session.name)
29+
assert isinstance(operation, types.DeleteAgentEngineSessionOperation)
30+
assert "/operations/" in operation.name
31+
32+
33+
pytestmark = pytest_helper.setup(
34+
file=__file__,
35+
globals_for_file=globals(),
36+
test_method="agent_engines.delete_session",
37+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 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_session(client):
22+
agent_engine = client.agent_engines.create()
23+
operation = client.agent_engines.create_session(
24+
name=agent_engine.api_resource.name,
25+
user_id="test-user-123",
26+
)
27+
assert isinstance(operation, types.AgentEngineSessionOperation)
28+
session = client.agent_engines.get_session(
29+
name=operation.response.name,
30+
)
31+
assert isinstance(session, types.Session)
32+
assert session.name == operation.response.name
33+
34+
35+
pytestmark = pytest_helper.setup(
36+
file=__file__,
37+
globals_for_file=globals(),
38+
test_method="agent_engines.get_session",
39+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2025 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_sessions(client):
22+
agent_engine = client.agent_engines.create()
23+
assert not list(
24+
client.agent_engines.list_sessions(
25+
name=agent_engine.api_resource.name,
26+
)
27+
)
28+
client.agent_engines.create_session(
29+
name=agent_engine.api_resource.name,
30+
user_id="test-user-123",
31+
)
32+
session_list = client.agent_engines.list_sessions(
33+
name=agent_engine.api_resource.name,
34+
)
35+
assert len(session_list) == 1
36+
assert isinstance(session_list[0], types.Session)
37+
38+
39+
pytestmark = pytest_helper.setup(
40+
file=__file__,
41+
globals_for_file=globals(),
42+
test_method="agent_engines.list_sessions",
43+
)

0 commit comments

Comments
 (0)