Skip to content

AgentStudio

dashscope.applications.agentstudio is the sub-SDK for the AgentStudio managed-agent API: agents, sessions, events, environments, deployments, memory, skills, vaults, security and webhooks. All resources are reached through its own client:

from dashscope.applications.agentstudio import Client
from dashscope.applications.agentstudio import user_message

client = Client(api_key="sk-xxx")
agent = client.agents.create(name="demo", model="qwen-plus")
session = client.sessions.create(agent=agent.id)
client.sessions.events.send(session.id, [user_message("Hello!")])
with client.sessions.events.stream(session.id) as stream:
    for event in stream:
        print(event.type)
        # session_status may also report running; stop only on a terminal state
        if event.session_status in ("idle", "terminated"):
            break

Session status and text consumption

A session_status event may report running (still working) as well as terminal states such as idle / terminated — do not treat the first session_status as the end of the run. When you only need the text reply, use stream.text_stream: it yields the text of agent messages and stops automatically once the session reaches a terminal state. If the agent uses tools that require approval, the session pauses at idle with stop_reason.type == "requires_action"; submit the decision with user_tool_approval_response and the session resumes.

Every resource class has an async twin (AsyncAgents, AsyncSessions, ...) used the same way through AsyncClient.

Clients

Client

Client(
    *,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
    region: Optional[str] = None,
    base_url: Optional[str] = None,
    uid: Optional[str] = None,
    timeout: Optional[
        Union[float, Timeout, Tuple[float, float]]
    ] = None,
    max_retries: int = AGENTSTUDIO_MAX_RETRIES,
    http_client: Optional[Client] = None,
    _exceptions_module: Any = _default_exceptions,
    _api_key_resolver: Any = _default_api_key,
    _transport_cls: Any = SyncTransport,
    _event_stream_cls: Any = EventStream
)

Synchronous AgentStudio client.

Usage::

from dashscope.applications.agentstudio import Client, ModelConfig

client = Client(api_key="sk-xxx", workspace="my-ws")
agent = client.agents.create(
    name="demo",
    model=ModelConfig(
        id="qwen-max",
        temperature=0.7,
        enable_thinking=True,
        thinking_budget=2048,
    ),
)
session = client.sessions.create(agent=agent.id)
with client.sessions.events.stream(session.id) as stream:
    for event in stream:
        print(event.type)
Source code in dashscope/applications/agentstudio/client.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def __init__(
    self,
    *,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
    region: Optional[str] = None,
    base_url: Optional[str] = None,
    uid: Optional[str] = None,
    timeout: Optional[
        Union[float, httpx.Timeout, Tuple[float, float]]
    ] = None,
    max_retries: int = AGENTSTUDIO_MAX_RETRIES,
    http_client: Optional[httpx.Client] = None,
    _exceptions_module: Any = _default_exceptions,
    _api_key_resolver: Any = _default_api_key,
    _transport_cls: Any = SyncTransport,
    _event_stream_cls: Any = EventStream,
) -> None:
    resolved_workspace = workspace or os.environ.get("DASHSCOPE_WORKSPACE")
    resolved_base = _resolve_base_url(
        base_url,
        resolved_workspace,
        region,
    )
    self._event_stream_cls = _event_stream_cls
    self.transport = _transport_cls(
        base_url=resolved_base,
        api_key=api_key or _api_key_resolver(),
        workspace=resolved_workspace,
        uid=uid or os.environ.get("DASHSCOPE_UID"),
        user_agent=_user_agent(resolved_base),
        timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
        max_retries=max_retries,
        http_client=http_client,
        exceptions_module=_exceptions_module,
    )
    self.agents = Agents(self)
    self.deployments = Deployments(self)
    self.deployment_runs = DeploymentRuns(self)
    self.sessions = Sessions(self)
    self.environments = Environments(self)
    self.files = Files(self)
    self.skills = Skills(self)
    self.vaults = Vaults(self)
    self.memory_stores = MemoryStores(self)
    self.webhook_endpoints = WebhookEndpoints(self)
    self.security = Security(self)
    self.usage = Usage(self)

transport instance-attribute

transport = _transport_cls(
    base_url=resolved_base,
    api_key=api_key or _api_key_resolver(),
    workspace=resolved_workspace,
    uid=uid or os.environ.get("DASHSCOPE_UID"),
    user_agent=_user_agent(resolved_base),
    timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
    max_retries=max_retries,
    http_client=http_client,
    exceptions_module=_exceptions_module,
)

agents instance-attribute

agents = Agents(self)

deployments instance-attribute

deployments = Deployments(self)

deployment_runs instance-attribute

deployment_runs = DeploymentRuns(self)

sessions instance-attribute

sessions = Sessions(self)

environments instance-attribute

environments = Environments(self)

files instance-attribute

files = Files(self)

skills instance-attribute

skills = Skills(self)

vaults instance-attribute

vaults = Vaults(self)

memory_stores instance-attribute

memory_stores = MemoryStores(self)

webhook_endpoints instance-attribute

webhook_endpoints = WebhookEndpoints(self)

security instance-attribute

security = Security(self)

usage instance-attribute

usage = Usage(self)

close

close() -> None
Source code in dashscope/applications/agentstudio/client.py
222
223
def close(self) -> None:
    self.transport.close()

AsyncClient

AsyncClient(
    *,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
    region: Optional[str] = None,
    base_url: Optional[str] = None,
    uid: Optional[str] = None,
    timeout: Optional[
        Union[float, Timeout, Tuple[float, float]]
    ] = None,
    max_retries: int = AGENTSTUDIO_MAX_RETRIES,
    http_client: Optional[AsyncClient] = None,
    _exceptions_module: Any = _default_exceptions,
    _api_key_resolver: Any = _default_api_key,
    _transport_cls: Any = AsyncTransport,
    _event_stream_cls: Any = AsyncEventStream
)

Asynchronous AgentStudio client.

Usage::

from dashscope.applications.agentstudio import AsyncClient, ModelConfig

client = AsyncClient(api_key="sk-xxx", workspace="my-ws")
agent = await client.agents.create(
    name="demo",
    model=ModelConfig(id="qwen-max", max_tokens=4096),
)
session = await client.sessions.create(agent=agent.id)
async with client.sessions.events.stream(session.id) as stream:
    async for event in stream:
        print(event.type)
Source code in dashscope/applications/agentstudio/client.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def __init__(
    self,
    *,
    api_key: Optional[str] = None,
    workspace: Optional[str] = None,
    region: Optional[str] = None,
    base_url: Optional[str] = None,
    uid: Optional[str] = None,
    timeout: Optional[
        Union[float, httpx.Timeout, Tuple[float, float]]
    ] = None,
    max_retries: int = AGENTSTUDIO_MAX_RETRIES,
    http_client: Optional[httpx.AsyncClient] = None,
    _exceptions_module: Any = _default_exceptions,
    _api_key_resolver: Any = _default_api_key,
    _transport_cls: Any = AsyncTransport,
    _event_stream_cls: Any = AsyncEventStream,
) -> None:
    resolved_workspace = workspace or os.environ.get("DASHSCOPE_WORKSPACE")
    resolved_base = _resolve_base_url(
        base_url,
        resolved_workspace,
        region,
    )
    self._event_stream_cls = _event_stream_cls
    self.transport = _transport_cls(
        base_url=resolved_base,
        api_key=api_key or _api_key_resolver(),
        workspace=resolved_workspace,
        uid=uid or os.environ.get("DASHSCOPE_UID"),
        user_agent=_user_agent(resolved_base),
        timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
        max_retries=max_retries,
        http_client=http_client,
        exceptions_module=_exceptions_module,
    )
    self.agents = AsyncAgents(self)
    self.deployments = AsyncDeployments(self)
    self.deployment_runs = AsyncDeploymentRuns(self)
    self.sessions = AsyncSessions(self)
    self.environments = AsyncEnvironments(self)
    self.files = AsyncFiles(self)
    self.skills = AsyncSkills(self)
    self.vaults = AsyncVaults(self)
    self.memory_stores = AsyncMemoryStores(self)
    self.webhook_endpoints = AsyncWebhookEndpoints(self)
    self.security = AsyncSecurity(self)
    self.usage = AsyncUsage(self)

transport instance-attribute

transport = _transport_cls(
    base_url=resolved_base,
    api_key=api_key or _api_key_resolver(),
    workspace=resolved_workspace,
    uid=uid or os.environ.get("DASHSCOPE_UID"),
    user_agent=_user_agent(resolved_base),
    timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
    max_retries=max_retries,
    http_client=http_client,
    exceptions_module=_exceptions_module,
)

agents instance-attribute

agents = AsyncAgents(self)

deployments instance-attribute

deployments = AsyncDeployments(self)

deployment_runs instance-attribute

deployment_runs = AsyncDeploymentRuns(self)

sessions instance-attribute

sessions = AsyncSessions(self)

environments instance-attribute

environments = AsyncEnvironments(self)

files instance-attribute

files = AsyncFiles(self)

skills instance-attribute

skills = AsyncSkills(self)

vaults instance-attribute

vaults = AsyncVaults(self)

memory_stores instance-attribute

memory_stores = AsyncMemoryStores(self)

webhook_endpoints instance-attribute

webhook_endpoints = AsyncWebhookEndpoints(self)

security instance-attribute

security = AsyncSecurity(self)

usage instance-attribute

usage = AsyncUsage(self)

aclose async

aclose() -> None
Source code in dashscope/applications/agentstudio/client.py
305
306
async def aclose(self) -> None:
    await self.transport.aclose()

Agents & sessions

Agents

Agents(client)

Agent CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/agents.py
36
37
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create

create(
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def create(
    self,
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Agent:
    body = AgentCreateParams(
        name=name,
        model=model,
        description=description,
        system_prompt=system_prompt,
        tools=tools,
        mcp_servers=mcp_servers,
        skills=skills,
        multiagent=multiagent,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request("POST", _PATH_AGENTS, json=body)
    return _coerce_agent(resp.data)

retrieve

retrieve(
    agent_id: str, *, version: Optional[int] = None
) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
66
67
68
69
70
71
72
73
74
75
76
77
78
def retrieve(
    self,
    agent_id: str,
    *,
    version: Optional[int] = None,
) -> Agent:
    params = {"version": version} if version is not None else None
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_AGENTS}/{agent_id}",
        params=params,
    )
    return _coerce_agent(resp.data)

update

update(
    agent_id: str,
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Agent

Update the latest version of an agent.

version must equal the server's current version; the server rejects mismatches with HTTP 409. Retrieve the agent first to obtain the current version. name is required too (AGENT_005 without it).

Source code in dashscope/applications/agentstudio/resources/agents.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def update(
    self,
    agent_id: str,
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Agent:
    """Update the latest version of an agent.

    ``version`` must equal the server's current version;
    the server rejects mismatches with HTTP 409.
    Retrieve the agent first to obtain the current version.
    ``name`` is required too (``AGENT_005`` without it).
    """
    body = AgentUpdateParams(
        version=version,
        name=name,
        model=model,
        description=description,
        system_prompt=system_prompt,
        tools=tools,
        mcp_servers=mcp_servers,
        skills=skills,
        multiagent=multiagent,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_AGENTS}/{agent_id}",
        json=body,
    )
    return _coerce_agent(resp.data)

archive

archive(agent_id: str) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
127
128
129
130
131
132
def archive(self, agent_id: str) -> Agent:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_AGENTS}/{agent_id}/archive",
    )
    return _coerce_agent(resp.data)

list

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None
) -> CursorPage[Agent]
Source code in dashscope/applications/agentstudio/resources/agents.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None,
) -> CursorPage[Agent]:
    params = AgentListParams(
        limit=limit,
        page=page,
        include_archived=include_archived,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_AGENTS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_agent,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            limit=limit,
            page=nxt,
            include_archived=include_archived,
        ),
    )

list_versions

list_versions(
    agent_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[AgentVersion]
Source code in dashscope/applications/agentstudio/resources/agents.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def list_versions(
    self,
    agent_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[AgentVersion]:
    params = AgentVersionListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_AGENTS}/{agent_id}/versions",
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_agent_version,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list_versions(
            agent_id,
            limit=limit,
            page=nxt,
        ),
    )

AsyncAgents

AsyncAgents(client)

Async Agent CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/agents.py
190
191
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create async

create(
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
async def create(
    self,
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Agent:
    body = AgentCreateParams(
        name=name,
        model=model,
        description=description,
        system_prompt=system_prompt,
        tools=tools,
        mcp_servers=mcp_servers,
        skills=skills,
        multiagent=multiagent,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_AGENTS,
        json=body,
    )
    return _coerce_agent(resp.data)

retrieve async

retrieve(
    agent_id: str, *, version: Optional[int] = None
) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
224
225
226
227
228
229
230
231
232
233
234
235
236
async def retrieve(
    self,
    agent_id: str,
    *,
    version: Optional[int] = None,
) -> Agent:
    params = {"version": version} if version is not None else None
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_AGENTS}/{agent_id}",
        params=params,
    )
    return _coerce_agent(resp.data)

update async

update(
    agent_id: str,
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Agent

Update the latest version of an agent.

version must equal the server's current version; the server rejects mismatches with HTTP 409. Retrieve the agent first to obtain the current version. name is required too (AGENT_005 without it).

Source code in dashscope/applications/agentstudio/resources/agents.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
async def update(
    self,
    agent_id: str,
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Agent:
    """Update the latest version of an agent.

    ``version`` must equal the server's current version;
    the server rejects mismatches with HTTP 409.
    Retrieve the agent first to obtain the current version.
    ``name`` is required too (``AGENT_005`` without it).
    """
    body = AgentUpdateParams(
        version=version,
        name=name,
        model=model,
        description=description,
        system_prompt=system_prompt,
        tools=tools,
        mcp_servers=mcp_servers,
        skills=skills,
        multiagent=multiagent,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_AGENTS}/{agent_id}",
        json=body,
    )
    return _coerce_agent(resp.data)

archive async

archive(agent_id: str) -> Agent
Source code in dashscope/applications/agentstudio/resources/agents.py
285
286
287
288
289
290
async def archive(self, agent_id: str) -> Agent:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_AGENTS}/{agent_id}/archive",
    )
    return _coerce_agent(resp.data)

list async

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None
) -> AsyncCursorPage[Agent]
Source code in dashscope/applications/agentstudio/resources/agents.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
async def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None,
) -> AsyncCursorPage[Agent]:
    params = AgentListParams(
        limit=limit,
        page=page,
        include_archived=include_archived,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_AGENTS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Agent]:
        return await self.list(
            limit=limit,
            page=nxt,
            include_archived=include_archived,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_agent,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

list_versions async

list_versions(
    agent_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[AgentVersion]
Source code in dashscope/applications/agentstudio/resources/agents.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
async def list_versions(
    self,
    agent_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[AgentVersion]:
    params = AgentVersionListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_AGENTS}/{agent_id}/versions",
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[AgentVersion]:
        return await self.list_versions(
            agent_id,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_agent_version,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

Sessions

Sessions(client)

Session CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/sessions.py
47
48
49
50
51
def __init__(self, client) -> None:
    self._client = client
    self.events = SessionEvents(client)
    self.resources = SessionResources(client)
    self.threads = SessionThreads(client)

events instance-attribute

events = SessionEvents(client)

resources instance-attribute

resources = SessionResources(client)

threads instance-attribute

threads = SessionThreads(client)

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create

create(
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Session

Create a session (POST /sessions).

agent is the Agent id string or an {"type": "agent_with_overrides", ...} mapping. resources entries are wire-format mappings (or :class:~dashscope.agentstudio.types.Mount objects, which serialize to the same mappings)::

client.sessions.create(
    agent=agent_id,
    resources=[
        {"type": "memory_store", "memory_store_id": store_id,
         "access": "read_write"},
        {"type": "oss", "region": "cn-beijing", "bucket": "bkt",
         "oss_path": "datasets/", "mount_path": "/data",
         "access": "read_only"},
    ],
)
Source code in dashscope/applications/agentstudio/resources/sessions.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def create(
    self,
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Session:
    """Create a session (``POST /sessions``).

    ``agent`` is the Agent id string or an
    ``{"type": "agent_with_overrides", ...}`` mapping. ``resources``
    entries are wire-format mappings (or
    :class:`~dashscope.agentstudio.types.Mount` objects, which
    serialize to the same mappings)::

        client.sessions.create(
            agent=agent_id,
            resources=[
                {"type": "memory_store", "memory_store_id": store_id,
                 "access": "read_write"},
                {"type": "oss", "region": "cn-beijing", "bucket": "bkt",
                 "oss_path": "datasets/", "mount_path": "/data",
                 "access": "read_only"},
            ],
        )
    """
    body = SessionCreateParams(
        agent=agent,
        environment_id=environment_id,
        title=title,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        mcp_configs=mcp_configs,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _PATH_SESSIONS,
        json=body,
    )
    return _coerce_session(resp.data)

retrieve

retrieve(session_id: str) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
101
102
103
104
105
106
def retrieve(self, session_id: str) -> Session:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_SESSIONS}/{session_id}",
    )
    return _coerce_session(resp.data)

update

update(
    session_id: str,
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    agent: Any = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None
) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def update(
    self,
    session_id: str,
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    agent: Any = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
) -> Session:
    body = SessionUpdateParams(
        title=title,
        metadata=metadata,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        agent=agent,
        mcp_configs=mcp_configs,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_SESSIONS}/{session_id}",
        json=body,
    )
    return _coerce_session(resp.data)

list

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    agent_id: Optional[str] = None,
    statuses: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None
) -> CursorPage[Session]
Source code in dashscope/applications/agentstudio/resources/sessions.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    agent_id: Optional[str] = None,
    statuses: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
) -> CursorPage[Session]:
    params = SessionListParams(
        limit=limit,
        page=page,
        agent_id=agent_id,
        statuses=statuses,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_SESSIONS,
        params=params,
    )

    def fetch_next(nxt: str) -> CursorPage[Session]:
        return self.list(
            limit=limit,
            page=nxt,
            agent_id=agent_id,
            statuses=statuses,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session,
        request_id=resp.request_id,
        fetch_next=fetch_next,
    )

archive

archive(session_id: str) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
187
188
189
190
191
192
def archive(self, session_id: str) -> Session:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_SESSIONS}/{session_id}/archive",
    )
    return _coerce_session(resp.data)

delete

delete(session_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/sessions.py
194
195
196
197
198
199
def delete(self, session_id: str) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_SESSIONS}/{session_id}",
    )
    return DeleteResponse(**resp.data)

AsyncSessions

