Skip to content

Commit ca348f0

Browse files
refactor(agent-memory): rename AccessStrategy values and add PROVIDER warning
- SUBSCRIBER_ONLY → SUBSCRIBER, PROVIDER_ONLY → PROVIDER across all agent_memory source, tests, feature files, and user guide - Add logger.warning() when AccessStrategy.PROVIDER is used, making the no-isolation behaviour explicit at runtime
1 parent 7de0f24 commit ca348f0

9 files changed

Lines changed: 209 additions & 204 deletions

File tree

src/sap_cloud_sdk/agent_memory/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
# Subscriber tenant — strategy and tenant set once, inherited by all calls
1111
client = create_client(
12-
access_strategy=AccessStrategy.SUBSCRIBER_ONLY,
12+
access_strategy=AccessStrategy.SUBSCRIBER,
1313
tenant="my-tenant-subdomain",
1414
)
1515
memories = client.list_memories(agent_id="my-agent", invoker_id="user-123")
@@ -41,7 +41,7 @@
4141
def create_client(
4242
*,
4343
config: Optional[AgentMemoryConfig] = None,
44-
access_strategy: AccessStrategy = AccessStrategy.SUBSCRIBER_ONLY,
44+
access_strategy: AccessStrategy = AccessStrategy.SUBSCRIBER,
4545
tenant: Optional[str] = None,
4646
) -> AgentMemoryClient:
4747
"""Create an :class:`AgentMemoryClient` with automatic credential detection.
@@ -52,18 +52,18 @@ def create_client(
5252
``/etc/secrets/appfnd/hana-agent-memory/default/`` or from
5353
``CLOUD_SDK_CFG_AGENT_MEMORY_DEFAULT_*`` environment variables.
5454
access_strategy: Default tenant access strategy for all client operations.
55-
Defaults to ``SUBSCRIBER_ONLY``. Individual method calls may override
55+
Defaults to ``SUBSCRIBER``. Individual method calls may override
5656
this value.
5757
tenant: Default subscriber tenant subdomain. Required when
58-
``access_strategy=SUBSCRIBER_ONLY``. Individual method calls may
58+
``access_strategy=SUBSCRIBER``. Individual method calls may
5959
override this value.
6060
6161
Returns:
6262
A ready-to-use :class:`AgentMemoryClient`.
6363
6464
Raises:
6565
AgentMemoryConfigError: If configuration is missing, invalid, or
66-
``access_strategy=SUBSCRIBER_ONLY`` is used without a ``tenant``.
66+
``access_strategy=SUBSCRIBER`` is used without a ``tenant``.
6767
"""
6868
try:
6969
resolved_config = config if config is not None else _load_config_from_env()

src/sap_cloud_sdk/agent_memory/_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
class AccessStrategy(str, Enum):
1919
"""Access strategy for tenant-scoped Agent Memory operations."""
2020

21-
SUBSCRIBER_ONLY = "SUBSCRIBER_ONLY"
22-
PROVIDER_ONLY = "PROVIDER_ONLY"
21+
SUBSCRIBER = "SUBSCRIBER"
22+
PROVIDER = "PROVIDER"
2323

2424

2525
class MessageRole(str, Enum):

src/sap_cloud_sdk/agent_memory/client.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from __future__ import annotations
1111

12+
import logging
1213
from typing import Any, Optional
1314

1415
from sap_cloud_sdk.agent_memory._endpoints import (
@@ -38,6 +39,8 @@
3839
)
3940
from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics
4041

42+
logger = logging.getLogger(__name__)
43+
4144

