Skip to content
Open
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
46 changes: 46 additions & 0 deletions tests/unit/vertexai/genai/test_agent_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,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": 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 @@ -1647,6 +1688,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 @@ -1741,6 +1783,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 @@ -1834,6 +1877,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 @@ -1990,6 +2034,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 @@ -2077,6 +2122,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
23 changes: 22 additions & 1 deletion vertexai/_genai/agent_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ def create(
if context_spec is not None:
# Conversion to a dict for _create_config
context_spec = context_spec.model_dump()
developer_connect_source = config.developer_connect_source
if developer_connect_source is not None:
developer_connect_source = developer_connect_source.model_dump()
if agent and agent_engine:
raise ValueError("Please specify only one of `agent` or `agent_engine`.")
elif agent_engine:
Expand Down Expand Up @@ -933,6 +936,7 @@ def create(
labels=config.labels,
class_methods=config.class_methods,
source_packages=config.source_packages,
developer_connect_source=developer_connect_source,
entrypoint_module=config.entrypoint_module,
entrypoint_object=config.entrypoint_object,
requirements_file=config.requirements_file,
Expand Down Expand Up @@ -1000,6 +1004,9 @@ def _create_config(
agent_server_mode: Optional[types.AgentServerMode] = None,
class_methods: Optional[Sequence[dict[str, Any]]] = None,
source_packages: Optional[Sequence[str]] = None,
developer_connect_source: Optional[
types.ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict
] = None,
entrypoint_module: Optional[str] = None,
entrypoint_object: Optional[str] = None,
requirements_file: Optional[str] = None,
Expand Down Expand Up @@ -1049,6 +1056,12 @@ def _create_config(
"do not specify `agent` in `agent_engines.create()` or "
"`agent_engines.update()`."
)
if developer_connect_source is not None:
raise ValueError(
"If you have provided `developer_connect_source` in `config`, please "
"do not specify `agent` in `agent_engines.create()` or "
"`agent_engines.update()`."
)

project = self._api_client.project
if project is None:
Expand Down Expand Up @@ -1148,6 +1161,11 @@ def _create_config(
}
}

if developer_connect_source is not None:
update_masks.append("spec.source_code_spec.developer_connect_source")
source_code_spec = {"developer_connect_source": developer_connect_source}

if source_packages is not None or developer_connect_source is not None:
update_masks.append("spec.source_code_spec.python_spec.version")
python_spec = {
"version": sys_version,
Expand Down Expand Up @@ -1189,7 +1207,6 @@ def _create_config(
for class_method_spec in class_methods_spec
],
}

if agent_engine_spec is not None:
if (
env_vars is not None
Expand Down Expand Up @@ -1439,6 +1456,9 @@ def update(
if context_spec is not None:
# Conversion to a dict for _create_config
context_spec = context_spec.model_dump()
developer_connect_source = config.developer_connect_source
if developer_connect_source is not None:
developer_connect_source = developer_connect_source.model_dump()
if agent and agent_engine:
raise ValueError("Please specify only one of `agent` or `agent_engine`.")
elif agent_engine:
Expand Down Expand Up @@ -1467,6 +1487,7 @@ def update(
labels=config.labels,
class_methods=config.class_methods,
source_packages=config.source_packages,
developer_connect_source=developer_connect_source,
entrypoint_module=config.entrypoint_module,
entrypoint_object=config.entrypoint_object,
requirements_file=config.requirements_file,
Expand Down
12 changes: 12 additions & 0 deletions vertexai/_genai/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@
from .common import ReasoningEngineSpecPackageSpecDict
from .common import ReasoningEngineSpecPackageSpecOrDict
from .common import ReasoningEngineSpecSourceCodeSpec
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigOrDict
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectSource
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict
from .common import ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceOrDict
from .common import ReasoningEngineSpecSourceCodeSpecDict
from .common import ReasoningEngineSpecSourceCodeSpecInlineSource
from .common import ReasoningEngineSpecSourceCodeSpecInlineSourceDict
Expand Down Expand Up @@ -1324,6 +1330,12 @@
"ReasoningEngineSpecPackageSpec",
"ReasoningEngineSpecPackageSpecDict",
"ReasoningEngineSpecPackageSpecOrDict",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigOrDict",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectSource",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict",
"ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceOrDict",
"ReasoningEngineSpecSourceCodeSpecInlineSource",
"ReasoningEngineSpecSourceCodeSpecInlineSourceDict",
"ReasoningEngineSpecSourceCodeSpecInlineSourceOrDict",
Expand Down
106 changes: 106 additions & 0 deletions vertexai/_genai/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4696,6 +4696,68 @@ class ReasoningEngineSpecPackageSpecDict(TypedDict, total=False):
]


class ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig(_common.BaseModel):
"""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use."""

dir: Optional[str] = Field(
default=None,
description="""Required. Directory, relative to the source root, in which to run the build.""",
)
git_repository_link: Optional[str] = Field(
default=None,
description="""Required. The Developer Connect Git repository link, formatted as `projects/*/locations/*/connections/*/gitRepositoryLink/*`.""",
)
revision: Optional[str] = Field(
default=None,
description="""Required. The revision to fetch from the Git repository such as a branch, a tag, a commit SHA, or any Git ref.""",
)


class ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict(
TypedDict, total=False
):
"""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use."""

dir: Optional[str]
"""Required. Directory, relative to the source root, in which to run the build."""

git_repository_link: Optional[str]
"""Required. The Developer Connect Git repository link, formatted as `projects/*/locations/*/connections/*/gitRepositoryLink/*`."""

revision: Optional[str]
"""Required. The revision to fetch from the Git repository such as a branch, a tag, a commit SHA, or any Git ref."""


ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigOrDict = Union[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig,
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict,
]


class ReasoningEngineSpecSourceCodeSpecDeveloperConnectSource(_common.BaseModel):
"""Specifies source code to be fetched from a Git repository managed through the Developer Connect service."""

config: Optional[ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig] = Field(
default=None,
description="""Required. The Developer Connect configuration thats defines the specific repository, revision, and directory to use as the source code root.""",
)


class ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict(
TypedDict, total=False
):
"""Specifies source code to be fetched from a Git repository managed through the Developer Connect service."""

config: Optional[ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict]
"""Required. The Developer Connect configuration thats defines the specific repository, revision, and directory to use as the source code root."""


ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceOrDict = Union[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectSource,
ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict,
]


class ReasoningEngineSpecSourceCodeSpecInlineSource(_common.BaseModel):
"""Specifies source code provided as a byte stream."""

Expand Down Expand Up @@ -4764,6 +4826,12 @@ class ReasoningEngineSpecSourceCodeSpecPythonSpecDict(TypedDict, total=False):
class ReasoningEngineSpecSourceCodeSpec(_common.BaseModel):
"""Specification for deploying from source code."""

developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectSource
] = Field(
default=None,
description="""Source code is in a Git repository managed by Developer Connect.""",
)
inline_source: Optional[ReasoningEngineSpecSourceCodeSpecInlineSource] = Field(
default=None, description="""Source code is provided directly in the request."""
)
Expand All @@ -4775,6 +4843,11 @@ class ReasoningEngineSpecSourceCodeSpec(_common.BaseModel):
class ReasoningEngineSpecSourceCodeSpecDict(TypedDict, total=False):
"""Specification for deploying from source code."""

developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectSourceDict
]
"""Source code is in a Git repository managed by Developer Connect."""

inline_source: Optional[ReasoningEngineSpecSourceCodeSpecInlineSourceDict]
"""Source code is provided directly in the request."""

Expand Down Expand Up @@ -5433,6 +5506,12 @@ class CreateAgentEngineConfig(_common.BaseModel):
- class_methods (required)
""",
)
developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig
] = Field(
default=None,
description="""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use.""",
)
entrypoint_module: Optional[str] = Field(
default=None,
description="""The entrypoint module to be used for the Agent Engine
Expand Down Expand Up @@ -5565,6 +5644,11 @@ class CreateAgentEngineConfigDict(TypedDict, total=False):
- class_methods (required)
"""

developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict
]
"""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use."""

entrypoint_module: Optional[str]
"""The entrypoint module to be used for the Agent Engine
This field only used when source_packages is specified."""
Expand Down Expand Up @@ -6193,6 +6277,12 @@ class UpdateAgentEngineConfig(_common.BaseModel):
- class_methods (required)
""",
)
developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig
] = Field(
default=None,
description="""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use.""",
)
entrypoint_module: Optional[str] = Field(
default=None,
description="""The entrypoint module to be used for the Agent Engine
Expand Down Expand Up @@ -6330,6 +6420,11 @@ class UpdateAgentEngineConfigDict(TypedDict, total=False):
- class_methods (required)
"""

developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict
]
"""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use."""

entrypoint_module: Optional[str]
"""The entrypoint module to be used for the Agent Engine
This field only used when source_packages is specified."""
Expand Down Expand Up @@ -13255,6 +13350,12 @@ class AgentEngineConfig(_common.BaseModel):
- class_methods (required)
""",
)
developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfig
] = Field(
default=None,
description="""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use.""",
)
entrypoint_module: Optional[str] = Field(
default=None,
description="""The entrypoint module to be used for the Agent Engine
Expand Down Expand Up @@ -13419,6 +13520,11 @@ class AgentEngineConfigDict(TypedDict, total=False):
- class_methods (required)
"""

developer_connect_source: Optional[
ReasoningEngineSpecSourceCodeSpecDeveloperConnectConfigDict
]
"""Specifies the configuration for fetching source code from a Git repository that is managed by Developer Connect. This includes the repository, revision, and directory to use."""

entrypoint_module: Optional[str]
"""The entrypoint module to be used for the Agent Engine
This field only used when source_packages is specified."""
Expand Down
Loading