Skip to content

Commit 69d87e2

Browse files
shawn-yang-googlecopybara-github
authored andcommitted
feat: GenAI SDK client - Agent Engine Session Events SDK
PiperOrigin-RevId: 794819284
1 parent ab94b66 commit 69d87e2

File tree

4 files changed

+1988
-245
lines changed

4 files changed

+1988
-245
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
import datetime
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
21+
22+
def test_append_session_event(client):
23+
agent_engine = client.agent_engines.create()
24+
operation = client.agent_engines.create_session(
25+
name=agent_engine.api_resource.name,
26+
user_id="test-user-123",
27+
)
28+
session = operation.response
29+
client.agent_engines.append_session_event(
30+
name=session.name,
31+
author="test-user-123",
32+
invocation_id="test-invocation-id",
33+
timestamp=datetime.datetime.fromtimestamp(1234567890, tz=datetime.timezone.utc),
34+
config={
35+
"content": {
36+
"parts": [
37+
{
38+
"text": "Hello World",
39+
},
40+
],
41+
},
42+
"error_code": "test-error-code",
43+
"error_message": "test-error-message",
44+
},
45+
)
46+
47+
48+
pytestmark = pytest_helper.setup(
49+
file=__file__,
50+
globals_for_file=globals(),
51+
test_method="agent_engines.append_session_event",
52+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
import datetime
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_list_session_events(client):
24+
agent_engine = client.agent_engines.create()
25+
operation = client.agent_engines.create_session(
26+
name=agent_engine.api_resource.name,
27+
user_id="test-user-123",
28+
)
29+
session = operation.response
30+
assert not list(
31+
client.agent_engines.list_session_events(
32+
name=session.name,
33+
)
34+
)
35+
client.agent_engines.append_session_event(
36+
name=session.name,
37+
author="test-user-123",
38+
invocation_id="test-invocation-id",
39+
timestamp=datetime.datetime.fromtimestamp(1234567890, tz=datetime.timezone.utc),
40+
)
41+
session_event_list = client.agent_engines.list_session_events(
42+
name=session.name,
43+
)
44+
assert len(session_event_list) == 1
45+
assert isinstance(session_event_list[0], types.SessionEvent)
46+
47+
48+
pytestmark = pytest_helper.setup(
49+
file=__file__,
50+
globals_for_file=globals(),
51+
test_method="agent_engines.list_session_events",
52+
)

0 commit comments

Comments
 (0)