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
19 changes: 19 additions & 0 deletions agentplatform/_genai/_memory_bank_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ async def __call__(
pass


def _is_memory_bank_name(name: str) -> bool:
"""Returns whether `name` is a top-level Memory Bank resource name.

Accepts both the full form
(`projects/{project}/locations/{location}/memoryBanks/{id}`) and the short
form (`memoryBanks/{id}`). Any other name, such as
`reasoningEngines/{id}`, refers to a Memory Bank backed by a Reasoning
Engine.
"""
return bool(
re.match(
r"^(projects/[^/]+/locations/[^/]+/)?memoryBanks/[^/]+$",
name or "",
)
)


def _get_memory_bank_id(operation_name: str = "", resource_name: str = "") -> str:
"""Returns Memory Bank ID from operation name or resource name."""
if not resource_name and not operation_name:
Expand Down Expand Up @@ -82,6 +99,8 @@ def _get_memory_bank_id(operation_name: str = "", resource_name: str = "") -> st
r"^projects/[^/]+/locations/[^/]+/memoryBanks/([^/]+)/operations/[^/]+$",
operation_name,
)
if match:
return match.group(1)
raise ValueError(
"Failed to parse Memory Bank ID from operation name: " f"`{operation_name}`"
)
Expand Down
Loading
Loading