Skip to content

Commit 86febef

Browse files
foleydangclaude
andcommitted
feat(agentstudio): session mount fields for bailian memory and oss
Mount/SessionResource cover provider/entity_id/project_ids/profile_schema (bailian memory) and region/bucket/oss_path (oss); resources entries accept Mount objects or raw mappings via the ResourceInput alias. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9d82fbd commit 86febef

5 files changed

Lines changed: 203 additions & 21 deletions

File tree

‎dashscope/applications/agentstudio/resources/sessions.py‎

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
SessionThreads,
2727
AsyncSessionThreads,
2828
)
29-
from dashscope.applications.agentstudio.types import DeleteResponse, Session
29+
from dashscope.applications.agentstudio.types import (
30+
DeleteResponse,
31+
ResourceInput,
32+
Session,
33+
)
3034
from dashscope.applications.agentstudio.types.params import (
3135
SessionCreateParams,
3236
SessionListParams,
@@ -52,12 +56,31 @@ def create(
5256
agent: Any,
5357
environment_id: Optional[str] = None,
5458
title: Optional[str] = None,
55-
resources: Optional[Sequence[Mapping[str, Any]]] = None,
59+
resources: Optional[Sequence[ResourceInput]] = None,
5660
vault_ids: Optional[Sequence[str]] = None,
5761
environment_variables: Optional[Mapping[str, str]] = None,
5862
mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
5963
metadata: Optional[Mapping[str, Any]] = None,
6064
) -> Session:
65+
"""Create a session (``POST /sessions``).
66+
67+
``agent`` is the Agent id string or an
68+
``{"type": "agent_with_overrides", ...}`` mapping. ``resources``
69+
entries are wire-format mappings (or
70+
:class:`~dashscope.agentstudio.types.Mount` objects, which
71+
serialize to the same mappings)::
72+
73+
client.sessions.create(
74+
agent=agent_id,
75+
resources=[
76+
{"type": "memory_store", "memory_store_id": store_id,
77+
"access": "read_write"},
78+
{"type": "oss", "region": "cn-beijing", "bucket": "bkt",
79+
"oss_path": "datasets/", "mount_path": "/data",
80+
"access": "read_only"},
81+
],
82+
)
83+
"""
6184
body = SessionCreateParams(
6285
agent=agent,
6386
environment_id=environment_id,
@@ -191,12 +214,31 @@ async def create(
191214
agent: Any,
192215
environment_id: Optional[str] = None,
193216
title: Optional[str] = None,
194-
resources: Optional[Sequence[Mapping[str, Any]]] = None,
217+
resources: Optional[Sequence[ResourceInput]] = None,
195218
vault_ids: Optional[Sequence[str]] = None,
196219
environment_variables: Optional[Mapping[str, str]] = None,
197220
mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
198221
metadata: Optional[Mapping[str, Any]] = None,
199222
) -> Session:
223+
"""Create a session (``POST /sessions``).
224+
225+
``agent`` is the Agent id string or an
226+
``{"type": "agent_with_overrides", ...}`` mapping. ``resources``
227+
entries are wire-format mappings (or
228+
:class:`~dashscope.agentstudio.types.Mount` objects, which
229+
serialize to the same mappings)::
230+
231+
client.sessions.create(
232+
agent=agent_id,
233+
resources=[
234+
{"type": "memory_store", "memory_store_id": store_id,
235+
"access": "read_write"},
236+
{"type": "oss", "region": "cn-beijing", "bucket": "bkt",
237+
"oss_path": "datasets/", "mount_path": "/data",
238+
"access": "read_only"},
239+
],
240+
)
241+
"""
200242
body = SessionCreateParams(
201243
agent=agent,
202244
environment_id=environment_id,

‎dashscope/applications/agentstudio/types/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Scope,
1212
Mount,
1313
Networking,
14+
ResourceInput,
1415
Packages,
1516
EnvironmentConfig,
1617
StopReason,

‎dashscope/applications/agentstudio/types/models.py‎

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,36 +131,68 @@ class Scope(BaseModel):
131131
class Mount(BaseModel):
132132
"""Session resource mount descriptor (create-time input on POST /sessions)."""
133133

134-
_fields = ("type", "file_id", "skill_id", "mount_path")
134+
_fields = (
135+
"type",
136+
"file_id",
137+
"skill_id",
138+
"mount_path",
139+
"memory_store_id",
140+
"provider",
141+
"entity_id",
142+
"project_ids",
143+
"profile_schema",
144+
"description",
145+
"access",
146+
"instructions",
147+
"region",
148+
"bucket",
149+
"oss_path",
150+
)
151+
152+
153+
# One resources[] entry on POST /sessions: a raw wire-format mapping
154+
# (dict) or a typed Mount object.
155+
ResourceInput = Union[Mapping[str, Any], Mount]
135156

136157

137158
class SessionResource(BaseModel):
138-
"""A resource mounted into a session at runtime.
139-
140-
The response ``file_id`` is the session-scoped copy id — **not** the
141-
source file id passed at mount time. ``mount_path`` is the absolute
142-
sandbox path (the server prepends a prefix; the user-supplied path is
143-
preserved losslessly and must be under ``/uploads/``).
144-
145-
For ``type="memory_store"`` resources the memory-specific fields
146-
apply: ``memory_store_id`` (the attached store), ``access``
147-
(``read_write`` default / ``read_only``), ``instructions``
148-
(per-session guidance, <= 4096 chars) and the server-snapshotted
149-
``name``/``description`` of the store at attach time. Memory
150-
stores can only be attached at session creation time —
151-
``sessions.resources.add`` accepts files only.
159+
"""A resource mounted into a session (file / memory_store / oss).
160+
161+
``file``: ``file_id`` is the session-scoped copy id (not the source
162+
file id); ``mount_path`` resolves under ``/uploads/``. Memory and
163+
OSS mounts are create-only — ``sessions.resources.add`` accepts
164+
files only.
165+
166+
``memory_store``: ``access`` (``read_write`` default) and
167+
``instructions``; ``name``/``description`` are server-snapshotted
168+
for built-in (``provider="default"``) mounts, which also carry the
169+
server-generated ``mount_path`` (``/mnt/memory/<name>``);
170+
``agentstudio_memory`` (Bailian) mounts echo ``entity_id`` and the
171+
configured ``project_ids``/``profile_schema``/``description``, with
172+
no ``mount_path``.
173+
174+
``oss``: echoes ``region``/``bucket``/``oss_path`` and the
175+
user-supplied logical ``mount_path`` (the sandbox resolves it under
176+
``/mnt/oss/``).
152177
"""
153178

154179
_fields = (
155180
"id",
156181
"type",
157182
"file_id",
158183
"memory_store_id",
184+
"provider",
185+
"entity_id",
186+
"project_ids",
187+
"profile_schema",
159188
"access",
160189
"instructions",
161190
"name",
162191
"description",
163192
"mount_path",
193+
"region",
194+
"bucket",
195+
"oss_path",
164196
"created_at",
165197
"updated_at",
166198
"request_id",

‎dashscope/applications/agentstudio/types/params.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from dashscope.applications.agentstudio.types.models import (
2222
BaseModel,
2323
ModelConfig,
24+
ResourceInput,
2425
)
2526

2627
_NOT_GIVEN = object()
@@ -288,7 +289,10 @@ class SessionCreateParams(BaseModel):
288289
289290
``environment_variables`` and ``mcp_configs`` are Session-level
290291
settings independent of the agent. ``resources`` is create-only — it
291-
cannot be modified via ``updateSession``.
292+
cannot be modified via ``updateSession``; each item is a mapping or
293+
a :class:`~dashscope.applications.agentstudio.types.models.Mount`
294+
(``file`` / ``memory_store`` — built-in or Bailian
295+
``provider="agentstudio_memory"`` — / ``oss``).
292296
"""
293297

294298
_fields = (
@@ -308,7 +312,7 @@ def __init__( # pylint: disable=useless-parent-delegation
308312
agent: Any,
309313
environment_id: Optional[str] = None,
310314
title: Optional[str] = None,
311-
resources: Optional[Sequence[Mapping[str, Any]]] = None,
315+
resources: Optional[Sequence[ResourceInput]] = None,
312316
vault_ids: Optional[Sequence[str]] = None,
313317
environment_variables: Optional[Mapping[str, str]] = None,
314318
mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
@@ -319,7 +323,9 @@ def __init__( # pylint: disable=useless-parent-delegation
319323
environment_id=environment_id,
320324
title=title,
321325
resources=(
322-
[dict(r) for r in resources] if resources is not None else None
326+
[_to_mapping(r) for r in resources]
327+
if resources is not None
328+
else None
323329
),
324330
vault_ids=(list(vault_ids) if vault_ids is not None else None),
325331
environment_variables=(

‎tests/test_agentstudio_models.py‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from dashscope.agentstudio.types import (
1111
Agent,
1212
Credential,
13+
Mount,
14+
SessionResource,
1315
CredentialAuth,
1416
DeleteResponse,
1517
Environment,
@@ -323,3 +325,102 @@ def test_file_model_fields():
323325
assert f.size_bytes == 1024
324326
assert f.status == "checking"
325327
assert f.downloadable is None # not set
328+
329+
330+
# ---------------------------------------------------------------------------
331+
# Session mounts (Mount input / SessionResource echo)
332+
# ---------------------------------------------------------------------------
333+
334+
335+
def test_mount_fields_roundtrip():
336+
mount = Mount(
337+
type="memory_store",
338+
provider="agentstudio_memory",
339+
memory_store_id="d7e534ca0e7d4fa8a4f4b079d314df3e",
340+
entity_id="customer_001",
341+
project_ids=["fact_rule_1", "skill_rule_1"],
342+
profile_schema="7dfdc775eee5422dad37957e5ccf0081",
343+
description="客户记忆",
344+
access="read_only",
345+
)
346+
d = mount.to_dict()
347+
assert d["type"] == "memory_store"
348+
assert d["provider"] == "agentstudio_memory"
349+
assert d["entity_id"] == "customer_001"
350+
assert d["project_ids"] == ["fact_rule_1", "skill_rule_1"]
351+
assert d["profile_schema"] == "7dfdc775eee5422dad37957e5ccf0081"
352+
assert d["description"] == "客户记忆"
353+
assert d["access"] == "read_only"
354+
355+
oss = Mount(
356+
type="oss",
357+
region="cn-beijing",
358+
bucket="agentstudio-ma-oss-mnt",
359+
oss_path="datasets/",
360+
mount_path="/data",
361+
).to_dict()
362+
assert oss == {
363+
"type": "oss",
364+
"region": "cn-beijing",
365+
"bucket": "agentstudio-ma-oss-mnt",
366+
"oss_path": "datasets/",
367+
"mount_path": "/data",
368+
}
369+
370+
371+
def test_session_resource_memory_oss_fields():
372+
r = SessionResource.from_dict(
373+
{
374+
"id": "sesrsc_1",
375+
"type": "memory_store",
376+
"provider": "agentstudio_memory",
377+
"memory_store_id": "d7e534ca0e7d4fa8a4f4b079d314df3e",
378+
"entity_id": "customer_001",
379+
"project_ids": ["fact_rule_1"],
380+
"profile_schema": "schema_demo",
381+
},
382+
)
383+
assert r.provider == "agentstudio_memory"
384+
assert r.entity_id == "customer_001"
385+
assert r.project_ids == ["fact_rule_1"]
386+
assert r.profile_schema == "schema_demo"
387+
assert r.mount_path is None
388+
389+
o = SessionResource.from_dict(
390+
{
391+
"id": "sesrsc_2",
392+
"type": "oss",
393+
"region": "cn-beijing",
394+
"bucket": "agentstudio-ma-oss-mnt",
395+
"oss_path": "datasets/",
396+
"mount_path": "/data",
397+
},
398+
)
399+
assert o.region == "cn-beijing"
400+
assert o.bucket == "agentstudio-ma-oss-mnt"
401+
assert o.oss_path == "datasets/"
402+
assert o.mount_path == "/data"
403+
404+
405+
def test_session_create_resources_accept_mount_and_dict():
406+
from dashscope.agentstudio.types.params import SessionCreateParams
407+
408+
mount = Mount(
409+
type="oss",
410+
region="cn-beijing",
411+
bucket="bkt",
412+
mount_path="/data",
413+
)
414+
body = SessionCreateParams(
415+
agent={"type": "agent", "id": "agent_1"},
416+
resources=[mount, {"type": "file", "file_id": "file_1"}],
417+
).to_dict()
418+
assert body["resources"] == [
419+
{
420+
"type": "oss",
421+
"region": "cn-beijing",
422+
"bucket": "bkt",
423+
"mount_path": "/data",
424+
},
425+
{"type": "file", "file_id": "file_1"},
426+
]

0 commit comments

Comments
 (0)