Skip to content

feat: GenAI SDK client - Initial release of Agent Engine Memories SDK #5461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions tests/unit/vertexai/genai/replays/test_create_agent_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os

from tests.unit.vertexai.genai.replays import pytest_helper
from vertexai._genai import types


def test_create_config_lightweight(client):
Expand All @@ -39,13 +38,6 @@ def test_create_config_lightweight(client):
}


def test_create_operation(client):
operation = client.agent_engines.create(
config=types.AgentEngineConfig(return_agent=False)
)
assert "reasoningEngines" in operation.name


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_create_memory(client):
agent_engine = client.agent_engines.create()
operation = client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact",
scope={"user_id": "123"},
)
assert operation.response.fact == "memory_fact"
assert operation.response.scope == {"user_id": "123"}
assert operation.response.name.startswith(agent_engine.api_resource.name)


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.create_memory",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_delete_memory(client):
agent_engine = client.agent_engines.create()
operation = client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact",
scope={"user_id": "123"},
)
memory = operation.response
operation = client.agent_engines.delete_memory(name=memory.name)
assert operation.name.startswith(memory.name + "/operations/")


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.delete_memory",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_generate_memories(client):
agent_engine = client.agent_engines.create()
assert not list(
client.agent_engines.list_memories(
name=agent_engine.api_resource.name,
)
)
client.agent_engines.generate_memories(
name=agent_engine.api_resource.name,
direct_contents_source={
"events": [
{
"content": {
"role": "model",
"parts": [
{"text": "I am a software engineer focusing in security"}
],
}
}
]
},
scope={"user_id": "test-user-id"},
)
assert (
len(
list(
client.agent_engines.list_memories(
name=agent_engine.api_resource.name,
)
)
)
>= 1
)


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.generate_memories",
)
37 changes: 37 additions & 0 deletions tests/unit/vertexai/genai/replays/test_get_agent_engine_memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_get_memory(client):
agent_engine = client.agent_engines.create()
operation = client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact",
scope={"user_id": "123"},
)
memory = client.agent_engines.get_memory(
name=operation.response.name,
)
assert memory.name == operation.response.name


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.get_memory",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_list_memories(client):
agent_engine = client.agent_engines.create()
assert not list(
client.agent_engines.list_memories(
name=agent_engine.api_resource.name,
)
)
client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact",
scope={"user_id": "123"},
)
assert (
len(
list(
client.agent_engines.list_memories(
name=agent_engine.api_resource.name,
)
)
)
== 1
)


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.list_memories",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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.
#
# pylint: disable=protected-access,bad-continuation,missing-function-docstring

from tests.unit.vertexai.genai.replays import pytest_helper


def test_retrieve_memories(client):
agent_engine = client.agent_engines.create()
assert not list(
client.agent_engines.retrieve_memories(
name=agent_engine.api_resource.name,
scope={"user_id": "123"},
)
)
client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact_1",
scope={"user_id": "123"},
)
assert (
len(
list(
client.agent_engines.retrieve_memories(
name=agent_engine.api_resource.name,
scope={"user_id": "123"},
)
)
)
== 1
)
assert not list(
client.agent_engines.retrieve_memories(
name=agent_engine.api_resource.name,
scope={"user_id": "456"},
)
)
client.agent_engines.create_memory(
name=agent_engine.api_resource.name,
fact="memory_fact_2",
scope={"user_id": "123"},
)
assert (
len(
list(
client.agent_engines.retrieve_memories(
name=agent_engine.api_resource.name,
scope={"user_id": "123"},
)
)
)
== 2
)


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="agent_engines.create_memory",
)
Loading