Skip to content

Commit 17c53f1

Browse files
coolsky99一里
andauthored
feat(agentstudio): add managed agent deployment APIs (#253)
* feat(agentstudio): add deployment APIs * fix(agentstudio): serialize empty deployment metadata * fix(http): parse nested error envelopes * feat: restrict deployment metadata to string values --------- Co-authored-by: 一里 <liangshuang.ls@alibaba-inc.com>
1 parent 680128d commit 17c53f1

25 files changed

Lines changed: 1231 additions & 2 deletions
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import com.alibaba.dashscope.agentstudio.AgentStudioClient;
2+
import com.alibaba.dashscope.agentstudio.message.ClientEvents;
3+
import com.alibaba.dashscope.agentstudio.model.Deployment;
4+
import com.alibaba.dashscope.agentstudio.model.DeploymentRun;
5+
import com.alibaba.dashscope.agentstudio.param.DeploymentAgentParam;
6+
import com.alibaba.dashscope.agentstudio.param.DeploymentCreateParam;
7+
import com.alibaba.dashscope.agentstudio.param.DeploymentRunListParam;
8+
import com.alibaba.dashscope.agentstudio.param.DeploymentScheduleParam;
9+
import java.util.Collections;
10+
11+
/**
12+
* Managed Agent deployment example.
13+
*
14+
* <p>Set DASHSCOPE_API_KEY and DASHSCOPE_WORKSPACE before running.
15+
*/
16+
public class AgentStudioDeployments {
17+
18+
public static void main(String[] args) {
19+
try (AgentStudioClient client = new AgentStudioClient()) {
20+
Deployment deployment =
21+
client
22+
.deployments()
23+
.create(
24+
DeploymentCreateParam.builder()
25+
.name("daily-summary")
26+
.description("Generate a daily summary")
27+
.agent(DeploymentAgentParam.builder().id("agent_xxx").build())
28+
.schedule(
29+
DeploymentScheduleParam.builder()
30+
.type(DeploymentScheduleParam.TYPE_CRON)
31+
.expression("0 9 * * 1-5")
32+
.timezone("Asia/Shanghai")
33+
.build())
34+
.initialEvents(
35+
Collections.singletonList(
36+
ClientEvents.userMessage("Summarize yesterday's orders")))
37+
.metadata(Collections.singletonMap("biz", "summary"))
38+
.build());
39+
System.out.printf("deployment: %s %s%n", deployment.getId(), deployment.getStatus());
40+
41+
DeploymentRun run = client.deployments().run(deployment.getId());
42+
System.out.printf("run: %s %s%n", run.getId(), run.getStatus());
43+
44+
for (DeploymentRun item :
45+
client
46+
.deployments()
47+
.listRuns(deployment.getId(), DeploymentRunListParam.builder().limit(20).build())) {
48+
System.out.printf("%s %s %s%n", item.getId(), item.getTriggerSource(), item.getStatus());
49+
}
50+
}
51+
}
52+
}

src/main/java/com/alibaba/dashscope/agentstudio/AgentStudioClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package com.alibaba.dashscope.agentstudio;
33

44
import com.alibaba.dashscope.agentstudio.resource.Agents;
5+
import com.alibaba.dashscope.agentstudio.resource.DeploymentRuns;
6+
import com.alibaba.dashscope.agentstudio.resource.Deployments;
57
import com.alibaba.dashscope.agentstudio.resource.Environments;
68
import com.alibaba.dashscope.agentstudio.resource.Files;
79
import com.alibaba.dashscope.agentstudio.resource.Sessions;
@@ -14,6 +16,8 @@
1416

1517
public class AgentStudioClient implements Closeable {
1618
private final Agents agents;
19+
private final Deployments deployments;
20+
private final DeploymentRuns deploymentRuns;
1721
private final Sessions sessions;
1822
private final Environments environments;
1923
private final Skills skills;
@@ -41,6 +45,8 @@ public AgentStudioClient(
4145
ConnectionOptions connectionOptions) {
4246
this.baseUrl = resolveBaseUrl(baseUrl, workspace, region);
4347
this.agents = new Agents(this.baseUrl, connectionOptions, apiKey);
48+
this.deployments = new Deployments(this.baseUrl, connectionOptions, apiKey);
49+
this.deploymentRuns = new DeploymentRuns(this.baseUrl, connectionOptions, apiKey);
4450
this.sessions = new Sessions(this.baseUrl, connectionOptions, apiKey);
4551
this.environments = new Environments(this.baseUrl, connectionOptions, apiKey);
4652
this.files = new Files(this.baseUrl, connectionOptions, apiKey);
@@ -93,6 +99,14 @@ public Agents agents() {
9399
return agents;
94100
}
95101

102+
public Deployments deployments() {
103+
return deployments;
104+
}
105+
106+
public DeploymentRuns deploymentRuns() {
107+
return deploymentRuns;
108+
}
109+
96110
public Sessions sessions() {
97111
return sessions;
98112
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.alibaba.dashscope.agentstudio.message.Message;
5+
import com.alibaba.dashscope.common.FlattenResultBase;
6+
import com.google.gson.annotations.SerializedName;
7+
import java.util.List;
8+
import java.util.Map;
9+
import lombok.Data;
10+
import lombok.EqualsAndHashCode;
11+
12+
@Data
13+
@EqualsAndHashCode(callSuper = true)
14+
public class Deployment extends FlattenResultBase {
15+
@SerializedName("id")
16+
private String id;
17+
18+
@SerializedName("type")
19+
private String type;
20+
21+
@SerializedName("name")
22+
private String name;
23+
24+
@SerializedName("description")
25+
private String description;
26+
27+
@SerializedName("agent")
28+
private Agent agent;
29+
30+
@SerializedName("environment_id")
31+
private String environmentId;
32+
33+
@SerializedName("schedule")
34+
private DeploymentSchedule schedule;
35+
36+
@SerializedName("initial_events")
37+
private List<Message> initialEvents;
38+
39+
@SerializedName("resources")
40+
private List<DeploymentResource> resources;
41+
42+
@SerializedName("vault_ids")
43+
private List<String> vaultIds;
44+
45+
@SerializedName("metadata")
46+
private Map<String, String> metadata;
47+
48+
@SerializedName("status")
49+
private String status;
50+
51+
@SerializedName("paused_reason")
52+
private DeploymentPausedReason pausedReason;
53+
54+
@SerializedName("archived_at")
55+
private String archivedAt;
56+
57+
@SerializedName("created_at")
58+
private String createdAt;
59+
60+
@SerializedName("updated_at")
61+
private String updatedAt;
62+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
7+
@Data
8+
public class DeploymentAgentReference {
9+
@SerializedName("id")
10+
private String id;
11+
12+
@SerializedName("version")
13+
private Integer version;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
7+
@Data
8+
public class DeploymentError {
9+
@SerializedName("code")
10+
private String code;
11+
12+
@SerializedName("message")
13+
private String message;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
7+
@Data
8+
public class DeploymentPausedReason {
9+
@SerializedName("type")
10+
private String type;
11+
12+
@SerializedName("error")
13+
private DeploymentError error;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
7+
@Data
8+
public class DeploymentResource {
9+
@SerializedName("type")
10+
private String type;
11+
12+
@SerializedName("file_id")
13+
private String fileId;
14+
15+
@SerializedName("mount_path")
16+
private String mountPath;
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.alibaba.dashscope.common.FlattenResultBase;
5+
import com.google.gson.annotations.SerializedName;
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
9+
@Data
10+
@EqualsAndHashCode(callSuper = true)
11+
public class DeploymentRun extends FlattenResultBase {
12+
@SerializedName("id")
13+
private String id;
14+
15+
@SerializedName("type")
16+
private String type;
17+
18+
@SerializedName("deployment_id")
19+
private String deploymentId;
20+
21+
@SerializedName("agent")
22+
private DeploymentAgentReference agent;
23+
24+
@SerializedName("session_id")
25+
private String sessionId;
26+
27+
@SerializedName("trigger_source")
28+
private String triggerSource;
29+
30+
@SerializedName("status")
31+
private String status;
32+
33+
@SerializedName("error")
34+
private DeploymentError error;
35+
36+
@SerializedName("started_at")
37+
private String startedAt;
38+
39+
@SerializedName("finished_at")
40+
private String finishedAt;
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.model;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
7+
@Data
8+
public class DeploymentSchedule {
9+
@SerializedName("type")
10+
private String type;
11+
12+
@SerializedName("expression")
13+
private String expression;
14+
15+
@SerializedName("timezone")
16+
private String timezone;
17+
18+
@SerializedName("last_run_at")
19+
private String lastRunAt;
20+
21+
@SerializedName("next_run_at")
22+
private String nextRunAt;
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Alibaba, Inc. and its affiliates.
2+
package com.alibaba.dashscope.agentstudio.param;
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NonNull;
8+
9+
@Data
10+
@Builder
11+
public class DeploymentAgentParam {
12+
@NonNull
13+
@SerializedName("id")
14+
private String id;
15+
16+
@SerializedName("version")
17+
private Integer version;
18+
}

0 commit comments

Comments
 (0)