Skip to content

Region Guard

agent_memory_hub.control_plane.region_guard.RegionGuard

Bases: RegionAware

Enforces region constraints for memory operations.

Source code in agent_memory_hub/control_plane/region_guard.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class RegionGuard(RegionAware):
    """
    Enforces region constraints for memory operations.
    """
    def __init__(self, region: str):
        if region not in SUPPORTED_REGIONS:
            raise ValueError(
                f"Region '{region}' is not supported. Supported: {SUPPORTED_REGIONS}"
            )
        self._region = region

    @property
    def current_region(self) -> str:
        return self._region

    def validate_region(self, target_region: str) -> bool:
        """
        Validates if the operation matches the guard's region.
        """
        return self._region == target_region

    def check_residency(self, operation_region: Optional[str] = None) -> None:
        """
        Raises generic RuntimeError if region mismatch.
        """
        if operation_region and operation_region != self._region:
             raise RuntimeError(
                 f"Region violation: Operation in '{operation_region}' "
                 f"but guard locked to '{self._region}'"
             )

check_residency(operation_region=None)

Raises generic RuntimeError if region mismatch.

Source code in agent_memory_hub/control_plane/region_guard.py
32
33
34
35
36
37
38
39
40
def check_residency(self, operation_region: Optional[str] = None) -> None:
    """
    Raises generic RuntimeError if region mismatch.
    """
    if operation_region and operation_region != self._region:
         raise RuntimeError(
             f"Region violation: Operation in '{operation_region}' "
             f"but guard locked to '{self._region}'"
         )

validate_region(target_region)

Validates if the operation matches the guard's region.

Source code in agent_memory_hub/control_plane/region_guard.py
26
27
28
29
30
def validate_region(self, target_region: str) -> bool:
    """
    Validates if the operation matches the guard's region.
    """
    return self._region == target_region