GeezerVison is showing github.com — feat: Migrate vertex_ai_session_service to use Agent Engine SDK · googleapis/python-aiplatform@03772e2
File tree
Expand file treeCollapse file tree
Open diff view settings
preview/reasoning_engines/templates
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: vertexai/agent_engines/templates/adk.py +13-8Lines changed: 13 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -537,15 +537,20 @@ def set_up(self): |
537 | 537 | if session_service_builder: |
538 | 538 | self._tmpl_attrs["session_service"] = session_service_builder() |
539 | 539 | elif "GOOGLE_CLOUD_AGENT_ENGINE_ID" in os.environ: |
540 | | - from google.adk.sessions.vertex_ai_session_service import ( |
541 | | - VertexAiSessionService, |
542 | | - ) |
| 540 | + try: |
| 541 | + from google.adk.sessions.vertex_ai_session_service import ( |
| 542 | + VertexAiSessionService, |
| 543 | + ) |
| 544 | + |
| 545 | + self._tmpl_attrs["session_service"] = VertexAiSessionService( |
| 546 | + project=project, |
| 547 | + location=location, |
| 548 | + agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
| 549 | + ) |
| 550 | + except ImportError: |
| 551 | + # TODO(ysian): Handle this via _g3 import for google3. |
| 552 | + pass |
543 | 553 |
|
544 | | - self._tmpl_attrs["session_service"] = VertexAiSessionService( |
545 | | - project=project, |
546 | | - location=location, |
547 | | - agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
548 | | - ) |
549 | 554 | else: |
550 | 555 | self._tmpl_attrs["session_service"] = InMemorySessionService() |
551 | 556 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: vertexai/preview/reasoning_engines/templates/adk.py +19-14Lines changed: 19 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -512,21 +512,26 @@ def set_up(self): |
512 | 512 | if session_service_builder: |
513 | 513 | self._tmpl_attrs["session_service"] = session_service_builder() |
514 | 514 | elif "GOOGLE_CLOUD_AGENT_ENGINE_ID" in os.environ: |
515 | | - from google.adk.sessions.vertex_ai_session_service import ( |
516 | | - VertexAiSessionService, |
517 | | - ) |
518 | | - |
519 | | - if is_version_sufficient("1.5.0"): |
520 | | - self._tmpl_attrs["session_service"] = VertexAiSessionService( |
521 | | - project=project, |
522 | | - location=location, |
523 | | - agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
524 | | - ) |
525 | | - else: |
526 | | - self._tmpl_attrs["session_service"] = VertexAiSessionService( |
527 | | - project=project, |
528 | | - location=location, |
| 515 | + try: |
| 516 | + from google.adk.sessions.vertex_ai_session_service import ( |
| 517 | + VertexAiSessionService, |
529 | 518 | ) |
| 519 | + |
| 520 | + if is_version_sufficient("1.5.0"): |
| 521 | + self._tmpl_attrs["session_service"] = VertexAiSessionService( |
| 522 | + project=project, |
| 523 | + location=location, |
| 524 | + agent_engine_id=os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID"), |
| 525 | + ) |
| 526 | + else: |
| 527 | + self._tmpl_attrs["session_service"] = VertexAiSessionService( |
| 528 | + project=project, |
| 529 | + location=location, |
| 530 | + ) |
| 531 | + except ImportError: |
| 532 | + # TODO(deanchen): Handle this via _g3 import for google3. |
| 533 | + pass |
| 534 | + |
530 | 535 | else: |
531 | 536 | self._tmpl_attrs["session_service"] = InMemorySessionService() |
532 | 537 |
|
|