Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/unit/vertexai/genai/replays/test_create_agent_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,43 @@ def test_create_with_identity_type(client):
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)


def test_create_with_developer_connect_source(client):
"""Tests creating an agent engine with developer connect source."""
developer_connect_source_config = types.ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig(
git_repository_link="projects/reasoning-engine-test-1/locations/europe-west3/connections/shawn-develop-connect/gitRepositoryLinks/shawn-yang-google-adk-samples",
revision="main",
dir="test",
)
agent_engine = client.agent_engines.create(
config={
"display_name": "test-agent-engine-dev-connect",
"developer_connect_source": developer_connect_source_config,
"entrypoint_module": "my_agent",
"entrypoint_object": "agent",
"class_methods": _TEST_CLASS_METHODS,
"http_options": {
"base_url": "https://europe-west3-aiplatform.googleapis.com",
"api_version": "v1beta1",
},
},
)
assert agent_engine.api_resource.display_name == "test-agent-engine-dev-connect"
assert (
agent_engine.api_resource.spec.source_code_spec.developer_connect_source.config.git_repository_link
== developer_connect_source_config.git_repository_link
)
assert (
agent_engine.api_resource.spec.source_code_spec.developer_connect_source.config.revision
== developer_connect_source_config.revision
)
assert (
agent_engine.api_resource.spec.source_code_spec.developer_connect_source.config.dir
== developer_connect_source_config.dir
)
# 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(),
Expand Down
78 changes: 67 additions & 11 deletions tests/unit/vertexai/genai/test_agent_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@ def test_agent_engine_adk_telemetry_enablement(
{"name": key, "value": value} for key, value in expected_env_vars.items()
]

@mock.patch.object(
_agent_engines_utils,
"_create_base64_encoded_tarball",
return_value="test_tarball",
)
@mock.patch.object(_agent_engines_utils, "_prepare")
@pytest.mark.parametrize(
"env_vars,expected_env_vars",
Expand All @@ -930,20 +935,25 @@ def test_agent_engine_adk_telemetry_enablement(
def test_agent_engine_adk_telemetry_enablement_through_source_packages(
self,
mock_prepare: mock.Mock,
mock_create_base64_encoded_tarball: mock.Mock,
env_vars: dict[str, str],
expected_env_vars: dict[str, str],
):
config = self.client.agent_engines._create_config(
mode="create",
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
description=_TEST_AGENT_ENGINE_DESCRIPTION,
source_packages=[],
class_methods=[],
entrypoint_module=".",
entrypoint_object=".",
env_vars=env_vars,
agent_framework="google-adk",
)
with tempfile.TemporaryDirectory() as tmpdir:
test_file_path = os.path.join(tmpdir, "test_file.txt")
with open(test_file_path, "w") as f:
f.write("test content")
config = self.client.agent_engines._create_config(
mode="create",
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
description=_TEST_AGENT_ENGINE_DESCRIPTION,
source_packages=[test_file_path],
class_methods=[],
entrypoint_module=".",
entrypoint_object=".",
env_vars=env_vars,
agent_framework="google-adk",
)
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
assert config["spec"]["deployment_spec"]["env"] == [
Expand Down Expand Up @@ -1062,6 +1072,47 @@ def test_create_agent_engine_config_with_source_packages(
== _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
)

def test_create_agent_engine_config_with_developer_connect_source(self):
with tempfile.TemporaryDirectory() as tmpdir:
requirements_file_path = os.path.join(tmpdir, "requirements.txt")
with open(requirements_file_path, "w") as f:
f.write("requests==2.0.0")
developer_connect_source = {
"git_repository_link": "projects/test-project/locations/us-central1/connections/test-connection/gitRepositoryLinks/test-repo",
"revision": "main",
"dir": "agent",
}
config = self.client.agent_engines._create_config(
mode="create",
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
description=_TEST_AGENT_ENGINE_DESCRIPTION,
developer_connect_source=developer_connect_source,
entrypoint_module="main",
entrypoint_object="app",
requirements_file=requirements_file_path,
class_methods=_TEST_AGENT_ENGINE_CLASS_METHODS,
agent_framework=_TEST_AGENT_FRAMEWORK,
identity_type=_TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT,
python_version=_TEST_PYTHON_VERSION_OVERRIDE,
)
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
assert config["spec"]["agent_framework"] == _TEST_AGENT_FRAMEWORK
assert config["spec"]["source_code_spec"] == {
"developer_connect_source": {"config": developer_connect_source},
"python_spec": {
"version": _TEST_PYTHON_VERSION_OVERRIDE,
"entrypoint_module": "main",
"entrypoint_object": "app",
"requirements_file": requirements_file_path,
},
}
assert config["spec"]["class_methods"] == _TEST_AGENT_ENGINE_CLASS_METHODS
assert (
config["spec"]["identity_type"]
== _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
)

@mock.patch.object(
_agent_engines_utils,
"_create_base64_encoded_tarball",
Expand Down Expand Up @@ -1824,6 +1875,7 @@ def test_create_agent_engine_with_env_vars_dict(
labels=None,
class_methods=None,
source_packages=None,
developer_connect_source=None,
entrypoint_module=None,
entrypoint_object=None,
requirements_file=None,
Expand Down Expand Up @@ -1924,6 +1976,7 @@ def test_create_agent_engine_with_custom_service_account(
agent_server_mode=None,
class_methods=None,
source_packages=None,
developer_connect_source=None,
entrypoint_module=None,
entrypoint_object=None,
requirements_file=None,
Expand Down Expand Up @@ -2023,6 +2076,7 @@ def test_create_agent_engine_with_experimental_mode(
agent_server_mode=_genai_types.AgentServerMode.EXPERIMENTAL,
class_methods=None,
source_packages=None,
developer_connect_source=None,
entrypoint_module=None,
entrypoint_object=None,
requirements_file=None,
Expand Down Expand Up @@ -2191,6 +2245,7 @@ def test_create_agent_engine_with_class_methods(
agent_server_mode=None,
class_methods=_TEST_AGENT_ENGINE_CLASS_METHODS,
source_packages=None,
developer_connect_source=None,
entrypoint_module=None,
entrypoint_object=None,
requirements_file=None,
Expand Down Expand Up @@ -2284,6 +2339,7 @@ def test_create_agent_engine_with_agent_framework(
agent_server_mode=None,
class_methods=None,
source_packages=None,
developer_connect_source=None,
entrypoint_module=None,
entrypoint_object=None,
requirements_file=None,
Expand Down
Loading
Loading