AsyncSessions(client)

Async Session CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/sessions.py
205
206
207
208
209
def __init__(self, client) -> None:
    self._client = client
    self.events = AsyncSessionEvents(client)
    self.resources = AsyncSessionResources(client)
    self.threads = AsyncSessionThreads(client)

events instance-attribute

events = AsyncSessionEvents(client)

resources instance-attribute

resources = AsyncSessionResources(client)

threads instance-attribute

threads = AsyncSessionThreads(client)

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create async

create(
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Session

Create a session (POST /sessions).

agent is the Agent id string or an {"type": "agent_with_overrides", ...} mapping. resources entries are wire-format mappings (or :class:~dashscope.agentstudio.types.Mount objects, which serialize to the same mappings)::

client.sessions.create(
    agent=agent_id,
    resources=[
        {"type": "memory_store", "memory_store_id": store_id,
         "access": "read_write"},
        {"type": "oss", "region": "cn-beijing", "bucket": "bkt",
         "oss_path": "datasets/", "mount_path": "/data",
         "access": "read_only"},
    ],
)
Source code in dashscope/applications/agentstudio/resources/sessions.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
async def create(
    self,
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Session:
    """Create a session (``POST /sessions``).

    ``agent`` is the Agent id string or an
    ``{"type": "agent_with_overrides", ...}`` mapping. ``resources``
    entries are wire-format mappings (or
    :class:`~dashscope.agentstudio.types.Mount` objects, which
    serialize to the same mappings)::

        client.sessions.create(
            agent=agent_id,
            resources=[
                {"type": "memory_store", "memory_store_id": store_id,
                 "access": "read_write"},
                {"type": "oss", "region": "cn-beijing", "bucket": "bkt",
                 "oss_path": "datasets/", "mount_path": "/data",
                 "access": "read_only"},
            ],
        )
    """
    body = SessionCreateParams(
        agent=agent,
        environment_id=environment_id,
        title=title,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        mcp_configs=mcp_configs,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_SESSIONS,
        json=body,
    )
    return _coerce_session(resp.data)

retrieve async

retrieve(session_id: str) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
259
260
261
262
263
264
async def retrieve(self, session_id: str) -> Session:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_SESSIONS}/{session_id}",
    )
    return _coerce_session(resp.data)

update async

update(
    session_id: str,
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    agent: Any = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None
) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
async def update(
    self,
    session_id: str,
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    agent: Any = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
) -> Session:
    body = SessionUpdateParams(
        title=title,
        metadata=metadata,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        agent=agent,
        mcp_configs=mcp_configs,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_SESSIONS}/{session_id}",
        json=body,
    )
    return _coerce_session(resp.data)

list async

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    agent_id: Optional[str] = None,
    statuses: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None
) -> AsyncCursorPage[Session]
Source code in dashscope/applications/agentstudio/resources/sessions.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
async def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    agent_id: Optional[str] = None,
    statuses: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
) -> AsyncCursorPage[Session]:
    params = SessionListParams(
        limit=limit,
        page=page,
        agent_id=agent_id,
        statuses=statuses,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_SESSIONS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Session]:
        return await self.list(
            limit=limit,
            page=nxt,
            agent_id=agent_id,
            statuses=statuses,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

archive async

archive(session_id: str) -> Session
Source code in dashscope/applications/agentstudio/resources/sessions.py
346
347
348
349
350
351
async def archive(self, session_id: str) -> Session:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_SESSIONS}/{session_id}/archive",
    )
    return _coerce_session(resp.data)

delete async

delete(session_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/sessions.py
353
354
355
356
357
358
async def delete(self, session_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_SESSIONS}/{session_id}",
    )
    return DeleteResponse(**resp.data)

SessionEvents

SessionEvents(client)

Session event send / list / stream.

Source code in dashscope/applications/agentstudio/resources/session_events.py
66
67
def __init__(self, client) -> None:
    self._client = client

send

send(
    session_id: str, events: Sequence[Mapping[str, Any]]
) -> Dict[str, Any]

Send events to a session.

Source code in dashscope/applications/agentstudio/resources/session_events.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def send(
    self,
    session_id: str,
    events: Sequence[Mapping[str, Any]],
) -> Dict[str, Any]:
    """Send events to a session."""
    if not events:
        raise ValueError("events must contain at least 1 entry")
    body = SessionEventSendParams(input=events).to_dict()
    resp = self._client.transport.request(
        "POST",
        _events_path(session_id),
        json=body,
    )
    return resp.data

list

list(
    session_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None
) -> CursorPage[ServerEvent]
Source code in dashscope/applications/agentstudio/resources/session_events.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def list(
    self,
    session_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None,
) -> CursorPage[ServerEvent]:
    params = SessionEventListParams(
        types=types,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
        limit=limit,
        order=order,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _events_path(session_id),
        params=params,
    )

    def fetch_next(nxt: str) -> CursorPage[ServerEvent]:
        return self.list(
            session_id,
            types=types,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
            limit=limit,
            order=order,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_event,
        request_id=resp.request_id,
        fetch_next=fetch_next,
    )

stream

stream(
    session_id: str,
    *,
    event_deltas: Optional[Sequence[str]] = None,
    timeout: Optional[float] = None
) -> "_TypedEventStream"

Open the SSE stream and return an iterator of typed events.

event_deltas opts into incremental streaming for the given event types ("message" and/or "reasoning"; aliases "agent.message" / "agent.thinking"); anything else the server rejects. The stream is read once, so text_deltas can be taken from it only; a second pass raises rather than returning nothing. A chunk stream is not a reliable source for final text: a reconnect replays only persisted events, so use text_stream.

Source code in dashscope/applications/agentstudio/resources/session_events.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def stream(
    self,
    session_id: str,
    *,
    event_deltas: Optional[Sequence[str]] = None,
    timeout: Optional[float] = None,
) -> "_TypedEventStream":
    """Open the SSE stream and return an iterator of typed events.

    ``event_deltas`` opts into incremental streaming for the given event
    types (``"message"`` and/or ``"reasoning"``; aliases ``"agent.message"``
    / ``"agent.thinking"``); anything else the server rejects. The stream is
    read once, so ``text_deltas`` can be taken from it only; a second pass
    raises rather than returning nothing. A chunk stream is not a reliable
    source for final text: a reconnect replays only persisted events, so use
    ``text_stream``.
    """
    params: Optional[Dict[str, Any]] = None
    if event_deltas:
        params = {"event_deltas[]": list(event_deltas)}
    resp = self._client.transport.request(
        "GET",
        _stream_path(session_id),
        extra_headers={"Accept": "text/event-stream"},
        params=params,
        stream=True,
        timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
    )
    return _TypedEventStream(
        self._client._event_stream_cls(
            response=resp,
            exceptions_module=self._client.transport.exceptions,
        ),
    )

AsyncSessionEvents

AsyncSessionEvents(client)

Async session event operations.

Source code in dashscope/applications/agentstudio/resources/session_events.py
265
266
def __init__(self, client) -> None:
    self._client = client

send async

send(
    session_id: str, events: Sequence[Mapping[str, Any]]
) -> Dict[str, Any]
Source code in dashscope/applications/agentstudio/resources/session_events.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
async def send(
    self,
    session_id: str,
    events: Sequence[Mapping[str, Any]],
) -> Dict[str, Any]:
    if not events:
        raise ValueError("events must contain at least 1 entry")
    body = SessionEventSendParams(input=events).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _events_path(session_id),
        json=body,
    )
    return resp.data

list async

