Skip to content

Commit db9ba9b

Browse files
feat(agent-memory): configure access_strategy and tenant at client level
- create_client() and AgentMemoryClient.__init__ accept access_strategy (default SUBSCRIBER_ONLY) and tenant as constructor params - _resolve_tenant is now an instance method; per-call params override instance defaults - All method signatures change to Optional[AccessStrategy] = None (sentinel: use instance default) - user-guide: add client-level configuration section and PROVIDER_ONLY isolation warning - tests: update TestAccessStrategy and TestCreateClient for instance method
1 parent c9888b7 commit db9ba9b

5 files changed

Lines changed: 266 additions & 89 deletions

File tree

src/sap_cloud_sdk/agent_memory/__init__.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
66
Usage::
77
8-
from sap_cloud_sdk.agent_memory import create_client
8+
from sap_cloud_sdk.agent_memory import create_client, AccessStrategy
99
10-
client = create_client()
10+
# Subscriber tenant — strategy and tenant set once, inherited by all calls
11+
client = create_client(
12+
access_strategy=AccessStrategy.SUBSCRIBER_ONLY,
13+
tenant="my-tenant-subdomain",
14+
)
1115
memories = client.list_memories(agent_id="my-agent", invoker_id="user-123")
1216
"""
1317

@@ -34,25 +38,41 @@
3438
from sap_cloud_sdk.agent_memory.utils._odata import FilterDefinition
3539

3640

37-
def create_client(*, config: Optional[AgentMemoryConfig] = None) -> AgentMemoryClient:
41+
def create_client(
42+
*,
43+
config: Optional[AgentMemoryConfig] = None,
44+
access_strategy: AccessStrategy = AccessStrategy.SUBSCRIBER_ONLY,
45+
tenant: Optional[str] = None,
46+
) -> AgentMemoryClient:
3847
"""Create an :class:`AgentMemoryClient` with automatic credential detection.
3948
4049
Args:
4150
config: Optional explicit configuration. If ``None``, credentials are
4251
loaded from the mounted volume at
4352
``/etc/secrets/appfnd/hana-agent-memory/default/`` or from
4453
``CLOUD_SDK_CFG_AGENT_MEMORY_DEFAULT_*`` environment variables.
54+
access_strategy: Default tenant access strategy for all client operations.
55+
Defaults to ``SUBSCRIBER_ONLY``. Individual method calls may override
56+
this value.
57+
tenant: Default subscriber tenant subdomain. Required when
58+
``access_strategy=SUBSCRIBER_ONLY``. Individual method calls may
59+
override this value.
4560
4661
Returns:
4762
A ready-to-use :class:`AgentMemoryClient`.
4863
4964
Raises:
50-
AgentMemoryConfigError: If configuration is missing or invalid.
65+
AgentMemoryConfigError: If configuration is missing, invalid, or
66+
``access_strategy=SUBSCRIBER_ONLY`` is used without a ``tenant``.
5167
"""
5268
try:
5369
resolved_config = config if config is not None else _load_config_from_env()
5470
transport = HttpTransport(resolved_config)
55-
return AgentMemoryClient(transport)
71+
return AgentMemoryClient(
72+
transport,
73+
access_strategy=access_strategy,
74+
tenant=tenant,
75+
)
5676
except AgentMemoryConfigError:
5777
raise
5878
except Exception as exc:

0 commit comments

Comments
 (0)