|
81 | 81 | _DEFAULT_USER_ID = "default-user-id" |
82 | 82 |
|
83 | 83 |
|
84 | | -def get_adk_major_version() -> int: |
85 | | - """Get the major version of google-adk.""" |
| 84 | +def get_adk_version() -> Optional[str]: |
| 85 | + """Returns the version of the ADK package.""" |
86 | 86 | try: |
87 | 87 | from google.adk import version |
88 | 88 |
|
89 | | - return int(version.__version__.split(".")[0]) |
| 89 | + return version.__version__ |
90 | 90 | except ImportError: |
91 | | - return 0 |
| 91 | + return None |
| 92 | + |
| 93 | + |
| 94 | +def is_version_sufficient(version_to_check: str) -> bool: |
| 95 | + """Compares the existing version of ADK with the required version. |
| 96 | +
|
| 97 | + Args: |
| 98 | + version_to_check: The version string to check. |
| 99 | +
|
| 100 | + Returns: |
| 101 | + True if the existing version is sufficient, False otherwise. |
| 102 | + """ |
| 103 | + try: |
| 104 | + from packaging.version import parse |
| 105 | + |
| 106 | + return parse(get_adk_version()) >= parse(version_to_check) |
| 107 | + except (AttributeError, ImportError): |
| 108 | + return False |
92 | 109 |
|
93 | 110 |
|
94 | 111 | class _ArtifactVersion: |
@@ -294,10 +311,10 @@ def __init__( |
294 | 311 | """An ADK Application.""" |
295 | 312 | from google.cloud.aiplatform import initializer |
296 | 313 |
|
297 | | - adk_major_version = get_adk_major_version() |
298 | | - if adk_major_version < 1: |
| 314 | + adk_version = get_adk_version() |
| 315 | + if not is_version_sufficient("1.0.0"): |
299 | 316 | msg = ( |
300 | | - f"Unsupported google-adk major version: {adk_major_version}, " |
| 317 | + f"Unsupported google-adk version: {adk_version}, " |
301 | 318 | "please use google-adk>=1.0.0 for AdkApp deployment." |
302 | 319 | ) |
303 | 320 | raise ValueError(msg) |
@@ -464,16 +481,35 @@ def set_up(self): |
464 | 481 | VertexAiSessionService, |
465 | 482 | ) |
466 | 483 |
|
467 | | - self._tmpl_attrs["session_service"] = VertexAiSessionService( |
468 | | - project=project, |
469 | | - location=location, |
470 | | - ) |
| 484 | + if is_version_sufficient("1.5.0"): |
| 485 | + self._tmpl_attrs["session_service"] = VertexAiSessionService( |
| 486 | + project=project, |
| 487 | + location=location, |
| 488 | + agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
| 489 | + ) |
| 490 | + else: |
| 491 | + self._tmpl_attrs["session_service"] = VertexAiSessionService( |
| 492 | + project=project, |
| 493 | + location=location, |
| 494 | + ) |
471 | 495 | else: |
472 | 496 | self._tmpl_attrs["session_service"] = InMemorySessionService() |
473 | 497 |
|
474 | 498 | memory_service_builder = self._tmpl_attrs.get("memory_service_builder") |
475 | 499 | if memory_service_builder: |
476 | 500 | self._tmpl_attrs["memory_service"] = memory_service_builder() |
| 501 | + elif "GOOGLE_CLOUD_AGENT_ENGINE_ID" in os.environ and is_version_sufficient( |
| 502 | + "1.5.0" |
| 503 | + ): |
| 504 | + from google.adk.memory.vertex_ai_memory_bank_service import ( |
| 505 | + VertexAiMemoryBankService, |
| 506 | + ) |
| 507 | + |
| 508 | + self._tmpl_attrs["memory_service"] = VertexAiMemoryBankService( |
| 509 | + project=project, |
| 510 | + location=location, |
| 511 | + agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
| 512 | + ) |
477 | 513 | else: |
478 | 514 | self._tmpl_attrs["memory_service"] = InMemoryMemoryService() |
479 | 515 |
|
|
0 commit comments