list(
    session_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[ServerEvent]
Source code in dashscope/applications/agentstudio/resources/session_events.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
async def list(
    self,
    session_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[ServerEvent]:
    params = SessionEventListParams(
        types=types,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
        limit=limit,
        order=order,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _events_path(session_id),
        params=params,
    )

    async def fetch_next(
        nxt: str,
    ) -> AsyncCursorPage[ServerEvent]:
        return await self.list(
            session_id,
            types=types,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
            limit=limit,
            order=order,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_event,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

stream async

stream(
    session_id: str,
    *,
    event_deltas: Optional[Sequence[str]] = None,
    timeout: Optional[float] = None
) -> "_AioTypedEventStream"
Source code in dashscope/applications/agentstudio/resources/session_events.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
async def stream(
    self,
    session_id: str,
    *,
    event_deltas: Optional[Sequence[str]] = None,
    timeout: Optional[float] = None,
) -> "_AioTypedEventStream":
    params: Optional[Dict[str, Any]] = None
    if event_deltas:
        params = {"event_deltas[]": list(event_deltas)}
    resp = await self._client.transport.request(
        "GET",
        _stream_path(session_id),
        extra_headers={"Accept": "text/event-stream"},
        params=params,
        stream=True,
        timeout=timeout or AGENTSTUDIO_DEFAULT_TIMEOUT,
    )
    return _AioTypedEventStream(
        self._client._event_stream_cls(
            response=resp,
            exceptions_module=self._client.transport.exceptions,
        ),
    )

SessionThreads

SessionThreads(client)

Sub-agent threads within a session.

Source code in dashscope/applications/agentstudio/resources/session_threads.py
153
154
155
def __init__(self, client) -> None:
    self._client = client
    self.events = SessionThreadEvents(client)

events instance-attribute

events = SessionThreadEvents(client)

get class-attribute instance-attribute

get = retrieve

list

list(
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[SessionThread]
Source code in dashscope/applications/agentstudio/resources/session_threads.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def list(
    self,
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[SessionThread]:
    params = SessionThreadListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        _session_threads_path(session_id),
        params=params,
    )

    def fetch_next(token: str) -> CursorPage[SessionThread]:
        return self.list(session_id, limit=limit, page=token)

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session_thread,
        request_id=resp.request_id,
        fetch_next=fetch_next,
    )

retrieve

retrieve(session_id: str, thread_id: str) -> SessionThread
Source code in dashscope/applications/agentstudio/resources/session_threads.py
181
182
183
184
185
186
def retrieve(self, session_id: str, thread_id: str) -> SessionThread:
    resp = self._client.transport.request(
        "GET",
        _session_thread_item_path(session_id, thread_id),
    )
    return _coerce_session_thread(resp.data)

archive

archive(session_id: str, thread_id: str) -> SessionThread
Source code in dashscope/applications/agentstudio/resources/session_threads.py
191
192
193
194
195
196
def archive(self, session_id: str, thread_id: str) -> SessionThread:
    resp = self._client.transport.request(
        "POST",
        _session_thread_archive_path(session_id, thread_id),
    )
    return _coerce_session_thread(resp.data)

AsyncSessionThreads

AsyncSessionThreads(client)

Async sub-agent threads within a session.

Source code in dashscope/applications/agentstudio/resources/session_threads.py
202
203
204
def __init__(self, client) -> None:
    self._client = client
    self.events = AsyncSessionThreadEvents(client)

events instance-attribute

events = AsyncSessionThreadEvents(client)

get class-attribute instance-attribute

get = retrieve

list async

list(
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[SessionThread]
Source code in dashscope/applications/agentstudio/resources/session_threads.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
async def list(
    self,
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[SessionThread]:
    params = SessionThreadListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _session_threads_path(session_id),
        params=params,
    )

    async def fetch_next(token: str) -> AsyncCursorPage[SessionThread]:
        return await self.list(session_id, limit=limit, page=token)

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session_thread,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

retrieve async

retrieve(session_id: str, thread_id: str) -> SessionThread
Source code in dashscope/applications/agentstudio/resources/session_threads.py
231
232
233
234
235
236
237
238
239
240
async def retrieve(
    self,
    session_id: str,
    thread_id: str,
) -> SessionThread:
    resp = await self._client.transport.request(
        "GET",
        _session_thread_item_path(session_id, thread_id),
    )
    return _coerce_session_thread(resp.data)

archive async

archive(session_id: str, thread_id: str) -> SessionThread
Source code in dashscope/applications/agentstudio/resources/session_threads.py
245
246
247
248
249
250
async def archive(self, session_id: str, thread_id: str) -> SessionThread:
    resp = await self._client.transport.request(
        "POST",
        _session_thread_archive_path(session_id, thread_id),
    )
    return _coerce_session_thread(resp.data)

SessionThreadEvents

SessionThreadEvents(client)

Events scoped to a single sub-agent thread (list only).

Source code in dashscope/applications/agentstudio/resources/session_threads.py
36
37
def __init__(self, client) -> None:
    self._client = client

list

list(
    session_id: str,
    thread_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None
) -> CursorPage[ServerEvent]
Source code in dashscope/applications/agentstudio/resources/session_threads.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def list(
    self,
    session_id: str,
    thread_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None,
) -> CursorPage[ServerEvent]:
    params = SessionEventListParams(
        types=types,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
        limit=limit,
        order=order,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _session_thread_events_path(session_id, thread_id),
        params=params,
    )

    def fetch_next(nxt: str) -> CursorPage[ServerEvent]:
        return self.list(
            session_id,
            thread_id,
            types=types,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
            limit=limit,
            order=order,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_event,
        request_id=resp.request_id,
        fetch_next=fetch_next,
    )

AsyncSessionThreadEvents

AsyncSessionThreadEvents(client)

Async events scoped to a single sub-agent thread (list only).

Source code in dashscope/applications/agentstudio/resources/session_threads.py
94
95
def __init__(self, client) -> None:
    self._client = client

list async

list(
    session_id: str,
    thread_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[ServerEvent]
Source code in dashscope/applications/agentstudio/resources/session_threads.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
async def list(
    self,
    session_id: str,
    thread_id: str,
    *,
    types: Optional[Sequence[str]] = None,
    created_at_gt: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lt: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    limit: Optional[int] = None,
    order: Optional[str] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[ServerEvent]:
    params = SessionEventListParams(
        types=types,
        created_at_gt=created_at_gt,
        created_at_gte=created_at_gte,
        created_at_lt=created_at_lt,
        created_at_lte=created_at_lte,
        limit=limit,
        order=order,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _session_thread_events_path(session_id, thread_id),
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[ServerEvent]:
        return await self.list(
            session_id,
            thread_id,
            types=types,
            created_at_gt=created_at_gt,
            created_at_gte=created_at_gte,
            created_at_lt=created_at_lt,
            created_at_lte=created_at_lte,
            limit=limit,
            order=order,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_event,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

SessionResources

SessionResources(client)

Runtime resource mount/unmount on a session.

Source code in dashscope/applications/agentstudio/resources/session_resources.py
36
37
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

add

add(
    session_id: str,
    *,
    resource_type: str = "file",
    file_id: str,
    mount_path: Optional[str] = None
) -> SessionResource

Mount a file into a running session (POST /sessions/{id}/resources).

mount_path must be an absolute path under /uploads/. The returned file_id is the session-scoped copy id and may differ from the source file_id passed in.

Source code in dashscope/applications/agentstudio/resources/session_resources.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def add(
    self,
    session_id: str,
    *,
    resource_type: str = "file",
    file_id: str,
    mount_path: Optional[str] = None,
) -> SessionResource:
    """Mount a file into a running session (``POST /sessions/{id}/resources``).

    ``mount_path`` must be an absolute path under ``/uploads/``. The
    returned ``file_id`` is the session-scoped copy id and may differ
    from the source ``file_id`` passed in.
    """
    body = SessionResourceAddParams(
        type=resource_type,
        file_id=file_id,
        mount_path=mount_path,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _session_resources_path(session_id),
        json=body,
    )
    return _coerce_session_resource(resp.data)

retrieve

retrieve(
    session_id: str, resource_id: str
) -> SessionResource
Source code in dashscope/applications/agentstudio/resources/session_resources.py
65
66
67
68
69
70
71
72
73
74
def retrieve(
    self,
    session_id: str,
    resource_id: str,
) -> SessionResource:
    resp = self._client.transport.request(
        "GET",
        _session_resource_item_path(session_id, resource_id),
    )
    return _coerce_session_resource(resp.data)

list

list(
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[SessionResource]
Source code in dashscope/applications/agentstudio/resources/session_resources.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def list(
    self,
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[SessionResource]:
    params = SessionResourceListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        _session_resources_path(session_id),
        params=params,
    )

    def fetch_next(token: str) -> CursorPage[SessionResource]:
        return self.list(session_id, limit=limit, page=token)

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session_resource,
        request_id=resp.request_id,
        fetch_next=fetch_next,
    )

delete

delete(session_id: str, resource_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/session_resources.py
103
104
105
106
107
108
109
110
111
112
def delete(
    self,
    session_id: str,
    resource_id: str,
) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        _session_resource_item_path(session_id, resource_id),
    )
    return DeleteResponse(**resp.data)

AsyncSessionResources

AsyncSessionResources(client)

Async runtime resource mount/unmount on a session.

Source code in dashscope/applications/agentstudio/resources/session_resources.py
118
119
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

add async

add(
    session_id: str,
    *,
    resource_type: str = "file",
    file_id: str,
    mount_path: Optional[str] = None
) -> SessionResource
Source code in dashscope/applications/agentstudio/resources/session_resources.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
async def add(
    self,
    session_id: str,
    *,
    resource_type: str = "file",
    file_id: str,
    mount_path: Optional[str] = None,
) -> SessionResource:
    body = SessionResourceAddParams(
        type=resource_type,
        file_id=file_id,
        mount_path=mount_path,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _session_resources_path(session_id),
        json=body,
    )
    return _coerce_session_resource(resp.data)

retrieve async

retrieve(
    session_id: str, resource_id: str
) -> SessionResource
Source code in dashscope/applications/agentstudio/resources/session_resources.py
141
142
143
144
145
146
147
148
149
150
async def retrieve(
    self,
    session_id: str,
    resource_id: str,
) -> SessionResource:
    resp = await self._client.transport.request(
        "GET",
        _session_resource_item_path(session_id, resource_id),
    )
    return _coerce_session_resource(resp.data)

list async

list(
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[SessionResource]
Source code in dashscope/applications/agentstudio/resources/session_resources.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
async def list(
    self,
    session_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[SessionResource]:
    params = SessionResourceListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _session_resources_path(session_id),
        params=params,
    )

    async def fetch_next(token: str) -> AsyncCursorPage[SessionResource]:
        return await self.list(session_id, limit=limit, page=token)

    return build_page(
        payload=resp.data,
        item_factory=_coerce_session_resource,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(session_id: str, resource_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/session_resources.py
180
181
182
183
184
185
186
187
188
189
async def delete(
    self,
    session_id: str,
    resource_id: str,
) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        _session_resource_item_path(session_id, resource_id),
    )
    return DeleteResponse(**resp.data)

Environments & deployments

Environments

Environments(client)

Environment CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/environments.py
34
35
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = "organization",
    metadata: Optional[Mapping[str, Any]] = None,
    extra_headers: Optional[Mapping[str, str]] = None
) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def create(
    self,
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = "organization",
    metadata: Optional[Mapping[str, Any]] = None,
    extra_headers: Optional[Mapping[str, str]] = None,
) -> Environment:
    body = EnvironmentCreateParams(
        name=name,
        config=config,
        description=description,
        scope=scope,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _PATH_ENVIRONMENTS,
        json=body,
        extra_headers=extra_headers,
    )
    return _coerce_env(resp.data)

retrieve

retrieve(environment_id: str) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
62
63
64
65
66
67
def retrieve(self, environment_id: str) -> Environment:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
    )
    return _coerce_env(resp.data)

update

update(
    environment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def update(
    self,
    environment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Environment:
    body = EnvironmentUpdateParams(
        name=name,
        description=description,
        config=config,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
        json=body,
    )
    return _coerce_env(resp.data)

list

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None
) -> CursorPage[Environment]
Source code in dashscope/applications/agentstudio/resources/environments.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None,
) -> CursorPage[Environment]:
    params = EnvironmentListParams(
        limit=limit,
        page=page,
        include_archived=include_archived,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_ENVIRONMENTS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_env,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            limit=limit,
            page=nxt,
            include_archived=include_archived,
        ),
    )

archive

archive(environment_id: str) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
122
123
124
125
126
127
def archive(self, environment_id: str) -> Environment:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_ENVIRONMENTS}/{environment_id}/archive",
    )
    return _coerce_env(resp.data)

delete

delete(environment_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/environments.py
129
130
131
132
133
134
def delete(self, environment_id: str) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
    )
    return DeleteResponse(**resp.data)

AsyncEnvironments

AsyncEnvironments(client)

Async Environment CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/environments.py
140
141
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = "organization",
    metadata: Optional[Mapping[str, Any]] = None,
    extra_headers: Optional[Mapping[str, str]] = None
) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
async def create(
    self,
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = "organization",
    metadata: Optional[Mapping[str, Any]] = None,
    extra_headers: Optional[Mapping[str, str]] = None,
) -> Environment:
    body = EnvironmentCreateParams(
        name=name,
        config=config,
        description=description,
        scope=scope,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_ENVIRONMENTS,
        json=body,
        extra_headers=extra_headers,
    )
    return _coerce_env(resp.data)

retrieve async

retrieve(environment_id: str) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
168
169
170
171
172
173
async def retrieve(self, environment_id: str) -> Environment:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
    )
    return _coerce_env(resp.data)

update async

update(
    environment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
async def update(
    self,
    environment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Environment:
    body = EnvironmentUpdateParams(
        name=name,
        description=description,
        config=config,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
        json=body,
    )
    return _coerce_env(resp.data)

list async

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None
) -> AsyncCursorPage[Environment]
Source code in dashscope/applications/agentstudio/resources/environments.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
async def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    include_archived: Optional[bool] = None,
) -> AsyncCursorPage[Environment]:
    params = EnvironmentListParams(
        limit=limit,
        page=page,
        include_archived=include_archived,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_ENVIRONMENTS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Environment]:
        return await self.list(
            limit=limit,
            page=nxt,
            include_archived=include_archived,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_env,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

archive async

archive(environment_id: str) -> Environment
Source code in dashscope/applications/agentstudio/resources/environments.py
233
234
235
236
237
238
async def archive(self, environment_id: str) -> Environment:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_ENVIRONMENTS}/{environment_id}/archive",
    )
    return _coerce_env(resp.data)

delete async

delete(environment_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/environments.py
240
241
242
243
244
245
async def delete(self, environment_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_ENVIRONMENTS}/{environment_id}",
    )
    return DeleteResponse(**resp.data)

Deployments

Deployments(client)

Managed Agent deployment lifecycle and execution.

Source code in dashscope/applications/agentstudio/resources/deployments.py
34
35
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def create(
    self,
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> Deployment:
    body = DeploymentCreateParams(
        name=name,
        agent=agent,
        initial_events=initial_events,
        description=description,
        environment_id=environment_id,
        schedule=schedule,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _PATH_DEPLOYMENTS,
        json=body,
    )
    return _coerce_deployment(resp.data)

retrieve

retrieve(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
70
71
72
73
74
75
def retrieve(self, deployment_id: str) -> Deployment:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}",
    )
    return _coerce_deployment(resp.data)

update

update(
    deployment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def update(
    self,
    deployment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[Sequence[Mapping[str, Any]]] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> Deployment:
    body = DeploymentUpdateParams(
        name=name,
        description=description,
        agent=agent,
        environment_id=environment_id,
        schedule=schedule,
        initial_events=initial_events,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}",
        json=body,
    )
    return _coerce_deployment(resp.data)

list

list(
    *,
    agent_id: Optional[str] = None,
    keyword: Optional[str] = None,
    status: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None
) -> CursorPage[Deployment]
Source code in dashscope/applications/agentstudio/resources/deployments.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def list(
    self,
    *,
    agent_id: Optional[str] = None,
    keyword: Optional[str] = None,
    status: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
) -> CursorPage[Deployment]:
    params = DeploymentListParams(
        agent_id=agent_id,
        keyword=keyword,
        status=status,
        include_archived=include_archived,
        limit=limit,
        page=page,
        created_at_gte=created_at_gte,
        created_at_lte=created_at_lte,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_DEPLOYMENTS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            agent_id=agent_id,
            keyword=keyword,
            status=status,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
            created_at_gte=created_at_gte,
            created_at_lte=created_at_lte,
        ),
    )

pause

pause(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
156
157
def pause(self, deployment_id: str) -> Deployment:
    return self._lifecycle(deployment_id, "pause")

unpause

unpause(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
159
160
def unpause(self, deployment_id: str) -> Deployment:
    return self._lifecycle(deployment_id, "unpause")

archive

archive(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
162
163
def archive(self, deployment_id: str) -> Deployment:
    return self._lifecycle(deployment_id, "archive")

run

run(deployment_id: str) -> DeploymentRun
Source code in dashscope/applications/agentstudio/resources/deployments.py
172
173
174
175
176
177
def run(self, deployment_id: str) -> DeploymentRun:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}/run",
    )
    return _coerce_deployment_run(resp.data)

list_runs

list_runs(
    deployment_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[DeploymentRun]
Source code in dashscope/applications/agentstudio/resources/deployments.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def list_runs(
    self,
    deployment_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[DeploymentRun]:
    params = DeploymentRunListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}/runs",
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment_run,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list_runs(
            deployment_id,
            limit=limit,
            page=nxt,
        ),
    )

AsyncDeployments

AsyncDeployments(client)

Asynchronous Managed Agent deployment lifecycle and execution.

Source code in dashscope/applications/agentstudio/resources/deployments.py
242
243
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
async def create(
    self,
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> Deployment:
    body = DeploymentCreateParams(
        name=name,
        agent=agent,
        initial_events=initial_events,
        description=description,
        environment_id=environment_id,
        schedule=schedule,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_DEPLOYMENTS,
        json=body,
    )
    return _coerce_deployment(resp.data)

retrieve async

retrieve(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
278
279
280
281
282
283
async def retrieve(self, deployment_id: str) -> Deployment:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}",
    )
    return _coerce_deployment(resp.data)

update async

update(
    deployment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
async def update(
    self,
    deployment_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[Sequence[Mapping[str, Any]]] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> Deployment:
    body = DeploymentUpdateParams(
        name=name,
        description=description,
        agent=agent,
        environment_id=environment_id,
        schedule=schedule,
        initial_events=initial_events,
        resources=resources,
        vault_ids=vault_ids,
        environment_variables=environment_variables,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}",
        json=body,
    )
    return _coerce_deployment(resp.data)

list async

list(
    *,
    agent_id: Optional[str] = None,
    keyword: Optional[str] = None,
    status: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None
) -> AsyncCursorPage[Deployment]
Source code in dashscope/applications/agentstudio/resources/deployments.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
async def list(
    self,
    *,
    agent_id: Optional[str] = None,
    keyword: Optional[str] = None,
    status: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
) -> AsyncCursorPage[Deployment]:
    params = DeploymentListParams(
        agent_id=agent_id,
        keyword=keyword,
        status=status,
        include_archived=include_archived,
        limit=limit,
        page=page,
        created_at_gte=created_at_gte,
        created_at_lte=created_at_lte,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_DEPLOYMENTS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Deployment]:
        return await self.list(
            agent_id=agent_id,
            keyword=keyword,
            status=status,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
            created_at_gte=created_at_gte,
            created_at_lte=created_at_lte,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

pause async

pause(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
369
370
async def pause(self, deployment_id: str) -> Deployment:
    return await self._lifecycle(deployment_id, "pause")

unpause async

unpause(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
372
373
async def unpause(self, deployment_id: str) -> Deployment:
    return await self._lifecycle(deployment_id, "unpause")

archive async

archive(deployment_id: str) -> Deployment
Source code in dashscope/applications/agentstudio/resources/deployments.py
375
376
async def archive(self, deployment_id: str) -> Deployment:
    return await self._lifecycle(deployment_id, "archive")

run async

run(deployment_id: str) -> DeploymentRun
Source code in dashscope/applications/agentstudio/resources/deployments.py
389
390
391
392
393
394
async def run(self, deployment_id: str) -> DeploymentRun:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}/run",
    )
    return _coerce_deployment_run(resp.data)

list_runs async

list_runs(
    deployment_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[DeploymentRun]
Source code in dashscope/applications/agentstudio/resources/deployments.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
async def list_runs(
    self,
    deployment_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[DeploymentRun]:
    params = DeploymentRunListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENTS}/{deployment_id}/runs",
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[DeploymentRun]:
        return await self.list_runs(
            deployment_id,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment_run,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

DeploymentRuns

DeploymentRuns(client)

Workspace-wide deployment run history.

Source code in dashscope/applications/agentstudio/resources/deployments.py
207
208
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

retrieve

retrieve(deployment_run_id: str) -> DeploymentRun
Source code in dashscope/applications/agentstudio/resources/deployments.py
210
211
212
213
214
215
def retrieve(self, deployment_run_id: str) -> DeploymentRun:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENT_RUNS}/{deployment_run_id}",
    )
    return _coerce_deployment_run(resp.data)

list

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[DeploymentRun]
Source code in dashscope/applications/agentstudio/resources/deployments.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[DeploymentRun]:
    params = DeploymentRunListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_DEPLOYMENT_RUNS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment_run,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(limit=limit, page=nxt),
    )

AsyncDeploymentRuns

AsyncDeploymentRuns(client)

Asynchronous workspace-wide deployment run history.

Source code in dashscope/applications/agentstudio/resources/deployments.py
429
430
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

retrieve async

retrieve(deployment_run_id: str) -> DeploymentRun
Source code in dashscope/applications/agentstudio/resources/deployments.py
432
433
434
435
436
437
async def retrieve(self, deployment_run_id: str) -> DeploymentRun:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_DEPLOYMENT_RUNS}/{deployment_run_id}",
    )
    return _coerce_deployment_run(resp.data)

list async

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[DeploymentRun]
Source code in dashscope/applications/agentstudio/resources/deployments.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
async def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[DeploymentRun]:
    params = DeploymentRunListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_DEPLOYMENT_RUNS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[DeploymentRun]:
        return await self.list(limit=limit, page=nxt)

    return build_page(
        payload=resp.data,
        item_factory=_coerce_deployment_run,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

Files

Files

Files(client)

File upload / download / list / delete.

Source code in dashscope/applications/agentstudio/resources/files.py
137
138
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

upload

upload(
    file: Union[
        str,
        "os.PathLike[str]",
        BinaryIO,
        Tuple[str, BinaryIO],
    ],
    *,
    mime_type: Optional[str] = None,
    progress: Optional[ProgressCallback] = None,
    extra_headers: Optional[Mapping[str, str]] = None
) -> File
Source code in dashscope/applications/agentstudio/resources/files.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def upload(
    self,
    file: Union[str, "os.PathLike[str]", BinaryIO, Tuple[str, BinaryIO]],
    *,
    mime_type: Optional[str] = None,
    progress: Optional[ProgressCallback] = None,
    extra_headers: Optional[Mapping[str, str]] = None,
) -> File:
    filename, fileobj, must_close = _open_file(file)
    try:
        payload_obj: Any
        if progress is not None:
            size = _file_size(fileobj)
            if size > 0:
                payload_obj = _ProgressFile(fileobj, size, progress)
            else:
                payload_obj = fileobj
        else:
            payload_obj = fileobj
        multipart: Dict[str, Any] = {
            "file": (
                filename,
                payload_obj,
                mime_type or "application/octet-stream",
            ),
        }
        resp = self._client.transport.request(
            "POST",
            _PATH_FILES,
            files=multipart,
            extra_headers=extra_headers,
        )
        return _coerce_file(resp.data)
    finally:
        if must_close:
            try:
                fileobj.close()
            except Exception:
                pass

retrieve

retrieve(file_id: str) -> File
Source code in dashscope/applications/agentstudio/resources/files.py
180
181
182
183
184
185
def retrieve(self, file_id: str) -> File:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_FILES}/{file_id}",
    )
    return _coerce_file(resp.data)

download

download(
    file_id: str, *, timeout: Optional[float] = None
) -> FileContent

Return the file content as a :class:FileContent.

Only files whose downloadable flag is true can be fetched; the service answers 403 otherwise. Use :meth:FileContent.write_to_file to persist the bytes to disk.

content = client.files.download("file_xxx")
content.write_to_file("output.txt")
Source code in dashscope/applications/agentstudio/resources/files.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def download(
    self,
    file_id: str,
    *,
    timeout: Optional[float] = None,
) -> FileContent:
    """Return the file content as a :class:`FileContent`.

    Only files whose ``downloadable`` flag is true can be fetched; the
    service answers 403 otherwise. Use :meth:`FileContent.write_to_file`
    to persist the bytes to disk.

        content = client.files.download("file_xxx")
        content.write_to_file("output.txt")
    """
    resp = self._open_content(file_id, timeout)
    try:
        resp.read()
        return FileContent(resp.content)
    finally:
        resp.close()

list

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    scope_id: Optional[str] = None
) -> CursorPage[File]
Source code in dashscope/applications/agentstudio/resources/files.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    scope_id: Optional[str] = None,
) -> CursorPage[File]:
    params = FileListParams(
        limit=limit,
        page=page,
        scope_id=scope_id,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_FILES,
        params=params,
    )

    def fetch_next(token: str) -> CursorPage[File]:
        return self.list(
            limit=limit,
            page=token,
            scope_id=scope_id,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_file,
        request_id=resp.request_id,
        page_cls=CursorPage,
        fetch_next=fetch_next,
    )

delete

delete(file_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/files.py
255
256
257
258
259
260
def delete(self, file_id: str) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_FILES}/{file_id}",
    )
    return DeleteResponse(**resp.data)

AsyncFiles

AsyncFiles(client)

Async file upload / download / list / delete.

Source code in dashscope/applications/agentstudio/resources/files.py
266
267
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

upload async

upload(
    file: Union[
        str,
        "os.PathLike[str]",
        BinaryIO,
        Tuple[str, BinaryIO],
    ],
    *,
    mime_type: Optional[str] = None,
    progress: Optional[ProgressCallback] = None,
    extra_headers: Optional[Mapping[str, str]] = None
) -> File
Source code in dashscope/applications/agentstudio/resources/files.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
async def upload(
    self,
    file: Union[str, "os.PathLike[str]", BinaryIO, Tuple[str, BinaryIO]],
    *,
    mime_type: Optional[str] = None,
    progress: Optional[ProgressCallback] = None,
    extra_headers: Optional[Mapping[str, str]] = None,
) -> File:
    filename, fileobj, must_close = _open_file(file)
    try:
        payload_obj: Any
        if progress is not None:
            size = _file_size(fileobj)
            if size > 0:
                payload_obj = _ProgressFile(fileobj, size, progress)
            else:
                payload_obj = fileobj
        else:
            payload_obj = fileobj
        multipart: Dict[str, Any] = {
            "file": (
                filename,
                payload_obj,
                mime_type or "application/octet-stream",
            ),
        }
        resp = await self._client.transport.request(
            "POST",
            _PATH_FILES,
            files=multipart,
            extra_headers=extra_headers,
        )
        return _coerce_file(resp.data)
    finally:
        if must_close:
            try:
                fileobj.close()
            except Exception:
                pass

retrieve async

retrieve(file_id: str) -> File
Source code in dashscope/applications/agentstudio/resources/files.py
309
310
311
312
313
314
async def retrieve(self, file_id: str) -> File:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_FILES}/{file_id}",
    )
    return _coerce_file(resp.data)

download async

download(
    file_id: str, *, timeout: Optional[float] = None
) -> FileContent

Return the file content as a :class:FileContent.

Only files whose downloadable flag is true can be fetched; the service answers 403 otherwise. Use :meth:FileContent.write_to_file to persist the bytes to disk.

content = await client.files.download("file_xxx")
content.write_to_file("output.txt")
Source code in dashscope/applications/agentstudio/resources/files.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
async def download(
    self,
    file_id: str,
    *,
    timeout: Optional[float] = None,
) -> FileContent:
    """Return the file content as a :class:`FileContent`.

    Only files whose ``downloadable`` flag is true can be fetched; the
    service answers 403 otherwise. Use :meth:`FileContent.write_to_file`
    to persist the bytes to disk.

        content = await client.files.download("file_xxx")
        content.write_to_file("output.txt")
    """
    resp = await self._open_content(file_id, timeout)
    try:
        await resp.aread()
        return FileContent(resp.content)
    finally:
        await resp.aclose()

list async

