AgentStudio¶
AgentStudio is the managed-agent platform: environments, agents, sessions, events, files, memory stores, vaults, skills, webhooks, and scheduled deployments. It is shared by the 2.x and 3.0 SDK generations and is not deprecated.
client.agentStudio() lazily mounts a single shared AgentStudioClient — workspace and region
forward from the client config, but the 3.0 baseUrl does not apply; override its endpoint
with DASHSCOPE_AGENTSTUDIO_URL. The subarea allocates its own HTTP clients; errors use the 3.0
unchecked exception family.
Resources¶
Accessor (studio.*) |
Manages |
|---|---|
environments() |
Sandboxed execution environments |
agents() |
Agent definitions (system prompt, model, tools) |
sessions() |
Conversation sessions; sessions().events() sends/streams events |
deployments() / deploymentRuns() |
Scheduled agent deployments and their runs |
memoryStores() |
Persistent memory: memories(), memoryVersions() |
files() |
Session/agent files |
vaults() |
Credential vaults |
skills() |
Reusable skills |
webhookEndpoints() |
Webhook subscriptions |
security() / usage() |
Security settings and usage reports |
End-to-end quickstart¶
Create environment → create agent → create session → send message → stream events → archive. Adapted from AgentStudioQuickStart:
import com.alibaba.dashscope.applications.agentstudio.AgentStudioClient;
import com.alibaba.dashscope.applications.agentstudio.message.ClientEvents;
import com.alibaba.dashscope.applications.agentstudio.model.Agent;
import com.alibaba.dashscope.applications.agentstudio.model.Environment;
import com.alibaba.dashscope.applications.agentstudio.model.Session;
import com.alibaba.dashscope.applications.agentstudio.param.AgentCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.EnvironmentCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.SessionCreateParam;
import com.alibaba.dashscope.applications.agentstudio.resource.AgentStudioEventStream;
try (DashScopeClient client = DashScopeClient.builder()
.workspace("trial") // DASHSCOPE_WORKSPACE selects the AgentStudio workspace
.build()) {
AgentStudioClient studio = client.agentStudio();
Environment env = studio.environments().create(
EnvironmentCreateParam.builder().name("quickstart-env").config(config).build());
Agent agent = studio.agents().create(
AgentCreateParam.builder()
.name("quickstart-agent")
.systemPrompt("You are a friendly demo agent. Reply briefly.")
.model("qwen3.8-max")
.tools(tools)
.build());
Session session = studio.sessions().create(
SessionCreateParam.builder()
.agent(agent.getId()).environmentId(env.getId()).title("quickstart").build());
studio.sessions().events().send(session.getId(),
Collections.singletonList(ClientEvents.userMessage("Tell me a fun fact about Hangzhou.")));
try (AgentStudioEventStream stream = studio.sessions().events().stream(session.getId())) {
for (String text : stream.textStream()) {
System.out.print(text);
}
}
}
Full runnable example: AgentStudioQuickStart.java (auto-synced)
// Copyright (c) Alibaba, Inc. and its affiliates.
package com.alibaba.dashscope.examples.recipes.agentstudio;
import com.alibaba.dashscope.DashScopeClient;
import com.alibaba.dashscope.applications.agentstudio.AgentStudioClient;
import com.alibaba.dashscope.applications.agentstudio.message.ClientEvents;
import com.alibaba.dashscope.applications.agentstudio.model.Agent;
import com.alibaba.dashscope.applications.agentstudio.model.Configs;
import com.alibaba.dashscope.applications.agentstudio.model.Environment;
import com.alibaba.dashscope.applications.agentstudio.model.Session;
import com.alibaba.dashscope.applications.agentstudio.param.AgentCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.EnvironmentCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.SessionCreateParam;
import com.alibaba.dashscope.applications.agentstudio.resource.AgentStudioEventStream;
import com.alibaba.dashscope.examples.ExampleSupport;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Agent recipe: AgentStudio end-to-end quickstart. Flow: create environment -> create agent ->
* create session -> send message -> stream events -> archive session.
*
* <p>AgentStudio is shared by the 2.x and 3.0 SDK generations: {@code client.agentStudio()} lazily
* mounts a single shared {@link AgentStudioClient} (workspace and region forward from the client
* config; the 3.0 {@code baseUrl} does not apply to it), so one {@code DashScopeClient} covers both
* the 3.0 resources and AgentStudio.
*
* <p>The Python example's opt-in {@code memory_stores_demo} flow (create store -> write memory ->
* list -> update -> list versions -> delete) is already covered by the Java sample {@code
* legacy_2x/AgentStudioMemoryStores.java}, so it is not duplicated here.
*
* <p>Translation of the Python blueprint example 03_agent_recipes/agentstudio.py.
*
* <p>Requires DASHSCOPE_API_KEY; DASHSCOPE_WORKSPACE selects the AgentStudio workspace (defaults to
* trial).
*/
public final class AgentStudioQuickStart {
private AgentStudioQuickStart() {}
private static String envOr(String name, String fallback) {
String value = System.getenv(name);
return value == null || value.isEmpty() ? fallback : value;
}
/** The builtin_toolkit entry from the Python example: everything off except bash. */
private static Configs.ToolConfig bashOnlyToolkit() {
Configs.ToolConfig toolkit = new Configs.ToolConfig();
toolkit.setType("builtin_toolkit");
Configs.ToolConfig.DefaultConfig defaultConfig = new Configs.ToolConfig.DefaultConfig();
defaultConfig.setEnabled(false);
toolkit.setDefaultConfig(defaultConfig);
Configs.ToolConfig.PerToolConfig bash = new Configs.ToolConfig.PerToolConfig();
bash.setName("bash");
bash.setEnabled(true);
toolkit.setConfigs(Collections.singletonList(bash));
return toolkit;
}
/** Run the full quickstart flow. */
public static void main(String[] args) {
try (DashScopeClient client =
DashScopeClient.builder()
.apiKey(ExampleSupport.requireApiKey())
.workspace(envOr("DASHSCOPE_WORKSPACE", "trial"))
.build()) {
AgentStudioClient studio = client.agentStudio();
System.out.println("==> creating environment");
Map<String, Object> config = new HashMap<>();
config.put("type", "cloud");
config.put("networking", Collections.singletonMap("type", "unrestricted"));
Environment env =
studio
.environments()
.create(
EnvironmentCreateParam.builder().name("quickstart-env").config(config).build());
System.out.println(" environment_id=" + env.getId());
System.out.println("==> creating agent");
Agent agent =
studio
.agents()
.create(
AgentCreateParam.builder()
.name("quickstart-agent")
.systemPrompt("You are a friendly demo agent. Reply briefly.")
.model("qwen3.8-max")
.tools(Collections.singletonList(bashOnlyToolkit()))
.build());
System.out.println(" agent_id=" + agent.getId());
System.out.println("==> creating session");
Session session =
studio
.sessions()
.create(
SessionCreateParam.builder()
.agent(agent.getId())
.environmentId(env.getId())
.title("quickstart")
.build());
System.out.println(" session_id=" + session.getId());
System.out.println("==> sending user message");
studio
.sessions()
.events()
.send(
session.getId(),
Collections.singletonList(
ClientEvents.userMessage("Hello! Tell me one fun fact about Hangzhou.")));
System.out.println("==> streaming events");
try (AgentStudioEventStream stream = studio.sessions().events().stream(session.getId())) {
for (String text : stream.textStream()) {
System.out.print(text);
System.out.flush();
}
System.out.println();
}
System.out.println("==> archiving session");
studio.sessions().archive(session.getId());
System.out.println("done.");
}
}
}
SSE stream semantics¶
AgentStudioEventStream is Iterable<Message> + Closeable with deliberate constraints:
- Single-pass: the queue drains into one reader; a second
iterator()throwsIllegalStateException. Open another stream to read events again. textStream()yields terminal full text;textDeltas()yields incremental deltas only when the stream was opened withevent_deltas—events().stream(sessionId, Arrays.asList("message"))(also accepts"reasoning").- An idle gap longer than the stream timeout throws
ApiTimeoutException(distinct from real end-of-stream).
Memory stores¶
Persistent, versioned memory the agent can read. Adapted from AgentStudioMemoryStores:
MemoryStore store = studio.memoryStores().create(
MemoryStoreCreateParam.builder()
.name("demo-preferences")
.description("Per-user preferences and project context.") // read by the agent
.build());
Memory memory = studio.memoryStores().memories().create(store.getId(),
MemoryCreateParam.builder()
.path("/formatting_standards.md")
.content("All reports use GAAP formatting.")
.build());
// view=full returns content (default basic is metadata only); iteration auto-paginates.
CursorPage<Memory> page = studio.memoryStores().memories()
.list(store.getId(), MemoryListParam.builder().view("full").build());
// Optimistic-lock update: pass the contentSha256 you read.
Memory updated = studio.memoryStores().memories().update(store.getId(), memory.getId(),
MemoryUpdateParam.builder()
.content("All reports use GAAP formatting. ISO-8601 dates.")
.contentSha256(memory.getContentSha256())
.build());
// Every mutation produces a version snapshot; versions can be redacted.
studio.memoryStores().memoryVersions().list(store.getId(), MemoryVersionListParam.builder().build());
studio.memoryStores().delete(store.getId());
Full runnable example: AgentStudioMemoryStores.java (auto-synced)
// Copyright (c) Alibaba, Inc. and its affiliates.
package com.alibaba.dashscope.examples.recipes.agentstudio;
import com.alibaba.dashscope.DashScopeClient;
import com.alibaba.dashscope.applications.agentstudio.AgentStudioClient;
import com.alibaba.dashscope.applications.agentstudio.model.AgentStudioDeletionStatus;
import com.alibaba.dashscope.applications.agentstudio.model.Memory;
import com.alibaba.dashscope.applications.agentstudio.model.MemoryStore;
import com.alibaba.dashscope.applications.agentstudio.model.MemoryVersion;
import com.alibaba.dashscope.applications.agentstudio.pagination.CursorPage;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryListParam;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryStoreCreateParam;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryStoreListParam;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryUpdateParam;
import com.alibaba.dashscope.applications.agentstudio.param.MemoryVersionListParam;
import com.alibaba.dashscope.examples.ExampleSupport;
/**
* Agent recipe: AgentStudio memory stores end-to-end. Flow: create store -> seed memory -> list
* with content (view=full, auto-pagination) -> update with optimistic lock -> list versions ->
* redact a version -> list stores -> delete store.
*
* <p>3.0 port of {@code legacy_2x/AgentStudioMemoryStores.java}: same flow under {@code
* com.alibaba.dashscope.applications.agentstudio}, mounted via {@code client.agentStudio()}, plus
* the {@code redact()} audit step. Unlike the frozen legacy copy, this file is a compiled example
* source and runs in the offline dry-run suite.
*
* <p>Requires DASHSCOPE_API_KEY; DASHSCOPE_WORKSPACE selects the AgentStudio workspace (defaults to
* trial).
*/
public final class AgentStudioMemoryStores {
private AgentStudioMemoryStores() {}
private static String envOr(String name, String fallback) {
String value = System.getenv(name);
return value == null || value.isEmpty() ? fallback : value;
}
/** Run the full memory-store flow. */
public static void main(String[] args) {
try (DashScopeClient client =
DashScopeClient.builder()
.apiKey(ExampleSupport.requireApiKey())
.workspace(envOr("DASHSCOPE_WORKSPACE", "trial"))
.build()) {
AgentStudioClient studio = client.agentStudio();
// 1. Create a store; description is read by the agent - write it for the model.
System.out.println("==> creating memory store");
MemoryStore store =
studio
.memoryStores()
.create(
MemoryStoreCreateParam.builder()
.name("demo-preferences")
.description("Per-user preferences and project context.")
.build());
System.out.println(" store_id=" + store.getId());
// 2. Seed reference material before any session runs.
System.out.println("==> seeding memory");
Memory memory =
studio
.memoryStores()
.memories()
.create(
store.getId(),
MemoryCreateParam.builder()
.path("/formatting_standards.md")
.content("All reports use GAAP formatting.")
.build());
System.out.printf(
" memory_id=%s path=%s size=%d%n",
memory.getId(), memory.getPath(), memory.getContentSizeBytes());
// 3. Read back with content (view=full; the default basic is metadata only). Print prefixes
// before iterating: the loop auto-paginates and prefixes are per page.
System.out.println("==> listing memories (view=full)");
CursorPage<Memory> page =
studio
.memoryStores()
.memories()
.list(store.getId(), MemoryListParam.builder().view("full").build());
System.out.println(" prefixes=" + page.getPrefixes());
for (Memory item : page) {
System.out.printf(" %s -> %s%n", item.getPath(), item.getContent());
}
// 4. Update with the optimistic lock (contentSha256 from step 2).
System.out.println("==> updating memory");
Memory updated =
studio
.memoryStores()
.memories()
.update(
store.getId(),
memory.getId(),
MemoryUpdateParam.builder()
.content("All reports use GAAP formatting. ISO-8601 dates.")
.contentSha256(memory.getContentSha256())
.build());
System.out.println(" updated_sha=" + updated.getContentSha256());
// 5. Audit history: every mutation produced a memver_ snapshot (newest first).
System.out.println("==> listing memory versions");
String firstVersionId = null;
for (MemoryVersion version :
studio
.memoryStores()
.memoryVersions()
.list(store.getId(), MemoryVersionListParam.builder().build())) {
System.out.printf(" version=%s operation=%s%n", version.getId(), version.getOperation());
if (firstVersionId == null) {
firstVersionId = version.getId();
}
}
// 6. Redact one snapshot: path/content/sha/size are cleared, the audit trail stays.
if (firstVersionId != null) {
System.out.println("==> redacting version " + firstVersionId);
MemoryVersion redacted =
studio.memoryStores().memoryVersions().redact(store.getId(), firstVersionId);
System.out.printf(
" redacted_at=%s content=%s%n", redacted.getRedactedAt(), redacted.getContent());
}
// 7. List stores and clean up.
System.out.println("==> listing stores");
for (MemoryStore item :
studio.memoryStores().list(MemoryStoreListParam.builder().limit(20).build())) {
System.out.printf(" store=%s name=%s%n", item.getId(), item.getName());
}
AgentStudioDeletionStatus deleted = studio.memoryStores().delete(store.getId());
System.out.println(" deleted=" + deleted.isDeleted());
System.out.println("done.");
}
}
}
More examples¶
- AgentStudioDeploymentsManage — scheduled deployments.
- Javadoc: applications.agentstudio.