4245
def _require_non_empty(**fields: str) -> None:
4346
"""Raise AgentMemoryValidationError if any named field is an empty string."""
@@ -76,16 +79,16 @@ class AgentMemoryClient:
7679
Args:
7780
transport: HTTP transport layer (injected by ``create_client``).
7881
access_strategy: Default tenant access strategy for all operations.
79-
Defaults to ``SUBSCRIBER_ONLY``. Can be overridden per method call.
82+
Defaults to ``SUBSCRIBER``. Can be overridden per method call.
8083
tenant: Default subscriber tenant subdomain. Required when
81-
``access_strategy=SUBSCRIBER_ONLY``. Can be overridden per method call.
84+
``access_strategy=SUBSCRIBER``. Can be overridden per method call.
8285
"""
8386

8487
def __init__(
8588
self,
8689
transport: HttpTransport,
8790
*,
88-
access_strategy: AccessStrategy = AccessStrategy.SUBSCRIBER_ONLY,
91+
access_strategy: AccessStrategy = AccessStrategy.SUBSCRIBER,
8992
tenant: Optional[str] = None,
9093
) -> None:
9194
self._transport = transport
@@ -112,7 +115,7 @@ def _resolve_tenant(
112115
Per-call parameters take precedence over instance defaults.
113116
114117
Raises:
115-
AgentMemoryValidationError: If the effective strategy is ``SUBSCRIBER_ONLY``
118+
AgentMemoryValidationError: If the effective strategy is ``SUBSCRIBER``
116119
but no tenant is available.
117120
"""
118121
effective_strategy = (
@@ -122,16 +125,18 @@ def _resolve_tenant(
122125
)
123126
effective_tenant = tenant if tenant is not None else self._default_tenant
124127

125-
if (
126-
effective_strategy is AccessStrategy.SUBSCRIBER_ONLY
127-
and not effective_tenant
128-
):
128+
if effective_strategy is AccessStrategy.SUBSCRIBER and not effective_tenant:
129129
raise AgentMemoryValidationError(
130-
"tenant is required when access_strategy=SUBSCRIBER_ONLY"
130+
"tenant is required when access_strategy=SUBSCRIBER"
131+
)
132+
if effective_strategy is not AccessStrategy.SUBSCRIBER:
133+
logger.warning(
134+
"AccessStrategy.PROVIDER is active: no tenant isolation will be applied. "
135+
"Only use this strategy for provider-owned operations."
131136
)
132137
return (
133138
effective_tenant
134-
if effective_strategy is AccessStrategy.SUBSCRIBER_ONLY
139+
if effective_strategy is AccessStrategy.SUBSCRIBER
135140
else None
136141
)
137142

@@ -158,14 +163,14 @@ def add_memory(
158163
access_strategy: Tenant access strategy. Overrides the client default when
159164
provided. Falls back to the default set on :func:`create_client`.
160165
tenant: Subscriber tenant subdomain. Overrides the client default when
161-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
166+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
162167
163168
Returns:
164169
The created :class:`Memory`.
165170
166171
Raises:
167172
AgentMemoryValidationError: If any required field is empty or tenant is missing
168-
for ``SUBSCRIBER_ONLY``.
173+
for ``SUBSCRIBER``.
169174
AgentMemoryHttpError: If the request fails.
170175
"""
171176
_require_non_empty(agent_id=agent_id, invoker_id=invoker_id, content=content)
@@ -197,15 +202,15 @@ def get_memory(
197202
access_strategy: Tenant access strategy. Overrides the client default when
198203
provided. Falls back to the default set on :func:`create_client`.
199204
tenant: Subscriber tenant subdomain. Overrides the client default when
200-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
205+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
201206
202207
Returns:
203208
The :class:`Memory`.
204209
205210
Raises:
206211
AgentMemoryNotFoundError: If no memory with the given ID exists.
207212
AgentMemoryValidationError: If ``memory_id`` is empty or tenant is missing
208-
for ``SUBSCRIBER_ONLY``.
213+
for ``SUBSCRIBER``.
209214
AgentMemoryHttpError: If the request fails.
210215
"""
211216
_require_non_empty(memory_id=memory_id)
@@ -234,12 +239,12 @@ def update_memory(
234239
access_strategy: Tenant access strategy. Overrides the client default when
235240
provided. Falls back to the default set on :func:`create_client`.
236241
tenant: Subscriber tenant subdomain. Overrides the client default when
237-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
242+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
238243
239244
Raises:
240245
AgentMemoryNotFoundError: If no memory with the given ID exists.
241246
AgentMemoryValidationError: If ``memory_id`` is empty, no fields are provided,
242-
or tenant is missing for ``SUBSCRIBER_ONLY``.
247+
or tenant is missing for ``SUBSCRIBER``.
243248
AgentMemoryHttpError: If the request fails.
244249
"""
245250
_require_non_empty(memory_id=memory_id)
@@ -272,12 +277,12 @@ def delete_memory(
272277
access_strategy: Tenant access strategy. Overrides the client default when
273278
provided. Falls back to the default set on :func:`create_client`.
274279
tenant: Subscriber tenant subdomain. Overrides the client default when
275-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
280+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
276281
277282
Raises:
278283
AgentMemoryNotFoundError: If no memory with the given ID exists.
279284
AgentMemoryValidationError: If ``memory_id`` is empty or tenant is missing
280-
for ``SUBSCRIBER_ONLY``.
285+
for ``SUBSCRIBER``.
281286
AgentMemoryHttpError: If the request fails.
282287
"""
283288
_require_non_empty(memory_id=memory_id)
@@ -313,14 +318,14 @@ def list_memories(
313318
access_strategy: Tenant access strategy. Overrides the client default when
314319
provided. Falls back to the default set on :func:`create_client`.
315320
tenant: Subscriber tenant subdomain. Overrides the client default when
316-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
321+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
317322
318323
Returns:
319324
List of :class:`Memory` objects.
320325
321326
Raises:
322327
AgentMemoryValidationError: If ``limit`` < 1, ``offset`` < 0, a filter
323-
clause is invalid, or tenant is missing for ``SUBSCRIBER_ONLY``.
328+
clause is invalid, or tenant is missing for ``SUBSCRIBER``.
324329
AgentMemoryHttpError: If the request fails.
325330
"""
326331
if limit < 1:
@@ -362,13 +367,13 @@ def count_memories(
362367
access_strategy: Tenant access strategy. Overrides the client default when
363368
provided. Falls back to the default set on :func:`create_client`.
364369
tenant: Subscriber tenant subdomain. Overrides the client default when
365-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
370+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
366371
367372
Returns:
368373
Total number of matching memories.
369374
370375
Raises:
371-
AgentMemoryValidationError: If tenant is missing for ``SUBSCRIBER_ONLY``.
376+
AgentMemoryValidationError: If tenant is missing for ``SUBSCRIBER``.
372377
AgentMemoryHttpError: If the request fails.
373378
"""
374379
tenant_subdomain = self._resolve_tenant(access_strategy, tenant)
@@ -406,15 +411,15 @@ def search_memories(
406411
access_strategy: Tenant access strategy. Overrides the client default when
407412
provided. Falls back to the default set on :func:`create_client`.
408413
tenant: Subscriber tenant subdomain. Overrides the client default when
409-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
414+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
410415
411416
Returns:
412417
List of :class:`SearchResult` objects.
413418
414419
Raises:
415420
AgentMemoryValidationError: If required fields are empty, parameters are
416421
out of range (``query`` must be 5–5000 chars, ``threshold`` 0.0–1.0,
417-
``limit`` 1–50), or tenant is missing for ``SUBSCRIBER_ONLY``.
422+
``limit`` 1–50), or tenant is missing for ``SUBSCRIBER``.
418423
AgentMemoryHttpError: If the request fails.
419424
"""
420425
_require_non_empty(agent_id=agent_id, invoker_id=invoker_id, query=query)
@@ -470,14 +475,14 @@ def add_message(
470475
access_strategy: Tenant access strategy. Overrides the client default when
471476
provided. Falls back to the default set on :func:`create_client`.
472477
tenant: Subscriber tenant subdomain. Overrides the client default when
473-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
478+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
474479
475480
Returns:
476481
The created :class:`Message`.
477482
478483
Raises:
479484
AgentMemoryValidationError: If any required field is empty or tenant is missing
480-
for ``SUBSCRIBER_ONLY``.
485+
for ``SUBSCRIBER``.
481486
AgentMemoryHttpError: If the request fails.
482487
"""
483488
_require_non_empty(
@@ -516,15 +521,15 @@ def get_message(
516521
access_strategy: Tenant access strategy. Overrides the client default when
517522
provided. Falls back to the default set on :func:`create_client`.
518523
tenant: Subscriber tenant subdomain. Overrides the client default when
519-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
524+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
520525
521526
Returns:
522527
The :class:`Message`.
523528
524529
Raises:
525530
AgentMemoryNotFoundError: If no message with the given ID exists.
526531
AgentMemoryValidationError: If ``message_id`` is empty or tenant is missing
527-
for ``SUBSCRIBER_ONLY``.
532+
for ``SUBSCRIBER``.
528533
AgentMemoryHttpError: If the request fails.
529534
"""
530535
_require_non_empty(message_id=message_id)
@@ -549,12 +554,12 @@ def delete_message(
549554
access_strategy: Tenant access strategy. Overrides the client default when
550555
provided. Falls back to the default set on :func:`create_client`.
551556
tenant: Subscriber tenant subdomain. Overrides the client default when
552-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
557+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
553558
554559
Raises:
555560
AgentMemoryNotFoundError: If no message with the given ID exists.
556561
AgentMemoryValidationError: If ``message_id`` is empty or tenant is missing
557-
for ``SUBSCRIBER_ONLY``.
562+
for ``SUBSCRIBER``.
558563
AgentMemoryHttpError: If the request fails.
559564
"""
560565
_require_non_empty(message_id=message_id)
@@ -594,14 +599,14 @@ def list_messages(
594599
access_strategy: Tenant access strategy. Overrides the client default when
595600
provided. Falls back to the default set on :func:`create_client`.
596601
tenant: Subscriber tenant subdomain. Overrides the client default when
597-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
602+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
598603
599604
Returns:
600605
List of :class:`Message` objects.
601606
602607
Raises:
603608
AgentMemoryValidationError: If ``limit`` < 1, ``offset`` < 0, a filter
604-
clause is invalid, or tenant is missing for ``SUBSCRIBER_ONLY``.
609+
clause is invalid, or tenant is missing for ``SUBSCRIBER``.
605610
AgentMemoryHttpError: If the request fails.
606611
"""
607612
if limit < 1:
@@ -643,13 +648,13 @@ def get_retention_config(
643648
access_strategy: Tenant access strategy. Overrides the client default when
644649
provided. Falls back to the default set on :func:`create_client`.
645650
tenant: Subscriber tenant subdomain. Overrides the client default when
646-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
651+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
647652
648653
Returns:
649654
The current :class:`RetentionConfig`.
650655
651656
Raises:
652-
AgentMemoryValidationError: If tenant is missing for ``SUBSCRIBER_ONLY``.
657+
AgentMemoryValidationError: If tenant is missing for ``SUBSCRIBER``.
653658
AgentMemoryHttpError: If the request fails.
654659
"""
655660
tenant_subdomain = self._resolve_tenant(access_strategy, tenant)
@@ -679,11 +684,11 @@ def update_retention_config(
679684
access_strategy: Tenant access strategy. Overrides the client default when
680685
provided. Falls back to the default set on :func:`create_client`.
681686
tenant: Subscriber tenant subdomain. Overrides the client default when
682-
provided. Required (at call or client level) when strategy is ``SUBSCRIBER_ONLY``.
687+
provided. Required (at call or client level) when strategy is ``SUBSCRIBER``.
683688
684689
Raises:
685690
AgentMemoryValidationError: If no fields are provided, any provided value is
686-
negative, or tenant is missing for ``SUBSCRIBER_ONLY``.
691+
negative, or tenant is missing for ``SUBSCRIBER``.
687692
AgentMemoryHttpError: If the request fails.
688693
"""
689694
if message_days is None and memory_days is None and usage_log_days is None:

src/sap_cloud_sdk/agent_memory/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AgentMemoryConfig:
3636
client_id: The OAuth2 client ID. Optional.
3737
client_secret: The OAuth2 client secret. Optional.
3838
identityzone: The provider tenant identity zone subdomain. Required when using
39-
``SUBSCRIBER_ONLY`` access strategy so the subscriber token URL
39+
``SUBSCRIBER`` access strategy so the subscriber token URL
4040
can be derived by replacing this value in ``token_url``.
4141
timeout: Timeout in seconds for HTTP requests. Default is 30.0.
4242

0 commit comments

Comments
 (0)