list(
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    scope_id: Optional[str] = None
) -> AsyncCursorPage[File]
Source code in dashscope/applications/agentstudio/resources/files.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
async def list(
    self,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
    scope_id: Optional[str] = None,
) -> AsyncCursorPage[File]:
    params = FileListParams(
        limit=limit,
        page=page,
        scope_id=scope_id,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_FILES,
        params=params,
    )

    async def fetch_next(token: str) -> AsyncCursorPage[File]:
        return await self.list(
            limit=limit,
            page=token,
            scope_id=scope_id,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_file,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(file_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/files.py
384
385
386
387
388
389
async def delete(self, file_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_FILES}/{file_id}",
    )
    return DeleteResponse(**resp.data)

Memory

MemoryStores

MemoryStores(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
359
360
361
362
def __init__(self, client) -> None:
    self._client = client
    self.memories = Memories(client)
    self.memory_versions = MemoryVersions(client)

memories instance-attribute

memories = Memories(client)

memory_versions instance-attribute

memory_versions = MemoryVersions(client)

get class-attribute instance-attribute

get = retrieve

create

create(
    *,
    name: str,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> MemoryStore

Create a memory store (POST /memory_stores).

description is passed to the agent so it knows what the store contains — write it for the model, not for humans.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
def create(
    self,
    *,
    name: str,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> MemoryStore:
    """Create a memory store (``POST /memory_stores``).

    ``description`` is passed to the agent so it knows what the
    store contains — write it for the model, not for humans.
    """
    body = MemoryStoreCreateParams(
        name=name,
        description=description,
        metadata=dict(metadata) if metadata is not None else None,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _memory_stores_path(),
        json=body,
    )
    return _coerce_memory_store(resp.data)

retrieve

retrieve(store_id: str) -> MemoryStore
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
388
389
390
391
392
393
def retrieve(self, store_id: str) -> MemoryStore:
    resp = self._client.transport.request(
        "GET",
        _memory_store_item_path(store_id),
    )
    return _coerce_memory_store(resp.data)

update

update(
    store_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> MemoryStore

Update a store (POST /memory_stores/{store_id}).

Mutate name / description / metadata — at least one must be given. metadata is replaced wholesale (unlike CMA's merge-patch): keys not included in the request are dropped; a key set to null deletes it.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
def update(
    self,
    store_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> MemoryStore:
    """Update a store (``POST /memory_stores/{store_id}``).

    Mutate ``name`` / ``description`` / ``metadata`` — at least one
    must be given. ``metadata`` is **replaced wholesale** (unlike
    CMA's merge-patch): keys not included in the request are
    dropped; a key set to ``null`` deletes it.
    """
    if name is None and description is None and metadata is None:
        raise TypeError(
            "memory_stores.update() requires at least one of "
            "'name', 'description' or 'metadata'",
        )
    body = MemoryStoreUpdateParams(
        name=name,
        description=description,
        metadata=dict(metadata) if metadata is not None else None,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _memory_store_item_path(store_id),
        json=body,
    )
    return _coerce_memory_store(resp.data)

list

list(
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[MemoryStore]

List stores (GET /memory_stores).

The public API has no keyword filter (that is a console-only capability).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
def list(
    self,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[MemoryStore]:
    """List stores (``GET /memory_stores``).

    The public API has no ``keyword`` filter (that is a
    console-only capability).
    """
    params = MemoryStoreListParams(
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _memory_stores_path(),
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_memory_store,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        ),
    )

delete

delete(store_id: str) -> DeleteResponse

Delete a store (DELETE /memory_stores/{id}).

Accepted immediately; items are removed asynchronously. The response is a marker (type="memory_store_deleted").

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
462
463
464
465
466
467
468
469
470
471
472
def delete(self, store_id: str) -> DeleteResponse:
    """Delete a store (``DELETE /memory_stores/{id}``).

    Accepted immediately; items are removed asynchronously.  The
    response is a marker (``type="memory_store_deleted"``).
    """
    resp = self._client.transport.request(
        "DELETE",
        _memory_store_item_path(store_id),
    )
    return DeleteResponse(**resp.data)

archive

archive(store_id: str) -> MemoryStore

Archive a store (POST /memory_stores/{id}/archive).

Read-only afterwards: existing session attachments continue, new sessions cannot reference it. Irreversible.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
474
475
476
477
478
479
480
481
482
483
484
def archive(self, store_id: str) -> MemoryStore:
    """Archive a store (``POST /memory_stores/{id}/archive``).

    Read-only afterwards: existing session attachments continue,
    new sessions cannot reference it.  Irreversible.
    """
    resp = self._client.transport.request(
        "POST",
        _memory_store_archive_path(store_id),
    )
    return _coerce_memory_store(resp.data)

AsyncMemoryStores

AsyncMemoryStores(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
687
688
689
690
def __init__(self, client) -> None:
    self._client = client
    self.memories = AsyncMemories(client)
    self.memory_versions = AsyncMemoryVersions(client)

memories instance-attribute

memories = AsyncMemories(client)

memory_versions instance-attribute

memory_versions = AsyncMemoryVersions(client)

get class-attribute instance-attribute

get = retrieve

create async

create(
    *,
    name: str,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> MemoryStore
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
async def create(
    self,
    *,
    name: str,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> MemoryStore:
    body = MemoryStoreCreateParams(
        name=name,
        description=description,
        metadata=dict(metadata) if metadata is not None else None,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _memory_stores_path(),
        json=body,
    )
    return _coerce_memory_store(resp.data)

retrieve async

retrieve(store_id: str) -> MemoryStore
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
711
712
713
714
715
716
async def retrieve(self, store_id: str) -> MemoryStore:
    resp = await self._client.transport.request(
        "GET",
        _memory_store_item_path(store_id),
    )
    return _coerce_memory_store(resp.data)

update async

update(
    store_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> MemoryStore
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
async def update(
    self,
    store_id: str,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> MemoryStore:
    if name is None and description is None and metadata is None:
        raise TypeError(
            "memory_stores.update() requires at least one of "
            "'name', 'description' or 'metadata'",
        )
    body = MemoryStoreUpdateParams(
        name=name,
        description=description,
        metadata=dict(metadata) if metadata is not None else None,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _memory_store_item_path(store_id),
        json=body,
    )
    return _coerce_memory_store(resp.data)

list async

list(
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[MemoryStore]
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
async def list(
    self,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[MemoryStore]:
    params = MemoryStoreListParams(
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _memory_stores_path(),
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[MemoryStore]:
        return await self.list(
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_memory_store,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(store_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
778
779
780
781
782
783
async def delete(self, store_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        _memory_store_item_path(store_id),
    )
    return DeleteResponse(**resp.data)

archive async

archive(store_id: str) -> MemoryStore
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
785
786
787
788
789
790
async def archive(self, store_id: str) -> MemoryStore:
    resp = await self._client.transport.request(
        "POST",
        _memory_store_archive_path(store_id),
    )
    return _coerce_memory_store(resp.data)

Memories

Memories(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
120
121
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(store_id: str, *, path: str, content: str) -> Memory

Create a memory at path (POST .../memories).

A memory already existing at path returns 409 memory_path_conflict_error.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def create(
    self,
    store_id: str,
    *,
    path: str,
    content: str,
) -> Memory:
    """Create a memory at ``path`` (``POST .../memories``).

    A memory already existing at ``path`` returns 409
    ``memory_path_conflict_error``.
    """
    body = MemoryCreateParams(path=path, content=content).to_dict()
    resp = self._client.transport.request(
        "POST",
        _memories_path(store_id),
        json=body,
    )
    return _coerce_memory(resp.data)

list

list(
    store_id: str,
    *,
    path_prefix: Optional[str] = None,
    depth: Optional[int] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[Memory]

List memories (GET .../memories).

path_prefix scopes the listing (server-validated: must start and end with / — segment-aligned, so /notes/ matches /notes/a.md but not /notes_backup/old.md; a bare "/" lists the whole store). File items land in data; directory nodes come back as page.prefixes (per page; merge across pages manually for a full tree). view="full" includes content per item but caps limit at 20 — the backend rejects higher values with 400 (CMA silently clamps); the default "basic" returns metadata only with limit up to 100.

depth bounds the tree walk below path_prefix; the backend implements 0/1 natively and larger values are derived client-side (see _MAX_WIRE_DEPTH). With view="full" the derivation still transfers the content of files the depth cut discards — prefer view="basic" for deep walks.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def list(
    self,
    store_id: str,
    *,
    path_prefix: Optional[str] = None,
    depth: Optional[int] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[Memory]:
    """List memories (``GET .../memories``).

    ``path_prefix`` scopes the listing (server-validated: must
    start and end with ``/`` — segment-aligned, so ``/notes/``
    matches ``/notes/a.md`` but not ``/notes_backup/old.md``; a
    bare ``"/"`` lists the whole store). File items land in
    ``data``; directory nodes come back as ``page.prefixes``
    (per page; merge across pages manually for a full tree).
    ``view="full"`` includes ``content`` per item but caps
    ``limit`` at 20 — the backend rejects higher values with
    400 (CMA silently clamps); the default ``"basic"`` returns
    metadata only with ``limit`` up to 100.

    ``depth`` bounds the tree walk below ``path_prefix``; the
    backend implements 0/1 natively and larger values are derived
    client-side (see ``_MAX_WIRE_DEPTH``). With ``view="full"`` the
    derivation still transfers the content of files the depth cut
    discards — prefer ``view="basic"`` for deep walks.
    """
    depth_emulated = depth is not None and depth > _MAX_WIRE_DEPTH
    wire_depth = None if depth_emulated else depth
    params = MemoryListParams(
        path_prefix=path_prefix,
        depth=wire_depth,
        view=view,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _memories_path(store_id),
        params=params,
    )
    result = build_page(
        payload=resp.data,
        item_factory=_coerce_memory,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            store_id,
            path_prefix=path_prefix,
            depth=depth,
            view=view,
            limit=limit,
            page=nxt,
        ),
    )
    if depth_emulated:
        result = _apply_depth_emulation(result, depth, path_prefix)
    return result

retrieve

retrieve(store_id: str, memory_id: str) -> Memory

Retrieve a memory with content (GET .../memories/{id}).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
203
204
205
206
207
208
209
210
211
212
213
def retrieve(
    self,
    store_id: str,
    memory_id: str,
) -> Memory:
    """Retrieve a memory with content (``GET .../memories/{id}``)."""
    resp = self._client.transport.request(
        "GET",
        _memory_item_path(store_id, memory_id),
    )
    return _coerce_memory(resp.data)

update

update(
    store_id: str,
    memory_id: str,
    *,
    path: Optional[str] = None,
    content: Optional[str] = None,
    content_sha256: Optional[str] = None
) -> Memory

Update a memory (POST .../memories/{id}).

Mutate content, rename via path, or both — at least one must be given. Pass the sha from the previously retrieved memory as content_sha256 for optimistic concurrency; a mismatch returns 409 memory_precondition_failed_error.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def update(
    self,
    store_id: str,
    memory_id: str,
    *,
    path: Optional[str] = None,
    content: Optional[str] = None,
    content_sha256: Optional[str] = None,
) -> Memory:
    """Update a memory (``POST .../memories/{id}``).

    Mutate ``content``, rename via ``path``, or both — at least one
    must be given.  Pass the sha from the previously retrieved
    memory as ``content_sha256`` for optimistic concurrency; a
    mismatch returns 409 ``memory_precondition_failed_error``.
    """
    if path is None and content is None:
        raise TypeError(
            "memories.update() requires at least one of "
            "'path' or 'content'",
        )
    body = MemoryUpdateParams(
        path=path,
        content=content,
        content_sha256=content_sha256,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _memory_item_path(store_id, memory_id),
        json=body,
    )
    return _coerce_memory(resp.data)

delete

delete(store_id: str, memory_id: str) -> DeleteResponse

Delete a memory (DELETE .../memories/{id}).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
250
251
252
253
254
255
256
257
258
259
260
def delete(
    self,
    store_id: str,
    memory_id: str,
) -> DeleteResponse:
    """Delete a memory (``DELETE .../memories/{id}``)."""
    resp = self._client.transport.request(
        "DELETE",
        _memory_item_path(store_id, memory_id),
    )
    return DeleteResponse(**resp.data)

AsyncMemories

AsyncMemories(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
493
494
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(store_id: str, *, path: str, content: str) -> Memory
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
496
497
498
499
500
501
502
503
504
505
506
507
508
509
async def create(
    self,
    store_id: str,
    *,
    path: str,
    content: str,
) -> Memory:
    body = MemoryCreateParams(path=path, content=content).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _memories_path(store_id),
        json=body,
    )
    return _coerce_memory(resp.data)

list async

list(
    store_id: str,
    *,
    path_prefix: Optional[str] = None,
    depth: Optional[int] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[Memory]

Async variant of :meth:Memories.list (depth >= 2 is emulated client-side the same way).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
async def list(
    self,
    store_id: str,
    *,
    path_prefix: Optional[str] = None,
    depth: Optional[int] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[Memory]:
    """Async variant of :meth:`Memories.list` (depth >= 2 is
    emulated client-side the same way)."""
    depth_emulated = depth is not None and depth > _MAX_WIRE_DEPTH
    wire_depth = None if depth_emulated else depth
    params = MemoryListParams(
        path_prefix=path_prefix,
        depth=wire_depth,
        view=view,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _memories_path(store_id),
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Memory]:
        return await self.list(
            store_id,
            path_prefix=path_prefix,
            depth=depth,
            view=view,
            limit=limit,
            page=nxt,
        )

    result = build_page(
        payload=resp.data,
        item_factory=_coerce_memory,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )
    if depth_emulated:
        result = _apply_depth_emulation(result, depth, path_prefix)
    return result

retrieve async

retrieve(store_id: str, memory_id: str) -> Memory
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
559
560
561
562
563
564
565
566
567
568
async def retrieve(
    self,
    store_id: str,
    memory_id: str,
) -> Memory:
    resp = await self._client.transport.request(
        "GET",
        _memory_item_path(store_id, memory_id),
    )
    return _coerce_memory(resp.data)

update async

update(
    store_id: str,
    memory_id: str,
    *,
    path: Optional[str] = None,
    content: Optional[str] = None,
    content_sha256: Optional[str] = None
) -> Memory
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
async def update(
    self,
    store_id: str,
    memory_id: str,
    *,
    path: Optional[str] = None,
    content: Optional[str] = None,
    content_sha256: Optional[str] = None,
) -> Memory:
    if path is None and content is None:
        raise TypeError(
            "memories.update() requires at least one of "
            "'path' or 'content'",
        )
    body = MemoryUpdateParams(
        path=path,
        content=content,
        content_sha256=content_sha256,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _memory_item_path(store_id, memory_id),
        json=body,
    )
    return _coerce_memory(resp.data)

delete async

delete(store_id: str, memory_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
598
599
600
601
602
603
604
605
606
607
async def delete(
    self,
    store_id: str,
    memory_id: str,
) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        _memory_item_path(store_id, memory_id),
    )
    return DeleteResponse(**resp.data)

MemoryVersions

MemoryVersions(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
269
270
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

list

list(
    store_id: str,
    *,
    memory_id: Optional[str] = None,
    operation: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[MemoryVersion]

List versions, newest-first (GET .../memory_versions).

Filters: memory_id, operation (created / modified / deleted), created_at_gte / created_at_lte (ISO-8601 timestamps; sent on the wire as created_at.gte / created_at.lte), and view (basic / full).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
def list(
    self,
    store_id: str,
    *,
    memory_id: Optional[str] = None,
    operation: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[MemoryVersion]:
    """List versions, newest-first (``GET .../memory_versions``).

    Filters: ``memory_id``, ``operation`` (``created`` / ``modified``
    / ``deleted``), ``created_at_gte`` / ``created_at_lte`` (ISO-8601
    timestamps; sent on the wire as ``created_at.gte`` /
    ``created_at.lte``), and ``view`` (``basic`` / ``full``).
    """
    params = MemoryVersionListParams(
        memory_id=memory_id,
        operation=operation,
        created_at_gte=created_at_gte,
        created_at_lte=created_at_lte,
        view=view,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _memory_versions_path(store_id),
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_memory_version,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            store_id,
            memory_id=memory_id,
            operation=operation,
            created_at_gte=created_at_gte,
            created_at_lte=created_at_lte,
            view=view,
            limit=limit,
            page=nxt,
        ),
    )

retrieve

retrieve(store_id: str, version_id: str) -> MemoryVersion

Retrieve a version snapshot (GET .../memory_versions/{id}).

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
321
322
323
324
325
326
327
328
329
330
331
def retrieve(
    self,
    store_id: str,
    version_id: str,
) -> MemoryVersion:
    """Retrieve a version snapshot (``GET .../memory_versions/{id}``)."""
    resp = self._client.transport.request(
        "GET",
        _memory_version_item_path(store_id, version_id),
    )
    return _coerce_memory_version(resp.data)

redact

redact(store_id: str, version_id: str) -> MemoryVersion

Redact a version (POST .../memory_versions/{id}/redact).

Scrubs path / content / content_sha256 / content_size_bytes while preserving the audit trail (created_at, ids). Idempotent and irreversible.

Source code in dashscope/applications/agentstudio/resources/memory_stores.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
def redact(
    self,
    store_id: str,
    version_id: str,
) -> MemoryVersion:
    """Redact a version (``POST .../memory_versions/{id}/redact``).

    Scrubs ``path`` / ``content`` / ``content_sha256`` /
    ``content_size_bytes`` while preserving the audit trail
    (``created_at``, ids).  Idempotent and irreversible.
    """
    resp = self._client.transport.request(
        "POST",
        _memory_version_redact_path(store_id, version_id),
    )
    return _coerce_memory_version(resp.data)

AsyncMemoryVersions

AsyncMemoryVersions(client)
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
611
612
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

list async

list(
    store_id: str,
    *,
    memory_id: Optional[str] = None,
    operation: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[MemoryVersion]
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
async def list(
    self,
    store_id: str,
    *,
    memory_id: Optional[str] = None,
    operation: Optional[str] = None,
    created_at_gte: Optional[str] = None,
    created_at_lte: Optional[str] = None,
    view: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[MemoryVersion]:
    params = MemoryVersionListParams(
        memory_id=memory_id,
        operation=operation,
        created_at_gte=created_at_gte,
        created_at_lte=created_at_lte,
        view=view,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _memory_versions_path(store_id),
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[MemoryVersion]:
        return await self.list(
            store_id,
            memory_id=memory_id,
            operation=operation,
            created_at_gte=created_at_gte,
            created_at_lte=created_at_lte,
            view=view,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_memory_version,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

retrieve async

retrieve(store_id: str, version_id: str) -> MemoryVersion
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
661
662
663
664
665
666
667
668
669
670
async def retrieve(
    self,
    store_id: str,
    version_id: str,
) -> MemoryVersion:
    resp = await self._client.transport.request(
        "GET",
        _memory_version_item_path(store_id, version_id),
    )
    return _coerce_memory_version(resp.data)

redact async

redact(store_id: str, version_id: str) -> MemoryVersion
Source code in dashscope/applications/agentstudio/resources/memory_stores.py
674
675
676
677
678
679
680
681
682
683
async def redact(
    self,
    store_id: str,
    version_id: str,
) -> MemoryVersion:
    resp = await self._client.transport.request(
        "POST",
        _memory_version_redact_path(store_id, version_id),
    )
    return _coerce_memory_version(resp.data)

Skills

Skills

Skills(client)

Skill CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/skills.py
40
41
42
def __init__(self, client) -> None:
    self._client = client
    self.versions = SkillVersions(client)

versions instance-attribute

versions = SkillVersions(client)

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create

create(
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None
) -> Skill
Source code in dashscope/applications/agentstudio/resources/skills.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def create(
    self,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None,
) -> Skill:
    resolved = _resolve_file_id_sync(
        client=self._client,
        file_id=file_id,
        file=file,
        mime_type=mime_type,
    )
    body = SkillCreateParams(file_id=resolved).to_dict()
    resp = self._client.transport.request("POST", _PATH_SKILLS, json=body)
    return _coerce_skill(resp.data)

retrieve

retrieve(skill_id: str) -> Skill
Source code in dashscope/applications/agentstudio/resources/skills.py
61
62
63
64
65
66
def retrieve(self, skill_id: str) -> Skill:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}",
    )
    return _coerce_skill(resp.data)

list

list(
    *,
    source: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[Skill]
Source code in dashscope/applications/agentstudio/resources/skills.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def list(
    self,
    *,
    source: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[Skill]:
    params = SkillListParams(
        source=source,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_SKILLS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_skill,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            source=source,
            limit=limit,
            page=nxt,
        ),
    )

delete

delete(skill_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/skills.py
102
103
104
105
106
107
def delete(self, skill_id: str) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_SKILLS}/{skill_id}",
    )
    return DeleteResponse(**resp.data)

AsyncSkills

AsyncSkills(client)

Async Skill CRUD — instance methods backed by a shared client.

Source code in dashscope/applications/agentstudio/resources/skills.py
183
184
185
def __init__(self, client) -> None:
    self._client = client
    self.versions = AsyncSkillVersions(client)

versions instance-attribute

versions = AsyncSkillVersions(client)

get class-attribute instance-attribute

get = retrieve

call class-attribute instance-attribute

call = create

create async

create(
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None
) -> Skill
Source code in dashscope/applications/agentstudio/resources/skills.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
async def create(
    self,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None,
) -> Skill:
    resolved = await _resolve_file_id_async(
        client=self._client,
        file_id=file_id,
        file=file,
        mime_type=mime_type,
    )
    body = SkillCreateParams(file_id=resolved).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_SKILLS,
        json=body,
    )
    return _coerce_skill(resp.data)

retrieve async

retrieve(skill_id: str) -> Skill
Source code in dashscope/applications/agentstudio/resources/skills.py
208
209
210
211
212
213
async def retrieve(self, skill_id: str) -> Skill:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}",
    )
    return _coerce_skill(resp.data)

list async

list(
    *,
    source: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[Skill]
Source code in dashscope/applications/agentstudio/resources/skills.py
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
async def list(
    self,
    *,
    source: Optional[str] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[Skill]:
    params = SkillListParams(
        source=source,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_SKILLS,
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[Skill]:
        return await self.list(
            source=source,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_skill,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(skill_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/skills.py
254
255
256
257
258
259
async def delete(self, skill_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_SKILLS}/{skill_id}",
    )
    return DeleteResponse(**resp.data)

SkillVersions

SkillVersions(client)

Skill version sub-resource.

Source code in dashscope/applications/agentstudio/resources/skills.py
113
114
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(
    skill_id: str,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None
) -> SkillVersion
Source code in dashscope/applications/agentstudio/resources/skills.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def create(
    self,
    skill_id: str,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None,
) -> SkillVersion:
    resolved = _resolve_file_id_sync(
        client=self._client,
        file_id=file_id,
        file=file,
        mime_type=mime_type,
    )
    body = SkillVersionCreateParams(file_id=resolved).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_SKILLS}/{skill_id}/versions",
        json=body,
    )
    return _coerce_skill_version(resp.data)

list

list(
    skill_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[SkillVersion]
Source code in dashscope/applications/agentstudio/resources/skills.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def list(
    self,
    skill_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[SkillVersion]:
    params = SkillVersionListParams(limit=limit, page=page).to_dict()
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions",
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_skill_version,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            skill_id,
            limit=limit,
            page=nxt,
        ),
    )

retrieve

retrieve(skill_id: str, version: str) -> SkillVersion
Source code in dashscope/applications/agentstudio/resources/skills.py
162
163
164
165
166
167
def retrieve(self, skill_id: str, version: str) -> SkillVersion:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions/{version}",
    )
    return _coerce_skill_version(resp.data)

download

download(skill_id: str, version: str) -> Dict[str, Any]
Source code in dashscope/applications/agentstudio/resources/skills.py
172
173
174
175
176
177
def download(self, skill_id: str, version: str) -> Dict[str, Any]:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions/{version}/content",
    )
    return dict(resp.data)

AsyncSkillVersions

AsyncSkillVersions(client)

Async skill version sub-resource.

Source code in dashscope/applications/agentstudio/resources/skills.py
265
266
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(
    skill_id: str,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None
) -> SkillVersion
Source code in dashscope/applications/agentstudio/resources/skills.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
async def create(
    self,
    skill_id: str,
    *,
    file_id: Optional[str] = None,
    file: Optional[FileSource] = None,
    mime_type: Optional[str] = None,
) -> SkillVersion:
    resolved = await _resolve_file_id_async(
        client=self._client,
        file_id=file_id,
        file=file,
        mime_type=mime_type,
    )
    body = SkillVersionCreateParams(file_id=resolved).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_SKILLS}/{skill_id}/versions",
        json=body,
    )
    return _coerce_skill_version(resp.data)

list async

list(
    skill_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[SkillVersion]
Source code in dashscope/applications/agentstudio/resources/skills.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
async def list(
    self,
    skill_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[SkillVersion]:
    params = SkillVersionListParams(limit=limit, page=page).to_dict()
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions",
        params=params,
    )

    async def fetch_next(nxt: str) -> AsyncCursorPage[SkillVersion]:
        return await self.list(
            skill_id,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_skill_version,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

retrieve async

retrieve(skill_id: str, version: str) -> SkillVersion
Source code in dashscope/applications/agentstudio/resources/skills.py
319
320
321
322
323
324
async def retrieve(self, skill_id: str, version: str) -> SkillVersion:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions/{version}",
    )
    return _coerce_skill_version(resp.data)

download async

download(skill_id: str, version: str) -> Dict[str, Any]
Source code in dashscope/applications/agentstudio/resources/skills.py
329
330
331
332
333
334
async def download(self, skill_id: str, version: str) -> Dict[str, Any]:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_SKILLS}/{skill_id}/versions/{version}/content",
    )
    return dict(resp.data)

Vaults & credentials

Vaults

Vaults(client)
Source code in dashscope/applications/agentstudio/resources/vaults.py
159
160
161
def __init__(self, client) -> None:
    self._client = client
    self.credentials = Credentials(client)

credentials instance-attribute

credentials = Credentials(client)

get class-attribute instance-attribute

get = retrieve

create

create(
    *,
    display_name: str,
    metadata: Optional[Mapping[str, Any]] = None
) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def create(
    self,
    *,
    display_name: str,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Vault:
    body = VaultCreateParams(
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        _PATH_VAULTS,
        json=body,
    )
    return _coerce_vault(resp.data)

retrieve

retrieve(vault_id: str) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
180
181
182
183
184
185
def retrieve(self, vault_id: str) -> Vault:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}",
    )
    return _coerce_vault(resp.data)

update

update(
    vault_id: str,
    *,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def update(
    self,
    vault_id: str,
    *,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Vault:
    body = VaultUpdateParams(
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}",
        json=body,
    )
    return _coerce_vault(resp.data)

list

list(
    *,
    keyword: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[Vault]
Source code in dashscope/applications/agentstudio/resources/vaults.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
def list(
    self,
    *,
    keyword: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[Vault]:
    params = VaultListParams(
        keyword=keyword,
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_VAULTS,
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_vault,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            keyword=keyword,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        ),
    )

delete

delete(vault_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/vaults.py
238
239
240
241
242
243
def delete(self, vault_id: str) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_VAULTS}/{vault_id}",
    )
    return DeleteResponse(**resp.data)

archive

archive(vault_id: str) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
245
246
247
248
249
250
def archive(self, vault_id: str) -> Vault:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/archive",
    )
    return _coerce_vault(resp.data)

AsyncVaults

AsyncVaults(client)
Source code in dashscope/applications/agentstudio/resources/vaults.py
378
379
380
def __init__(self, client) -> None:
    self._client = client
    self.credentials = AsyncCredentials(client)

credentials instance-attribute

credentials = AsyncCredentials(client)

get class-attribute instance-attribute

get = retrieve

create async

create(
    *,
    display_name: str,
    metadata: Optional[Mapping[str, Any]] = None
) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
async def create(
    self,
    *,
    display_name: str,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Vault:
    body = VaultCreateParams(
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        _PATH_VAULTS,
        json=body,
    )
    return _coerce_vault(resp.data)

retrieve async

retrieve(vault_id: str) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
399
400
401
402
403
404
async def retrieve(self, vault_id: str) -> Vault:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}",
    )
    return _coerce_vault(resp.data)

update async

update(
    vault_id: str,
    *,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
async def update(
    self,
    vault_id: str,
    *,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Vault:
    body = VaultUpdateParams(
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}",
        json=body,
    )
    return _coerce_vault(resp.data)

list async

list(
    *,
    keyword: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[Vault]
Source code in dashscope/applications/agentstudio/resources/vaults.py
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
async def list(
    self,
    *,
    keyword: Optional[str] = None,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[Vault]:
    params = VaultListParams(
        keyword=keyword,
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_VAULTS,
        params=params,
    )

    async def fetch_next(
        nxt: str,
    ) -> AsyncCursorPage[Vault]:
        return await self.list(
            keyword=keyword,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_vault,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(vault_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/vaults.py
464
465
466
467
468
469
async def delete(self, vault_id: str) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_VAULTS}/{vault_id}",
    )
    return DeleteResponse(**resp.data)

archive async

archive(vault_id: str) -> Vault
Source code in dashscope/applications/agentstudio/resources/vaults.py
471
472
473
474
475
476
async def archive(self, vault_id: str) -> Vault:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/archive",
    )
    return _coerce_vault(resp.data)

Credentials

Credentials(client)
Source code in dashscope/applications/agentstudio/resources/vaults.py
42
43
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(
    vault_id: str,
    *,
    auth: Any,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def create(
    self,
    vault_id: str,
    *,
    auth: Any,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Credential:
    body = CredentialCreateParams(
        auth=auth,
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials",
        json=body,
    )
    return _coerce_credential(resp.data)

retrieve

retrieve(vault_id: str, credential_id: str) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
65
66
67
68
69
70
71
72
73
74
def retrieve(
    self,
    vault_id: str,
    credential_id: str,
) -> Credential:
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
    )
    return _coerce_credential(resp.data)

update

update(
    vault_id: str,
    credential_id: str,
    *,
    auth: Any = None,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def update(
    self,
    vault_id: str,
    credential_id: str,
    *,
    auth: Any = None,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Credential:
    body = CredentialUpdateParams(
        auth=auth,
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
        json=body,
    )
    return _coerce_credential(resp.data)

list

list(
    vault_id: str,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[Credential]
Source code in dashscope/applications/agentstudio/resources/vaults.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def list(
    self,
    vault_id: str,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[Credential]:
    params = CredentialListParams(
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}/credentials",
        params=params,
    )
    return build_page(
        payload=resp.data,
        item_factory=_coerce_credential,
        request_id=resp.request_id,
        fetch_next=lambda nxt: self.list(
            vault_id,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        ),
    )

delete

delete(vault_id: str, credential_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/vaults.py
129
130
131
132
133
134
135
136
137
138
def delete(
    self,
    vault_id: str,
    credential_id: str,
) -> DeleteResponse:
    resp = self._client.transport.request(
        "DELETE",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
    )
    return DeleteResponse(**resp.data)

archive

archive(vault_id: str, credential_id: str) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
140
141
142
143
144
145
146
147
148
149
150
def archive(
    self,
    vault_id: str,
    credential_id: str,
) -> Credential:
    resp = self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials"
        f"/{credential_id}/archive",
    )
    return _coerce_credential(resp.data)

AsyncCredentials

AsyncCredentials(client)
Source code in dashscope/applications/agentstudio/resources/vaults.py
259
260
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(
    vault_id: str,
    *,
    auth: Any,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
async def create(
    self,
    vault_id: str,
    *,
    auth: Any,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Credential:
    body = CredentialCreateParams(
        auth=auth,
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials",
        json=body,
    )
    return _coerce_credential(resp.data)

retrieve async

retrieve(vault_id: str, credential_id: str) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
282
283
284
285
286
287
288
289
290
291
async def retrieve(
    self,
    vault_id: str,
    credential_id: str,
) -> Credential:
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
    )
    return _coerce_credential(resp.data)

update async

update(
    vault_id: str,
    credential_id: str,
    *,
    auth: Any = None,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
async def update(
    self,
    vault_id: str,
    credential_id: str,
    *,
    auth: Any = None,
    display_name: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Credential:
    body = CredentialUpdateParams(
        auth=auth,
        display_name=display_name,
        metadata=metadata,
    ).to_dict()
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
        json=body,
    )
    return _coerce_credential(resp.data)

list async

list(
    vault_id: str,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[Credential]
Source code in dashscope/applications/agentstudio/resources/vaults.py
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
async def list(
    self,
    vault_id: str,
    *,
    include_archived: Optional[bool] = None,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[Credential]:
    params = CredentialListParams(
        include_archived=include_archived,
        limit=limit,
        page=page,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        f"{_PATH_VAULTS}/{vault_id}/credentials",
        params=params,
    )

    async def fetch_next(
        nxt: str,
    ) -> AsyncCursorPage[Credential]:
        return await self.list(
            vault_id,
            include_archived=include_archived,
            limit=limit,
            page=nxt,
        )

    return build_page(
        payload=resp.data,
        item_factory=_coerce_credential,
        request_id=resp.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

delete async

delete(vault_id: str, credential_id: str) -> DeleteResponse
Source code in dashscope/applications/agentstudio/resources/vaults.py
353
354
355
356
357
358
359
360
361
362
async def delete(
    self,
    vault_id: str,
    credential_id: str,
) -> DeleteResponse:
    resp = await self._client.transport.request(
        "DELETE",
        f"{_PATH_VAULTS}/{vault_id}/credentials" f"/{credential_id}",
    )
    return DeleteResponse(**resp.data)

archive async

archive(vault_id: str, credential_id: str) -> Credential
Source code in dashscope/applications/agentstudio/resources/vaults.py
364
365
366
367
368
369
370
371
372
373
374
async def archive(
    self,
    vault_id: str,
    credential_id: str,
) -> Credential:
    resp = await self._client.transport.request(
        "POST",
        f"{_PATH_VAULTS}/{vault_id}/credentials"
        f"/{credential_id}/archive",
    )
    return _coerce_credential(resp.data)

Security & webhooks

Security

Security(client)

Security center read interface (overview + agent logs).

Source code in dashscope/applications/agentstudio/resources/security.py
38
39
def __init__(self, client) -> None:
    self._client = client

overview

overview() -> SecurityOverview

24h protection dashboard (GET /security/overview).

Source code in dashscope/applications/agentstudio/resources/security.py
41
42
43
44
45
46
47
def overview(self) -> SecurityOverview:
    """24h protection dashboard (``GET /security/overview``)."""
    resp = self._client.transport.request(
        "GET",
        _PATH_SECURITY_OVERVIEW,
    )
    return _overview_from_payload(resp.data)

list_agent_logs

list_agent_logs(
    *,
    current_page: Optional[int] = None,
    page_size: Optional[int] = None,
    risk_level: Optional[str] = None,
    status: Optional[str] = None,
    risk_name: Optional[str] = None,
    app_name: Optional[str] = None,
    asset_type: Optional[str] = None,
    vendor: Optional[str] = None,
    order_by: Optional[str] = None,
    order: Optional[str] = None,
    lang: Optional[str] = None,
    status_list: Optional[Sequence[str]] = None
) -> SecurityAlertList

Alert list (GET /security/agent_logs).

Page-number pagination: pass current_page + 1 for the next page, or use the returned next_page cursor if non-null. check_time / handle_time on rows are millisecond strings.

Source code in dashscope/applications/agentstudio/resources/security.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def list_agent_logs(
    self,
    *,
    current_page: Optional[int] = None,
    page_size: Optional[int] = None,
    risk_level: Optional[str] = None,
    status: Optional[str] = None,
    risk_name: Optional[str] = None,
    app_name: Optional[str] = None,
    asset_type: Optional[str] = None,
    vendor: Optional[str] = None,
    order_by: Optional[str] = None,
    order: Optional[str] = None,
    lang: Optional[str] = None,
    status_list: Optional[Sequence[str]] = None,
) -> SecurityAlertList:
    """Alert list (``GET /security/agent_logs``).

    Page-number pagination: pass ``current_page + 1`` for the next
    page, or use the returned ``next_page`` cursor if non-null.
    ``check_time`` / ``handle_time`` on rows are millisecond strings.
    """
    params = SecurityListAgentLogsParams(
        current_page=current_page,
        page_size=page_size,
        risk_level=risk_level,
        status=status,
        risk_name=risk_name,
        app_name=app_name,
        asset_type=asset_type,
        vendor=vendor,
        order_by=order_by,
        order=order,
        lang=lang,
        status_list=status_list,
    ).to_dict()
    resp = self._client.transport.request(
        "GET",
        _PATH_SECURITY_AGENT_LOGS,
        params=params,
    )
    return _alert_list_from_payload(resp.data)

AsyncSecurity

AsyncSecurity(client)

Async security center read interface.

Source code in dashscope/applications/agentstudio/resources/security.py
96
97
def __init__(self, client) -> None:
    self._client = client

overview async

overview() -> SecurityOverview
Source code in dashscope/applications/agentstudio/resources/security.py
 99
100
101
102
103
104
async def overview(self) -> SecurityOverview:
    resp = await self._client.transport.request(
        "GET",
        _PATH_SECURITY_OVERVIEW,
    )
    return _overview_from_payload(resp.data)

list_agent_logs async

list_agent_logs(
    *,
    current_page: Optional[int] = None,
    page_size: Optional[int] = None,
    risk_level: Optional[str] = None,
    status: Optional[str] = None,
    risk_name: Optional[str] = None,
    app_name: Optional[str] = None,
    asset_type: Optional[str] = None,
    vendor: Optional[str] = None,
    order_by: Optional[str] = None,
    order: Optional[str] = None,
    lang: Optional[str] = None,
    status_list: Optional[Sequence[str]] = None
) -> SecurityAlertList
Source code in dashscope/applications/agentstudio/resources/security.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
async def list_agent_logs(
    self,
    *,
    current_page: Optional[int] = None,
    page_size: Optional[int] = None,
    risk_level: Optional[str] = None,
    status: Optional[str] = None,
    risk_name: Optional[str] = None,
    app_name: Optional[str] = None,
    asset_type: Optional[str] = None,
    vendor: Optional[str] = None,
    order_by: Optional[str] = None,
    order: Optional[str] = None,
    lang: Optional[str] = None,
    status_list: Optional[Sequence[str]] = None,
) -> SecurityAlertList:
    params = SecurityListAgentLogsParams(
        current_page=current_page,
        page_size=page_size,
        risk_level=risk_level,
        status=status,
        risk_name=risk_name,
        app_name=app_name,
        asset_type=asset_type,
        vendor=vendor,
        order_by=order_by,
        order=order,
        lang=lang,
        status_list=status_list,
    ).to_dict()
    resp = await self._client.transport.request(
        "GET",
        _PATH_SECURITY_AGENT_LOGS,
        params=params,
    )
    return _alert_list_from_payload(resp.data)

WebhookEndpoints

WebhookEndpoints(client)

Synchronous Managed Agent webhook endpoint APIs.

Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
39
40
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create

create(
    *,
    url: str,
    events: Sequence[str],
    description: Optional[str] = None
) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def create(
    self,
    *,
    url: str,
    events: Sequence[str],
    description: Optional[str] = None,
) -> WebhookEndpoint:
    body = WebhookEndpointCreateParams(
        url=url,
        events=list(events),
        description=description,
    ).to_dict()
    response = self._client.transport.request(
        "POST",
        _PATH_WEBHOOK_ENDPOINTS,
        json=body,
    )
    return _coerce_webhook_endpoint(response.data)

retrieve

retrieve(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
61
62
63
64
65
66
def retrieve(self, webhook_id: str) -> WebhookEndpoint:
    response = self._client.transport.request(
        "GET",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
    )
    return _coerce_webhook_endpoint(response.data)

list

list() -> WebhookEndpointList
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
70
71
72
73
74
75
def list(self) -> WebhookEndpointList:
    response = self._client.transport.request(
        "GET",
        _PATH_WEBHOOK_ENDPOINTS,
    )
    return WebhookEndpointList(**response.data)

update

update(
    webhook_id: str,
    *,
    description: Optional[str] = None,
    url: Optional[str] = None,
    events: Optional[Sequence[str]] = None
) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def update(
    self,
    webhook_id: str,
    *,
    description: Optional[str] = None,
    url: Optional[str] = None,
    events: Optional[Sequence[str]] = None,
) -> WebhookEndpoint:
    body = WebhookEndpointUpdateParams(
        description=description,
        url=url,
        events=list(events) if events is not None else None,
    ).to_dict()
    response = self._client.transport.request(
        "PUT",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
        json=body,
    )
    return _coerce_webhook_endpoint(response.data)

delete

delete(webhook_id: str) -> Dict[str, Any]
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
 97
 98
 99
100
101
102
def delete(self, webhook_id: str) -> Dict[str, Any]:
    response = self._client.transport.request(
        "DELETE",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
    )
    return response.data

enable

enable(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
104
105
106
107
108
109
def enable(self, webhook_id: str) -> WebhookEndpoint:
    response = self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/enable",
    )
    return _coerce_webhook_endpoint(response.data)

disable

disable(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
111
112
113
114
115
116
def disable(self, webhook_id: str) -> WebhookEndpoint:
    response = self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/disable",
    )
    return _coerce_webhook_endpoint(response.data)

test

test(webhook_id: str) -> WebhookEvent
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
118
119
120
121
122
123
def test(self, webhook_id: str) -> WebhookEvent:
    response = self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/test",
    )
    return _coerce_webhook_event(response.data)

reset_secret

reset_secret(webhook_id: str) -> WebhookSecretReset
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
125
126
127
128
129
130
def reset_secret(self, webhook_id: str) -> WebhookSecretReset:
    response = self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/reset_secret",
    )
    return _coerce_webhook_secret_reset(response.data)

list_events

list_events(
    webhook_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> CursorPage[WebhookEvent]
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def list_events(
    self,
    webhook_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> CursorPage[WebhookEvent]:
    params = WebhookEventListParams(limit=limit, page=page).to_dict()
    response = self._client.transport.request(
        "GET",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/events",
        params=params,
    )
    return build_page(
        payload=response.data,
        item_factory=_coerce_webhook_event,
        request_id=response.request_id,
        fetch_next=lambda cursor: self.list_events(
            webhook_id,
            limit=limit,
            page=cursor,
        ),
    )

AsyncWebhookEndpoints

AsyncWebhookEndpoints(client)

Asynchronous Managed Agent webhook endpoint APIs.

Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
160
161
def __init__(self, client) -> None:
    self._client = client

get class-attribute instance-attribute

get = retrieve

create async

create(
    *,
    url: str,
    events: Sequence[str],
    description: Optional[str] = None
) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
async def create(
    self,
    *,
    url: str,
    events: Sequence[str],
    description: Optional[str] = None,
) -> WebhookEndpoint:
    body = WebhookEndpointCreateParams(
        url=url,
        events=list(events),
        description=description,
    ).to_dict()
    response = await self._client.transport.request(
        "POST",
        _PATH_WEBHOOK_ENDPOINTS,
        json=body,
    )
    return _coerce_webhook_endpoint(response.data)

retrieve async

retrieve(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
182
183
184
185
186
187
async def retrieve(self, webhook_id: str) -> WebhookEndpoint:
    response = await self._client.transport.request(
        "GET",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
    )
    return _coerce_webhook_endpoint(response.data)

list async

list() -> WebhookEndpointList
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
191
192
193
194
195
196
async def list(self) -> WebhookEndpointList:
    response = await self._client.transport.request(
        "GET",
        _PATH_WEBHOOK_ENDPOINTS,
    )
    return WebhookEndpointList(**response.data)

update async

update(
    webhook_id: str,
    *,
    description: Optional[str] = None,
    url: Optional[str] = None,
    events: Optional[Sequence[str]] = None
) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
async def update(
    self,
    webhook_id: str,
    *,
    description: Optional[str] = None,
    url: Optional[str] = None,
    events: Optional[Sequence[str]] = None,
) -> WebhookEndpoint:
    body = WebhookEndpointUpdateParams(
        description=description,
        url=url,
        events=list(events) if events is not None else None,
    ).to_dict()
    response = await self._client.transport.request(
        "PUT",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
        json=body,
    )
    return _coerce_webhook_endpoint(response.data)

delete async

delete(webhook_id: str) -> Dict[str, Any]
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
218
219
220
221
222
223
async def delete(self, webhook_id: str) -> Dict[str, Any]:
    response = await self._client.transport.request(
        "DELETE",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}",
    )
    return response.data

enable async

enable(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
225
226
227
228
229
230
async def enable(self, webhook_id: str) -> WebhookEndpoint:
    response = await self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/enable",
    )
    return _coerce_webhook_endpoint(response.data)

disable async

disable(webhook_id: str) -> WebhookEndpoint
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
232
233
234
235
236
237
async def disable(self, webhook_id: str) -> WebhookEndpoint:
    response = await self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/disable",
    )
    return _coerce_webhook_endpoint(response.data)

test async

test(webhook_id: str) -> WebhookEvent
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
239
240
241
242
243
244
async def test(self, webhook_id: str) -> WebhookEvent:
    response = await self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/test",
    )
    return _coerce_webhook_event(response.data)

reset_secret async

reset_secret(webhook_id: str) -> WebhookSecretReset
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
246
247
248
249
250
251
async def reset_secret(self, webhook_id: str) -> WebhookSecretReset:
    response = await self._client.transport.request(
        "POST",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/reset_secret",
    )
    return _coerce_webhook_secret_reset(response.data)

list_events async

list_events(
    webhook_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None
) -> AsyncCursorPage[WebhookEvent]
Source code in dashscope/applications/agentstudio/resources/webhook_endpoints.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
async def list_events(
    self,
    webhook_id: str,
    *,
    limit: Optional[int] = None,
    page: Optional[str] = None,
) -> AsyncCursorPage[WebhookEvent]:
    params = WebhookEventListParams(limit=limit, page=page).to_dict()
    response = await self._client.transport.request(
        "GET",
        f"{_PATH_WEBHOOK_ENDPOINTS}/{webhook_id}/events",
        params=params,
    )

    async def fetch_next(cursor: str) -> AsyncCursorPage[WebhookEvent]:
        return await self.list_events(
            webhook_id,
            limit=limit,
            page=cursor,
        )

    return build_page(
        payload=response.data,
        item_factory=_coerce_webhook_event,
        request_id=response.request_id,
        page_cls=AsyncCursorPage,
        fetch_next=fetch_next,
    )

Client event helpers

user_message

user_message(
    text_or_blocks: Any,
    *,
    session_thread_id: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Dict[str, Any]

Build a message client event (AGENTSTUDIO wire format).

text_or_blocks may be a plain string (wrapped as a text block) or a list of pre-built content block dicts.

Source code in dashscope/applications/agentstudio/types/models.py
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
def user_message(
    text_or_blocks: Any,
    *,
    session_thread_id: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Dict[str, Any]:
    """Build a ``message`` client event (AGENTSTUDIO wire format).

    ``text_or_blocks`` may be a plain string (wrapped as a text block)
    or a list of pre-built content block dicts.
    """

    if isinstance(text_or_blocks, str):
        content: List[Dict[str, Any]] = [
            {"type": BlockType.TEXT, "text": text_or_blocks},
        ]
    else:
        content = list(text_or_blocks)
    evt: Dict[str, Any] = {
        "role": MessageRole.USER,
        "type": SSEEventType.MESSAGE,
        "content": content,
    }
    if session_thread_id:
        evt["session_thread_id"] = session_thread_id
    if metadata:
        evt["metadata"] = dict(metadata)
    return evt

user_interrupt

user_interrupt(
    *,
    session_thread_id: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
) -> Dict[str, Any]

Cancel the agent's current turn (best-effort).

Source code in dashscope/applications/agentstudio/types/models.py
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
def user_interrupt(
    *,
    session_thread_id: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> Dict[str, Any]:
    """Cancel the agent's current turn (best-effort)."""

    evt: Dict[str, Any] = {
        "role": MessageRole.USER,
        "type": SSEEventType.INTERRUPT,
    }
    if session_thread_id:
        evt["session_thread_id"] = session_thread_id
    if metadata:
        evt["metadata"] = dict(metadata)
    return evt

user_tool_result

user_tool_result(
    *,
    tool_use_id: str,
    content: Any,
    is_error: bool = False,
    session_thread_id: Optional[str] = None
) -> Dict[str, Any]

Self-hosted tool result (advanced; mirrors built-in tool execution).

Emits a tool_call_output event in the AGENTSTUDIO wire format.

Source code in dashscope/applications/agentstudio/types/models.py
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
def user_tool_result(
    *,
    tool_use_id: str,
    content: Any,
    is_error: bool = False,
    session_thread_id: Optional[str] = None,
) -> Dict[str, Any]:
    """Self-hosted tool result (advanced; mirrors built-in tool execution).

    Emits a ``tool_call_output`` event in the AGENTSTUDIO wire format.
    """

    if isinstance(content, str):
        output = content
    elif isinstance(content, Sequence) and not isinstance(content, str):
        output = list(content)
    else:
        output = content
    evt: Dict[str, Any] = {
        "role": MessageRole.TOOL,
        "type": SSEEventType.TOOL_CALL_OUTPUT,
        "content": [
            {
                "type": "data",
                "data": {
                    "call_id": tool_use_id,
                    "output": output,
                },
            },
        ],
        "is_error": bool(is_error),
    }
    if session_thread_id:
        evt["session_thread_id"] = session_thread_id
    return evt

user_custom_tool_result

user_custom_tool_result(
    *,
    custom_tool_use_id: str,
    content: Any,
    is_error: bool = False,
    session_thread_id: Optional[str] = None
) -> Dict[str, Any]

Reply to an :class:AgentCustomToolUseEvent with a tool result.

Emits a function_call_output event in the AGENTSTUDIO wire format.

Source code in dashscope/applications/agentstudio/types/models.py
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
def user_custom_tool_result(
    *,
    custom_tool_use_id: str,
    content: Any,
    is_error: bool = False,
    session_thread_id: Optional[str] = None,
) -> Dict[str, Any]:
    """Reply to an :class:`AgentCustomToolUseEvent` with a tool result.

    Emits a ``function_call_output`` event in the AGENTSTUDIO wire format.
    """

    if isinstance(content, str):
        output = content
    elif isinstance(content, Sequence) and not isinstance(content, str):
        output = list(content)
    else:
        output = content
    evt: Dict[str, Any] = {
        "role": MessageRole.TOOL,
        "type": SSEEventType.FUNCTION_CALL_OUTPUT,
        "content": [
            {
                "type": "data",
                "data": {
                    "call_id": custom_tool_use_id,
                    "output": output,
                },
            },
        ],
        "is_error": bool(is_error),
    }
    if session_thread_id:
        evt["session_thread_id"] = session_thread_id
    return evt

user_tool_approval_response

user_tool_approval_response(
    *,
    batch_id: str,
    call_id: str,
    result: str,
    deny_message: Optional[str] = None
) -> Dict[str, Any]

Submit a tool approval ruling for an always_ask tool call.

result must be "allow" or "deny"; deny_message is optional and only meaningful when denying. The approval identity is the (batch_id, call_id) composite key — call_id may be reused across turns, so never match on call_id alone. Approval responses target the primary thread only (no session_thread_id); the legacy tool_confirmation type is rejected by the server (HTTP 400 bma_invalid_event).

Source code in dashscope/applications/agentstudio/types/models.py
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
def user_tool_approval_response(
    *,
    batch_id: str,
    call_id: str,
    result: str,
    deny_message: Optional[str] = None,
) -> Dict[str, Any]:
    """Submit a tool approval ruling for an ``always_ask`` tool call.

    ``result`` must be ``"allow"`` or ``"deny"``; ``deny_message`` is
    optional and only meaningful when denying. The approval identity is the
    ``(batch_id, call_id)`` composite key — ``call_id`` may be reused across
    turns, so never match on ``call_id`` alone. Approval responses target
    the primary thread only (no ``session_thread_id``); the legacy
    ``tool_confirmation`` type is rejected by the server (HTTP 400
    ``bma_invalid_event``).
    """
    if result not in ("allow", "deny"):
        raise ValueError("result must be 'allow' or 'deny'")
    data: Dict[str, Any] = {
        "batch_id": batch_id,
        "call_id": call_id,
        "result": result,
    }
    if deny_message and result == "deny":
        data["deny_message"] = deny_message
    return {
        "role": MessageRole.USER,
        "type": SSEEventType.TOOL_APPROVAL_RESPONSE,
        "content": [{"type": "data", "data": data}],
    }

user_define_outcome

user_define_outcome(
    *,
    description: str,
    rubric: Optional[str] = None,
    max_iterations: Optional[int] = None,
    session_thread_id: Optional[str] = None
) -> Dict[str, Any]

Steer the agent towards a measurable outcome.

Source code in dashscope/applications/agentstudio/types/models.py
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
def user_define_outcome(
    *,
    description: str,
    rubric: Optional[str] = None,
    max_iterations: Optional[int] = None,
    session_thread_id: Optional[str] = None,
) -> Dict[str, Any]:
    """Steer the agent towards a measurable outcome."""

    data: Dict[str, Any] = {"description": description}
    if rubric is not None:
        data["rubric"] = rubric
    if max_iterations is not None:
        data["max_iterations"] = int(max_iterations)
    evt: Dict[str, Any] = {
        "role": MessageRole.USER,
        "type": SSEEventType.DEFINE_OUTCOME,
        "content": [{"type": "data", "data": data}],
    }
    if session_thread_id:
        evt["session_thread_id"] = session_thread_id
    return evt

Core types

Message

Message(**kwargs: Any)

Bases: BaseModel

Unified event/message model corresponding to the AgentStudio API protocol Message structure.

All SSE stream events and history events share this structure. The type field discriminates between event kinds::

message, tool_call, tool_call_output, function_call,
function_call_output, mcp_call, mcp_call_output, reasoning,
session_status, error, session_updated, thread_created,
thread_status, thread_message_sent, thread_message_received,
thread_context_compacted, model_request_start, model_request_end,
outcome_evaluation, interrupt, tool_confirmation, define_outcome

Legacy agent.* / session.* / span.* type strings are also accepted transparently for backward compatibility.

Source code in dashscope/applications/agentstudio/types/models.py
1062
1063
1064
1065
1066
def __init__(self, **kwargs: Any) -> None:
    content = kwargs.get("content")
    if isinstance(content, list):
        kwargs["content"] = parse_content_blocks(content)
    super().__init__(**kwargs)

stop_reason property

stop_reason: Optional[Dict[str, Any]]

stop_reason carried by session_status idle events.

The server puts stop_reason inside the session_status event's data block (not in session.retrieve()). Returns a dict like {"type": "end_turn"} or None for non-session_status events.

session_status property

session_status: Optional[str]

session_status value from session_status events.

Returns "idle", "running", "rescheduled", "terminated", "deleted" or None for non-session_status events.

tool_approval_request property

tool_approval_request: Optional[Dict[str, Any]]

tool_approval_request payload: batch_id / call_id / name / arguments (JSON string) / tool_type / server_label (MCP only).

Returns None for non-tool_approval_request events. The approval identity is the (batch_id, call_id) composite key — call_id may be reused across turns, so never match on call_id alone.

error property

error: Optional[Dict[str, Any]]

{"code", "message"} from type: error events, else None.

Approval failures surface in the event stream as type: error events (not as HTTP exceptions). Use :attr:pending_tool_approvals to read the suspend signal alongside this.

pending_tool_approvals property

pending_tool_approvals: Optional[Dict[str, Any]]

Suspend signal {"batch_id", "call_ids"} carried in the metadata of an error / response frame while the approval barrier is up. None when the barrier is not up.

This is the reliable way to tell pending state — do NOT derive it from request/response event diffs (the server emits it only while the barrier stands).

event_start property

event_start: Optional[Dict[str, Any]]

{"id", "type"} from an event_start delta frame (a preview of an upcoming message/reasoning event; carries no content). None for other frames.

event_delta property

event_delta: Optional[Dict[str, Any]]

{"event_id", "delta": {"type", "index", "content"}} from an event_delta frame. None for other frames.

delta_text property

delta_text: Optional[str]

Incremental text chunk from an event_delta frame (the delta.content.text of a content_delta), else None. Use the :attr:text_deltas iterator on the stream for the full sequence.

data property

data: Optional[Dict[str, Any]]

The first content block's data payload, for events that carry one (tool_call / tool_call_output / mcp_call / mcp_call_output / session_status / tool_approval_request / model_request_end / outcome_evaluation / thread_status / thread_created / session_updated). None otherwise.

outcome_evaluation property

outcome_evaluation: Optional[Dict[str, Any]]

outcome_evaluation payload: outcome_id, iteration, phase (start/ongoing/end), result, explanation, token usage, speed. None for other events.

thread_status property

thread_status: Optional[Dict[str, Any]]

thread_status payload: session_thread_id, agent_name, thread_status (running/idle/terminated/rescheduled), and stop_reason when idle. None for other events.

thread_created property

thread_created: Optional[Dict[str, Any]]

thread_created payload: session_thread_id, agent_name. None for other events.

session_updated property

session_updated: Optional[Dict[str, Any]]

session_updated payload: title, session_metadata, agent (only the changed fields, present when changed). None for other events.

thread_message_routing property

thread_message_routing: Optional[Dict[str, str]]

Sub-agent routing from thread_message_sent / thread_message_received metadata: to_session_thread_id / to_agent_name on sent, from_session_thread_id / from_agent_name on received. None for other events.

ServerEvent module-attribute

ServerEvent = Message

SessionResource

SessionResource(**kwargs: Any)

Bases: BaseModel

A resource mounted into a session (file / memory_store / oss).

file: file_id is the session-scoped copy id (not the source file id); mount_path resolves under /uploads/. Memory and OSS mounts are create-only — sessions.resources.add accepts files only.

memory_store: access (read_write default) and instructions; name/description are server-snapshotted for built-in (provider="default") mounts, which also carry the server-generated mount_path (/mnt/memory/<name>); agentstudio_memory (Bailian) mounts echo entity_id and the configured project_ids/profile_schema/description, with no mount_path.

oss: echoes region/bucket/oss_path and the user-supplied logical mount_path (the sandbox resolves it under /mnt/oss/).

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

StopReason

StopReason(**kwargs: Any)

Bases: BaseModel

Carried by session_status idle events (and Session.stop_reason).

A running Session's stop_reason is null. requires_action carries pending_batch_id + pending_call_ids (only the calls not yet adjudicated); do not derive pending from request/response diffs.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

Memory

Memory(**kwargs: Any)

Bases: BaseModel

One text document inside a memory store, addressed by path.

content appears only in retrieve responses and in list responses with view="full"; create and update never return it. content_sha256 identifies the content revision — pass it back to memories.update for optimistic concurrency (a mismatch returns 409 memory_precondition_failed_error).

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

MemoryStore

MemoryStore(**kwargs: Any)

Bases: BaseModel

A workspace-scoped store of small text documents.

Stores persist across sessions and are mounted into a session container at /mnt/memory/<name>/ when attached via the session resources[] array. archived_at is set once the store is archived: read-only afterwards, existing session attachments keep working, but new sessions cannot reference it.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

MemoryVersion

MemoryVersion(**kwargs: Any)

Bases: BaseModel

Immutable snapshot produced by every memory mutation; versions are returned newest-first.

operation is created / modified / deleted. After redact, path, content, content_sha256 and content_size_bytes are cleared; the audit trail is preserved.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

PermissionPolicy

PermissionPolicy(**kwargs: Any)

Bases: BaseModel

Tool approval policy (permission_policy on tool configs).

Must be the object form {"type": "always_allow" | "always_ask"}; the string form is rejected (the server rejects it as well). Defaults to always_allow when omitted.

Source code in dashscope/applications/agentstudio/types/models.py
242
243
244
245
246
247
248
249
250
251
def __init__(self, **kwargs: Any) -> None:
    t = kwargs.get("type")
    if isinstance(t, str) and t not in ("always_allow", "always_ask"):
        raise ValueError(
            "permission_policy.type must be 'always_allow' or "
            "'always_ask'",
        )
    if t is None:
        kwargs["type"] = "always_allow"
    super().__init__(**kwargs)

SecurityAlert

SecurityAlert(**kwargs: Any)

Bases: BaseModel

A single security alert row. check_time / handle_time are millisecond-string timestamps (not ISO 8601).

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

SecurityAlertList

SecurityAlertList(**kwargs: Any)

Bases: BaseModel

Response of GET /security/agent_logs (page-number + cursor).

Source code in dashscope/applications/agentstudio/types/models.py
795
796
797
798
799
800
801
802
803
804
805
def __init__(self, **kwargs: Any) -> None:
    stats = kwargs.get("stats")
    if isinstance(stats, Mapping):
        kwargs["stats"] = SecurityAlertStats(**dict(stats))
    data = kwargs.get("data")
    if isinstance(data, list):
        kwargs["data"] = [
            SecurityAlert(**dict(it)) if isinstance(it, Mapping) else it
            for it in data
        ]
    super().__init__(**kwargs)

SecurityOverview

SecurityOverview(**kwargs: Any)

Bases: BaseModel

Response of GET /security/overview (last-24h dashboard).

Source code in dashscope/applications/agentstudio/types/models.py
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
def __init__(self, **kwargs: Any) -> None:
    for k in ("capabilities", "protection"):
        v = kwargs.get(k)
        if isinstance(v, list):
            kwargs[k] = [
                SecurityCapability(**dict(it))
                if isinstance(it, Mapping)
                else it
                for it in v
            ]
    for k in ("content_safety", "file_scan", "skill_scan"):
        v = kwargs.get(k)
        if isinstance(v, Mapping):
            kwargs[k] = SecurityScanStat(**dict(v))
    super().__init__(**kwargs)

Request parameter types

AgentCreateParams

AgentCreateParams(
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
)

Bases: BaseModel

Request body for POST /agents.

Maps to :meth:Agents.create. The SDK method exposes model as a :class:ModelConfig or a bare model id, and system_prompt as a keyword arg; the wire format uses model: {"id": "…", …} and system.

Source code in dashscope/applications/agentstudio/types/params.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def __init__(
    self,
    *,
    name: str,
    model: Union[str, ModelConfig],
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> None:
    super().__init__(
        name=name,
        model=_resolve_model(model),
        description=description,
        system=system_prompt,
        tools=([dict(t) for t in tools] if tools is not None else None),
        mcp_servers=(
            [dict(s) for s in mcp_servers]
            if mcp_servers is not None
            else None
        ),
        skills=([dict(s) for s in skills] if skills is not None else None),
        multiagent=(
            _to_mapping(multiagent) if multiagent is not None else None
        ),
        metadata=(dict(metadata) if metadata is not None else None),
    )

AgentUpdateParams

AgentUpdateParams(
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None
)

Bases: BaseModel

Request body for POST /agents/{id} (update latest version).

Source code in dashscope/applications/agentstudio/types/params.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def __init__(
    self,
    *,
    version: int,
    name: Optional[str] = None,
    model: Optional[Union[str, ModelConfig]] = None,
    description: Optional[str] = None,
    system_prompt: Optional[str] = None,
    tools: Optional[Sequence[Mapping[str, Any]]] = None,
    mcp_servers: Optional[Sequence[Mapping[str, Any]]] = None,
    skills: Optional[Sequence[Mapping[str, Any]]] = None,
    multiagent: Optional[Mapping[str, Any]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> None:
    super().__init__(
        version=version,
        name=name,
        model=(_resolve_model(model) if model is not None else None),
        description=description,
        system=system_prompt,
        tools=([dict(t) for t in tools] if tools is not None else None),
        mcp_servers=(
            [dict(s) for s in mcp_servers]
            if mcp_servers is not None
            else None
        ),
        skills=([dict(s) for s in skills] if skills is not None else None),
        multiagent=(
            _to_mapping(multiagent) if multiagent is not None else None
        ),
        metadata=(dict(metadata) if metadata is not None else None),
    )

SessionCreateParams

SessionCreateParams(
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    metadata: Optional[Mapping[str, Any]] = None
)

Bases: BaseModel

Request body for POST /sessions.

agent accepts the Agent ID string (backward compatible) or an Agent reference/override object (a mapping with type="agent_with_overrides") that establishes Session-level overrides for system/tools/mcp_servers/skills.

environment_variables and mcp_configs are Session-level settings independent of the agent. resources is create-only — it cannot be modified via updateSession; each item is a mapping or a :class:~dashscope.applications.agentstudio.types.models.Mount (file / memory_store — built-in or Bailian provider="agentstudio_memory" — / oss).

Source code in dashscope/applications/agentstudio/types/params.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def __init__(  # pylint: disable=useless-parent-delegation
    self,
    *,
    agent: Any,
    environment_id: Optional[str] = None,
    title: Optional[str] = None,
    resources: Optional[Sequence[ResourceInput]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> None:
    super().__init__(
        agent=_to_mapping(agent),
        environment_id=environment_id,
        title=title,
        resources=(
            [_to_mapping(r) for r in resources]
            if resources is not None
            else None
        ),
        vault_ids=(list(vault_ids) if vault_ids is not None else None),
        environment_variables=(
            dict(environment_variables)
            if environment_variables is not None
            else None
        ),
        mcp_configs=(
            [_to_mapping(m) for m in mcp_configs]
            if mcp_configs is not None
            else None
        ),
        metadata=(dict(metadata) if metadata is not None else None),
    )

SessionUpdateParams

SessionUpdateParams(
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    agent: Any = None,
    mcp_configs: Optional[
        Sequence[Mapping[str, Any]]
    ] = None
)

Bases: BaseModel

Request body for POST /sessions/{id}.

Omitted (None) fields are not sent — the existing value is kept; [] / {} explicitly clear the value. agent is a Session-level Agent config patch (a plain mapping carrying only system/tools/ mcp_servers/skills); the mapping is passed through verbatim so an explicit None sub-field serializes to JSON null (delete the override and re-inherit), an omitted sub-field stays absent (keep the override), and [] / "" override to empty. The server enforces the override principle; the SDK does not read or merge the agent source.

Source code in dashscope/applications/agentstudio/types/params.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
def __init__(  # pylint: disable=useless-parent-delegation
    self,
    *,
    title: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    agent: Any = None,
    mcp_configs: Optional[Sequence[Mapping[str, Any]]] = None,
) -> None:
    super().__init__(
        title=title,
        metadata=(dict(metadata) if metadata is not None else None),
        vault_ids=(list(vault_ids) if vault_ids is not None else None),
        environment_variables=(
            dict(environment_variables)
            if environment_variables is not None
            else None
        ),
        agent=(_to_mapping(agent) if agent is not None else None),
        mcp_configs=(
            [_to_mapping(m) for m in mcp_configs]
            if mcp_configs is not None
            else None
        ),
    )

SessionEventSendParams

SessionEventSendParams(
    *, input: Sequence[Mapping[str, Any]]
)

Bases: BaseModel

Request body for POST /sessions/{id}/events.

The input array must contain at least one event.

Source code in dashscope/applications/agentstudio/types/params.py
459
460
461
462
463
464
465
466
467
468
def __init__(  # pylint: disable=useless-parent-delegation
    self,
    *,
    input: Sequence[  # pylint: disable=redefined-builtin
        Mapping[str, Any]
    ],
) -> None:
    super().__init__(
        input=[dict(e) for e in input],
    )

EnvironmentCreateParams

EnvironmentCreateParams(
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
)

Bases: BaseModel

Request body for POST /environments.

Source code in dashscope/applications/agentstudio/types/params.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def __init__(  # pylint: disable=useless-parent-delegation
    self,
    *,
    name: str,
    config: Mapping[str, Any],
    description: Optional[str] = None,
    scope: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> None:
    super().__init__(
        name=name,
        config=dict(config),
        description=description,
        scope=scope,
        metadata=(dict(metadata) if metadata is not None else None),
    )

EnvironmentUpdateParams

EnvironmentUpdateParams(
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    scope: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None
)

Bases: BaseModel

Request body for POST /environments/{id}.

Source code in dashscope/applications/agentstudio/types/params.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
def __init__(  # pylint: disable=useless-parent-delegation
    self,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[Mapping[str, Any]] = None,
    scope: Optional[str] = None,
    metadata: Optional[Mapping[str, Any]] = None,
) -> None:
    super().__init__(
        name=name,
        description=description,
        config=(dict(config) if config is not None else None),
        scope=scope,
        metadata=(dict(metadata) if metadata is not None else None),
    )

DeploymentCreateParams

DeploymentCreateParams(
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
)

Bases: BaseModel

Request body for POST /deployments.

Source code in dashscope/applications/agentstudio/types/params.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
def __init__(
    self,
    *,
    name: str,
    agent: Any,
    initial_events: Sequence[Mapping[str, Any]],
    description: Optional[str] = None,
    environment_id: Optional[str] = None,
    schedule: Any = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> None:
    BaseModel.__init__(
        self,
        name=name,
        description=description,
        agent=_to_mapping(agent),
        environment_id=environment_id,
        schedule=(_to_mapping(schedule) if schedule is not None else None),
        initial_events=[dict(event) for event in initial_events],
        resources=(
            [_to_mapping(resource) for resource in resources]
            if resources is not None
            else None
        ),
        vault_ids=(list(vault_ids) if vault_ids is not None else None),
        environment_variables=(
            dict(environment_variables)
            if environment_variables is not None
            else None
        ),
        metadata=(dict(metadata) if metadata is not None else None),
    )

DeploymentUpdateParams

DeploymentUpdateParams(
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[
        Sequence[Mapping[str, Any]]
    ] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[
        Mapping[str, str]
    ] = None,
    metadata: Optional[Mapping[str, str]] = None
)

Bases: BaseModel

Request body for POST /deployments/{deployment_id}.

environment_id and schedule preserve the distinction between an omitted argument and an explicit None. Explicit None is emitted as JSON null to clear the field.

Source code in dashscope/applications/agentstudio/types/params.py
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
def __init__(
    self,
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    agent: Any = None,
    environment_id: Any = _NOT_GIVEN,
    schedule: Any = _NOT_GIVEN,
    initial_events: Optional[Sequence[Mapping[str, Any]]] = None,
    resources: Optional[Sequence[Any]] = None,
    vault_ids: Optional[Sequence[str]] = None,
    environment_variables: Optional[Mapping[str, str]] = None,
    metadata: Optional[Mapping[str, str]] = None,
) -> None:
    self._environment_id_given = environment_id is not _NOT_GIVEN
    self._schedule_given = schedule is not _NOT_GIVEN
    super().__init__(
        name=name,
        description=description,
        agent=(_to_mapping(agent) if agent is not None else None),
        environment_id=(
            environment_id if self._environment_id_given else None
        ),
        schedule=(
            _to_mapping(schedule)
            if self._schedule_given and schedule is not None
            else None
        ),
        initial_events=(
            [dict(event) for event in initial_events]
            if initial_events is not None
            else None
        ),
        resources=(
            [_to_mapping(resource) for resource in resources]
            if resources is not None
            else None
        ),
        vault_ids=(list(vault_ids) if vault_ids is not None else None),
        environment_variables=(
            dict(environment_variables)
            if environment_variables is not None
            else None
        ),
        metadata=(dict(metadata) if metadata is not None else None),
    )

to_dict

to_dict() -> dict
Source code in dashscope/applications/agentstudio/types/params.py
738
739
740
741
742
743
744
def to_dict(self) -> dict:
    body = super().to_dict()
    if self._environment_id_given and self.environment_id is None:
        body["environment_id"] = None
    if self._schedule_given and self.schedule is None:
        body["schedule"] = None
    return body

WebhookEndpointCreateParams

WebhookEndpointCreateParams(**kwargs: Any)

Bases: BaseModel

Request body for POST /webhook_endpoints.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

WebhookEndpointUpdateParams

WebhookEndpointUpdateParams(**kwargs: Any)

Bases: BaseModel

Request body for PUT /webhook_endpoints/{id}.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

WebhookEventListParams

WebhookEventListParams(**kwargs: Any)

Bases: BaseModel

Query parameters for endpoint-specific webhook events.

Source code in dashscope/applications/agentstudio/types/models.py
53
54
55
56
57
58
59
def __init__(self, **kwargs: Any) -> None:
    self._raw: Dict[str, Any] = dict(kwargs)
    for name in self._fields:
        setattr(self, name, kwargs.get(name))
    self.extra: Dict[str, Any] = {
        k: v for k, v in kwargs.items() if k not in set(self._fields)
    }

Constants & enums

SessionStatus

Bases: StrEnum

Session run-status values (session_status).

Top-level Session.status ∈ {idle, running, terminated, rescheduled}; the session_status event data.session_status value set is the same plus deleted (a delete returns a tombstone, not a Session with status=deleted). idle also covers waiting for tool approval, signalled by stop_reason.type=requires_action.

IDLE class-attribute instance-attribute

IDLE = 'idle'

RUNNING class-attribute instance-attribute

RUNNING = 'running'

RESCHEDULED class-attribute instance-attribute

RESCHEDULED = 'rescheduled'

TERMINATED class-attribute instance-attribute

TERMINATED = 'terminated'

DELETED class-attribute instance-attribute

DELETED = 'deleted'

SSEEventType

Bases: StrEnum

Server-sent event types (the value of event.type in SSE payloads).

Client-sendable: MESSAGE, INTERRUPT, TOOL_APPROVAL_RESPONSE, FUNCTION_CALL_OUTPUT, TOOL_CALL_OUTPUT, DEFINE_OUTCOME. Server-emitted: all types (23 total).

MESSAGE class-attribute instance-attribute

MESSAGE = 'message'

INTERRUPT class-attribute instance-attribute

INTERRUPT = 'interrupt'

TOOL_APPROVAL_RESPONSE class-attribute instance-attribute

TOOL_APPROVAL_RESPONSE = 'tool_approval_response'

FUNCTION_CALL_OUTPUT class-attribute instance-attribute

FUNCTION_CALL_OUTPUT = 'function_call_output'

TOOL_CALL_OUTPUT class-attribute instance-attribute

TOOL_CALL_OUTPUT = 'tool_call_output'

DEFINE_OUTCOME class-attribute instance-attribute

DEFINE_OUTCOME = 'define_outcome'

FUNCTION_CALL class-attribute instance-attribute

FUNCTION_CALL = 'function_call'

TOOL_CALL class-attribute instance-attribute

TOOL_CALL = 'tool_call'

REASONING class-attribute instance-attribute

REASONING = 'reasoning'

MCP_CALL class-attribute instance-attribute

MCP_CALL = 'mcp_call'

MCP_CALL_OUTPUT class-attribute instance-attribute

MCP_CALL_OUTPUT = 'mcp_call_output'

TOOL_APPROVAL_REQUEST class-attribute instance-attribute

TOOL_APPROVAL_REQUEST = 'tool_approval_request'

THREAD_MESSAGE_SENT class-attribute instance-attribute

THREAD_MESSAGE_SENT = 'thread_message_sent'

THREAD_MESSAGE_RECEIVED class-attribute instance-attribute

THREAD_MESSAGE_RECEIVED = 'thread_message_received'

THREAD_CONTEXT_COMPACTED class-attribute instance-attribute

THREAD_CONTEXT_COMPACTED = 'thread_context_compacted'

SESSION_STATUS class-attribute instance-attribute

SESSION_STATUS = 'session_status'

ERROR class-attribute instance-attribute

ERROR = 'error'

SESSION_UPDATED class-attribute instance-attribute

SESSION_UPDATED = 'session_updated'

THREAD_CREATED class-attribute instance-attribute

THREAD_CREATED = 'thread_created'

THREAD_STATUS class-attribute instance-attribute

THREAD_STATUS = 'thread_status'

MODEL_REQUEST_START class-attribute instance-attribute

MODEL_REQUEST_START = 'model_request_start'

MODEL_REQUEST_END class-attribute instance-attribute

MODEL_REQUEST_END = 'model_request_end'

OUTCOME_EVALUATION class-attribute instance-attribute

OUTCOME_EVALUATION = 'outcome_evaluation'

StopReasonType

Bases: StrEnum

stop_reason.type carried by session_status idle events.

Only idle carries stop_reason; a running Session's stop_reason is null.

END_TURN class-attribute instance-attribute

END_TURN = 'end_turn'

REQUIRES_ACTION class-attribute instance-attribute

REQUIRES_ACTION = 'requires_action'

RETRIES_EXHAUSTED class-attribute instance-attribute

RETRIES_EXHAUSTED = 'retries_exhausted'

PermissionPolicyType

Bases: StrEnum

Tool approval policy (permission_policy.type).

always_allow (default) executes the tool without asking; always_ask produces a tool_approval_request per call. Subagent/subthread always_ask degrades to always_allow.

ALWAYS_ALLOW class-attribute instance-attribute

ALWAYS_ALLOW = 'always_allow'

ALWAYS_ASK class-attribute instance-attribute

ALWAYS_ASK = 'always_ask'

WebhookStatus

Bases: StrEnum

Webhook endpoint activation status.

ACTIVE class-attribute instance-attribute

ACTIVE = 'ACTIVE'

DISABLED class-attribute instance-attribute

DISABLED = 'DISABLED'

WebhookEventType

Bases: StrEnum

Event types accepted by webhook endpoint subscriptions.

SESSION_CREATED class-attribute instance-attribute

SESSION_CREATED = 'session.created'

SESSION_UPDATED class-attribute instance-attribute

SESSION_UPDATED = 'session.updated'

SESSION_ARCHIVED class-attribute instance-attribute

SESSION_ARCHIVED = 'session.archived'

SESSION_DELETED class-attribute instance-attribute

SESSION_DELETED = 'session.deleted'

SESSION_STATUS_RUN_STARTED class-attribute instance-attribute

SESSION_STATUS_RUN_STARTED = 'session.status_run_started'

SESSION_STATUS_IDLED class-attribute instance-attribute

SESSION_STATUS_IDLED = 'session.status_idled'

SESSION_STATUS_TERMINATED class-attribute instance-attribute

SESSION_STATUS_TERMINATED = 'session.status_terminated'

SESSION_THREAD_CREATED class-attribute instance-attribute

SESSION_THREAD_CREATED = 'session.thread_created'

SESSION_THREAD_RUN_STARTED class-attribute instance-attribute

SESSION_THREAD_RUN_STARTED = 'session.thread_run_started'

SESSION_THREAD_IDLED class-attribute instance-attribute

SESSION_THREAD_IDLED = 'session.thread_idled'

SESSION_THREAD_TERMINATED class-attribute instance-attribute

SESSION_THREAD_TERMINATED = 'session.thread_terminated'

AGENT_CREATED class-attribute instance-attribute

AGENT_CREATED = 'agent.created'

AGENT_UPDATED class-attribute instance-attribute

AGENT_UPDATED = 'agent.updated'

AGENT_ARCHIVED class-attribute instance-attribute

AGENT_ARCHIVED = 'agent.archived'

DEPLOYMENT_CREATED class-attribute instance-attribute

DEPLOYMENT_CREATED = 'deployment.created'

DEPLOYMENT_UPDATED class-attribute instance-attribute

DEPLOYMENT_UPDATED = 'deployment.updated'

DEPLOYMENT_ARCHIVED class-attribute instance-attribute

DEPLOYMENT_ARCHIVED = 'deployment.archived'

DEPLOYMENT_PAUSED class-attribute instance-attribute

DEPLOYMENT_PAUSED = 'deployment.paused'

DEPLOYMENT_UNPAUSED class-attribute instance-attribute

DEPLOYMENT_UNPAUSED = 'deployment.unpaused'

DEPLOYMENT_RUN_STARTED class-attribute instance-attribute

DEPLOYMENT_RUN_STARTED = 'deployment_run.started'

DEPLOYMENT_RUN_FAILED class-attribute instance-attribute

DEPLOYMENT_RUN_FAILED = 'deployment_run.failed'

DEPLOYMENT_RUN_SUCCEEDED class-attribute instance-attribute

DEPLOYMENT_RUN_SUCCEEDED = 'deployment_run.succeeded'

ENVIRONMENT_CREATED class-attribute instance-attribute

ENVIRONMENT_CREATED = 'environment.created'

ENVIRONMENT_UPDATED class-attribute instance-attribute

ENVIRONMENT_UPDATED = 'environment.updated'

ENVIRONMENT_ARCHIVED class-attribute instance-attribute

ENVIRONMENT_ARCHIVED = 'environment.archived'

ENVIRONMENT_DELETED class-attribute instance-attribute

ENVIRONMENT_DELETED = 'environment.deleted'

VAULT_CREATED class-attribute instance-attribute

VAULT_CREATED = 'vault.created'

VAULT_ARCHIVED class-attribute instance-attribute

VAULT_ARCHIVED = 'vault.archived'

VAULT_DELETED class-attribute instance-attribute

VAULT_DELETED = 'vault.deleted'

VAULT_CREDENTIAL_CREATED class-attribute instance-attribute

VAULT_CREDENTIAL_CREATED = 'vault_credential.created'

VAULT_CREDENTIAL_ARCHIVED class-attribute instance-attribute

VAULT_CREDENTIAL_ARCHIVED = 'vault_credential.archived'

VAULT_CREDENTIAL_DELETED class-attribute instance-attribute

VAULT_CREDENTIAL_DELETED = 'vault_credential.deleted'

WebhookDeliveryStatus

Bases: StrEnum

Webhook delivery status.

PENDING class-attribute instance-attribute

PENDING = 'PENDING'

DELIVERING class-attribute instance-attribute

DELIVERING = 'DELIVERING'

WAITING_RETRY class-attribute instance-attribute

WAITING_RETRY = 'WAITING_RETRY'

SUCCEEDED class-attribute instance-attribute

SUCCEEDED = 'SUCCEEDED'

FAILED class-attribute instance-attribute

FAILED = 'FAILED'

CANCELED class-attribute instance-attribute

CANCELED = 'CANCELED'

WebhookDisabledReason

Bases: StrEnum

Reason why a webhook endpoint was disabled.

MANUAL class-attribute instance-attribute

MANUAL = 'MANUAL'

CONSECUTIVE_DELIVERY_FAILURES class-attribute instance-attribute

CONSECUTIVE_DELIVERY_FAILURES = (
    "CONSECUTIVE_DELIVERY_FAILURES"
)

REDIRECT_RESPONSE class-attribute instance-attribute

REDIRECT_RESPONSE = 'REDIRECT_RESPONSE'

SSRF_VALIDATION_FAILED class-attribute instance-attribute

SSRF_VALIDATION_FAILED = 'SSRF_VALIDATION_FAILED'

TLS_VALIDATION_FAILED class-attribute instance-attribute

TLS_VALIDATION_FAILED = 'TLS_VALIDATION_FAILED'

Pagination, transport & exceptions

CursorPage

CursorPage(
    *,
    data: List[T],
    next_page: Optional[str],
    request_id: Optional[str],
    fetch_next: Optional[
        Callable[[str], "CursorPage[T]"]
    ] = None,
    extra: Optional[Dict[str, Any]] = None
)

Bases: Generic[T]

Synchronous page over an opaque page cursor.

extra preserves any additional top-level fields the list envelope carried beyond data / next_page (forward compatibility when the server adds fields); extra is per page and does not participate in auto-pagination.

Source code in dashscope/applications/agentstudio/pagination.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(
    self,
    *,
    data: List[T],
    next_page: Optional[str],
    request_id: Optional[str],
    fetch_next: Optional[Callable[[str], "CursorPage[T]"]] = None,
    extra: Optional[Dict[str, Any]] = None,
) -> None:
    self.data = data
    self.next_page = next_page
    self.request_id = request_id
    self._fetch_next = fetch_next
    self.extra: Dict[str, Any] = dict(extra or {})

data instance-attribute

data = data

next_page instance-attribute

next_page = next_page

request_id instance-attribute

request_id = request_id

extra instance-attribute

extra: Dict[str, Any] = dict(extra or {})

prefixes property

prefixes: List[str]

Directory prefixes of a tree-style listing (memory only).

has_next

has_next() -> bool
Source code in dashscope/applications/agentstudio/pagination.py
51
52
def has_next(self) -> bool:
    return bool(self.next_page) and self._fetch_next is not None

get_next

get_next() -> Optional['CursorPage[T]']
Source code in dashscope/applications/agentstudio/pagination.py
54
55
56
57
58
def get_next(self) -> Optional["CursorPage[T]"]:
    if not self.has_next():
        return None
    assert self._fetch_next is not None and self.next_page is not None
    return self._fetch_next(self.next_page)

AsyncCursorPage

AsyncCursorPage(
    *,
    data: List[T],
    next_page: Optional[str],
    request_id: Optional[str],
    fetch_next: Optional[
        Callable[[str], "AsyncCursorPage[T]"]
    ] = None,
    extra: Optional[Dict[str, Any]] = None
)

Bases: Generic[T]

Asynchronous page over an opaque page cursor.

See :class:CursorPage for the extra forward-compatibility bag.

Source code in dashscope/applications/agentstudio/pagination.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(
    self,
    *,
    data: List[T],
    next_page: Optional[str],
    request_id: Optional[str],
    fetch_next: Optional[Callable[[str], "AsyncCursorPage[T]"]] = None,
    extra: Optional[Dict[str, Any]] = None,
) -> None:
    self.data = data
    self.next_page = next_page
    self.request_id = request_id
    self._fetch_next = fetch_next
    self.extra: Dict[str, Any] = dict(extra or {})

data instance-attribute

data = data

next_page instance-attribute

next_page = next_page

request_id instance-attribute

request_id = request_id

extra instance-attribute

extra: Dict[str, Any] = dict(extra or {})

prefixes property

prefixes: List[str]

Directory prefixes of a tree-style listing (memory only).

has_next

has_next() -> bool
Source code in dashscope/applications/agentstudio/pagination.py
107
108
def has_next(self) -> bool:
    return bool(self.next_page) and self._fetch_next is not None

get_next async

get_next() -> Optional['AsyncCursorPage[T]']
Source code in dashscope/applications/agentstudio/pagination.py
110
111
112
113
114
115
116
117
async def get_next(self) -> Optional["AsyncCursorPage[T]"]:
    if not self.has_next():
        return None
    assert self._fetch_next is not None and self.next_page is not None
    result = self._fetch_next(self.next_page)
    if hasattr(result, "__await__"):
        result = await result  # type: ignore[assignment]
    return result  # type: ignore[return-value]

RequestOptions dataclass

RequestOptions(
    method: str,
    path: str,
    json: Optional[Dict[str, Any]] = None,
    params: Optional[Dict[str, Any]] = None,
    data: Optional[Union[bytes, IO]] = None,
    files: Optional[Dict[str, Any]] = None,
    headers: Optional[Dict[str, str]] = None,
    timeout: Optional[float] = None,
    max_retries: Optional[int] = None,
    stream: bool = False,
)

method instance-attribute

method: str

path instance-attribute

path: str

json class-attribute instance-attribute

json: Optional[Dict[str, Any]] = None

params class-attribute instance-attribute

params: Optional[Dict[str, Any]] = None

data class-attribute instance-attribute

data: Optional[Union[bytes, IO]] = None

files class-attribute instance-attribute

files: Optional[Dict[str, Any]] = None

headers class-attribute instance-attribute

headers: Optional[Dict[str, str]] = None

timeout class-attribute instance-attribute

timeout: Optional[float] = None

max_retries class-attribute instance-attribute

max_retries: Optional[int] = None

stream class-attribute instance-attribute

stream: bool = False

APIResponse dataclass

APIResponse(
    data: Dict[str, Any],
    request_id: Optional[str] = None,
    status_code: int = 200,
)

data instance-attribute

data: Dict[str, Any]

request_id class-attribute instance-attribute

request_id: Optional[str] = None

status_code class-attribute instance-attribute

status_code: int = 200

from_http_response classmethod

from_http_response(response, exceptions_module)
Source code in dashscope/applications/agentstudio/transport.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@classmethod
def from_http_response(cls, response, exceptions_module):
    content_type = response.headers.get("Content-Type", "")
    if response.status_code < 400 and not content_type.startswith(
        "application/json",
    ):
        payload = {
            "_binary": response.content,
            "_content_type": content_type,
        }
    else:
        try:
            payload = response.json()
        except ValueError:
            payload = {"raw": response.text}
    if response.status_code >= 400 or is_error_payload(payload):
        raise exceptions_module.from_response(
            status_code=response.status_code,
            body=payload,
            headers=response.headers,
        )
    data, request_id = unwrap(payload)
    return cls(
        data,
        request_id or response.headers.get("x-request-id"),
        response.status_code,
    )

AgentStudioError module-attribute

AgentStudioError = DashScopeError

APIConnectionError

APIConnectionError(
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any
)

Bases: _CatalogSdkError

Network-level failure (connection refused, DNS, TLS...).

Backed by the catalog's sdk.ConnectionError entry: code / solution / allow_retry default from it, so every raise site is catalog-identical without repeating the wiring. Pass detail instead of message to use the entry's message template.

Source code in dashscope/errors.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any,
) -> None:
    entry = _SDK_ERRORS[self._SDK_ERROR_NAME]
    if message is None:
        message = entry.format_message({"detail": detail or ""})
    kwargs.setdefault("code", entry.name)
    kwargs.setdefault("solution", entry.solution)
    kwargs.setdefault("allow_retry", entry.allow_retry)
    super().__init__(message, **kwargs)

APITimeoutError

APITimeoutError(
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any
)

Bases: APIConnectionError

Request timed out; backed by the catalog's sdk.Timeout entry.

Source code in dashscope/errors.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any,
) -> None:
    entry = _SDK_ERRORS[self._SDK_ERROR_NAME]
    if message is None:
        message = entry.format_message({"detail": detail or ""})
    kwargs.setdefault("code", entry.name)
    kwargs.setdefault("solution", entry.solution)
    kwargs.setdefault("allow_retry", entry.allow_retry)
    super().__init__(message, **kwargs)

APIStatusError

APIStatusError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: DashScopeError

A failure the gateway declared, on either layer of the model.

Both a non-2xx HTTP status and an HTTP 200 whose body carries a business code land here; the instance's status_code says which one it was.

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code: Optional[int] = None

AuthenticationError

AuthenticationError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: APIStatusError

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code = _CATALOG_STATUS['AuthenticationError']

PermissionDeniedError

PermissionDeniedError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: APIStatusError

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code = _CATALOG_STATUS['PermissionDeniedError']

NotFoundError

NotFoundError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: APIStatusError

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code = _CATALOG_STATUS['NotFoundError']

ConflictError module-attribute

ConflictError = APIStatusError

InvalidRequestError module-attribute

InvalidRequestError = BadRequestError

RateLimitError

RateLimitError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: APIStatusError

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code = _CATALOG_STATUS['RateLimitError']

OverloadedError module-attribute

OverloadedError = ServiceUnavailableError

InternalServerError

InternalServerError(
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None
)

Bases: APIStatusError

Source code in dashscope/errors.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    message: str,
    *,
    code: Optional[str] = None,
    status_code: Optional[int] = None,
    request_id: Optional[str] = None,
    body: Any = None,
    headers: Optional[Mapping[str, str]] = None,
) -> None:
    super().__init__(message)
    self.message = message
    self.code = code
    self.status_code = status_code
    self.request_id = request_id
    self.body = body
    self.headers = headers or {}

status_code class-attribute instance-attribute

status_code = _CATALOG_STATUS['InternalServerError']

StreamError

StreamError(
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any
)

Bases: _CatalogSdkError

The SSE stream encountered a fatal protocol error.

Backed by the catalog's sdk.agentstudio.StreamError entry: code / solution / allow_retry default from it.

Source code in dashscope/errors.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any,
) -> None:
    entry = _SDK_ERRORS[self._SDK_ERROR_NAME]
    if message is None:
        message = entry.format_message({"detail": detail or ""})
    kwargs.setdefault("code", entry.name)
    kwargs.setdefault("solution", entry.solution)
    kwargs.setdefault("allow_retry", entry.allow_retry)
    super().__init__(message, **kwargs)

StreamClosedError

StreamClosedError(
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any
)

Bases: StreamError

Attempted I/O on an already-closed stream.

Backed by the catalog's sdk.agentstudio.StreamClosedError entry.

Source code in dashscope/errors.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    message: Optional[str] = None,
    *,
    detail: Optional[str] = None,
    **kwargs: Any,
) -> None:
    entry = _SDK_ERRORS[self._SDK_ERROR_NAME]
    if message is None:
        message = entry.format_message({"detail": detail or ""})
    kwargs.setdefault("code", entry.name)
    kwargs.setdefault("solution", entry.solution)
    kwargs.setdefault("allow_retry", entry.allow_retry)
    super().__init__(message, **kwargs)