Skip to content

Commit 368e17f

Browse files
committed
add deployer example
Change-Id: Ide55ac90a9ea87cdaa2c67703164b1b8c2da489c
1 parent a7d152e commit 368e17f

File tree

5 files changed

+292
-16
lines changed

5 files changed

+292
-16
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
pom.xml.next
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
.mvn/wrapper/maven-wrapper.jar
12+
13+
# IDE
14+
.idea/
15+
*.iml
16+
.vscode/
17+
.settings/
18+
.project
19+
.classpath
20+
21+
# Logs
22+
*.log
23+
logs/
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Environment
30+
.env
31+
.env.local
32+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2024-2025 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
20+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-parent</artifactId>
26+
<version>3.2.0</version>
27+
<relativePath/>
28+
</parent>
29+
30+
<groupId>io.agentscope</groupId>
31+
<artifactId>agentscope_deployer_example</artifactId>
32+
<version>1.0.0</version>
33+
<name>Example::Deployer Plugin</name>
34+
<description>Java backend for AgentScope Deployer Plugin</description>
35+
36+
<properties>
37+
<java.version>17</java.version>
38+
<maven.compiler.source>17</maven.compiler.source>
39+
<maven.compiler.target>17</maven.compiler.target>
40+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41+
</properties>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>io.agentscope</groupId>
46+
<artifactId>agentscope-runtime-agentscope</artifactId>
47+
<version>0.1.1</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>io.agentscope</groupId>
52+
<artifactId>agentscope-runtime-web</artifactId>
53+
<version>0.1.1</version>
54+
</dependency>
55+
56+
<!-- Logging -->
57+
<dependency>
58+
<groupId>org.slf4j</groupId>
59+
<artifactId>slf4j-api</artifactId>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>ch.qos.logback</groupId>
64+
<artifactId>logback-classic</artifactId>
65+
</dependency>
66+
67+
</dependencies>
68+
69+
<repositories>
70+
<repository>
71+
<id>spring-milestones</id>
72+
<name>Spring Milestones</name>
73+
<url>https://repo.spring.io/milestone</url>
74+
<snapshots>
75+
<enabled>false</enabled>
76+
</snapshots>
77+
</repository>
78+
<repository>
79+
<id>spring-snapshots</id>
80+
<name>Spring Snapshots</name>
81+
<url>https://repo.spring.io/snapshot</url>
82+
<releases>
83+
<enabled>false</enabled>
84+
</releases>
85+
</repository>
86+
</repositories>
87+
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-compiler-plugin</artifactId>
93+
<version>3.11.0</version>
94+
<configuration>
95+
<source>17</source>
96+
<target>17</target>
97+
</configuration>
98+
</plugin>
99+
100+
<plugin>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-maven-plugin</artifactId>
103+
<configuration>
104+
<mainClass>io.agentscope.AgentScopeDeployExample</mainClass>
105+
</configuration>
106+
</plugin>
107+
108+
<plugin>
109+
<groupId>io.agentscope</groupId>
110+
<artifactId>deployer-maven-plugin</artifactId>
111+
<version>1.0.0-SNAPSHOT</version>
112+
<configuration>
113+
<configFile>${project.basedir}/deployer.yml</configFile>
114+
</configuration>
115+
<executions>
116+
<execution>
117+
<id>deployer</id>
118+
<phase>package</phase>
119+
<goals>
120+
<goal>build</goal>
121+
</goals>
122+
</execution>
123+
</executions>
124+
</plugin>
125+
126+
</plugins>
127+
</build>
128+
</project>
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.agentscope;
18+
19+
import io.agentscope.core.ReActAgent;
20+
import io.agentscope.core.formatter.dashscope.DashScopeChatFormatter;
21+
import io.agentscope.core.memory.InMemoryMemory;
22+
import io.agentscope.core.tool.Toolkit;
23+
import io.agentscope.runtime.LocalDeployManager;
24+
import io.agentscope.runtime.engine.Runner;
25+
import io.agentscope.runtime.engine.agents.agentscope.AgentScopeAgent;
26+
import io.agentscope.runtime.engine.memory.context.ContextComposer;
27+
import io.agentscope.runtime.engine.memory.context.ContextManager;
28+
import io.agentscope.runtime.engine.memory.persistence.memory.service.InMemoryMemoryService;
29+
import io.agentscope.runtime.engine.memory.persistence.session.InMemorySessionHistoryService;
30+
import io.agentscope.runtime.engine.memory.service.MemoryService;
31+
import io.agentscope.runtime.engine.memory.service.SessionHistoryService;
32+
33+
/**
34+
* Example demonstrating how to use SaaAgent to proxy ReactAgent and Runner to execute SaaAgent
35+
*/
36+
public class AgentScopeDeployExample {
37+
38+
private ContextManager contextManager;
39+
40+
public AgentScopeDeployExample() {
41+
// Initialize ContextManager (you may need to adapt this based on your actual implementation)
42+
initializeContextManager();
43+
}
44+
45+
46+
private void initializeContextManager() {
47+
try {
48+
// Create SessionHistoryService for managing conversation history
49+
SessionHistoryService sessionHistoryService = new InMemorySessionHistoryService();
50+
51+
// Create MemoryService for managing agent memory
52+
MemoryService memoryService = new InMemoryMemoryService();
53+
54+
// Create ContextManager with the required services
55+
this.contextManager = new ContextManager(
56+
ContextComposer.class,
57+
sessionHistoryService,
58+
memoryService
59+
);
60+
61+
// Start the context manager services
62+
sessionHistoryService.start().get();
63+
memoryService.start().get();
64+
this.contextManager.start().get();
65+
66+
System.out.println("ContextManager and its services initialized successfully");
67+
} catch (Exception e) {
68+
System.err.println("Failed to initialize ContextManager services: " + e.getMessage());
69+
throw new RuntimeException("ContextManager initialization failed", e);
70+
}
71+
}
72+
73+
74+
/**
75+
* Basic example of using SaaAgent with ReactAgent
76+
*/
77+
public void basicExample() {
78+
try {
79+
80+
Toolkit toolkit = new Toolkit();
81+
82+
ReActAgent.Builder agent =
83+
ReActAgent.builder()
84+
.name("WebAgent")
85+
.sysPrompt(
86+
"You are a helpful AI assistant. Provide clear and concise"
87+
+ " answers.")
88+
.toolkit(toolkit)
89+
.memory(new InMemoryMemory())
90+
.model(
91+
io.agentscope.core.model.DashScopeChatModel.builder()
92+
.apiKey(System.getenv("AI_DASHSCOPE_API_KEY"))
93+
.modelName("qwen-plus")
94+
.stream(true) // Enable streaming
95+
.enableThinking(true)
96+
.formatter(new DashScopeChatFormatter())
97+
.build());
98+
99+
AgentScopeAgent agentScopeAgent = AgentScopeAgent.builder().agent(agent).build();
100+
101+
Runner runner = Runner.builder()
102+
.agent(agentScopeAgent)
103+
.contextManager(contextManager)
104+
.build();
105+
106+
LocalDeployManager.builder().port(10001).build().deploy(runner);
107+
108+
} catch (Exception e) {
109+
e.printStackTrace();
110+
}
111+
}
112+
113+
/**
114+
* Main method to run all examples
115+
*/
116+
public static void main(String[] args) {
117+
// Check if API key is set
118+
if (System.getenv("AI_DASHSCOPE_API_KEY") == null) {
119+
System.err.println("Please set the AI_DASHSCOPE_API_KEY environment variable");
120+
System.exit(1);
121+
}
122+
123+
AgentScopeDeployExample example = new AgentScopeDeployExample();
124+
125+
try {
126+
example.basicExample();
127+
} catch (Exception e) {
128+
e.printStackTrace();
129+
}
130+
}
131+
}
132+

examples/simple_agent_use_examples/agentscope_use_example/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@
8787

8888
<build>
8989
<plugins>
90-
<plugin>
91-
<groupId>org.springframework.boot</groupId>
92-
<artifactId>spring-boot-maven-plugin</artifactId>
93-
<configuration>
94-
<mainClass>io.agentscope.browser.BrowserAgentApplication</mainClass>
95-
</configuration>
96-
</plugin>
97-
9890
<plugin>
9991
<groupId>org.apache.maven.plugins</groupId>
10092
<artifactId>maven-compiler-plugin</artifactId>

examples/simple_agent_use_examples/custom_sandbox_example/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@
8787

8888
<build>
8989
<plugins>
90-
<plugin>
91-
<groupId>org.springframework.boot</groupId>
92-
<artifactId>spring-boot-maven-plugin</artifactId>
93-
<configuration>
94-
<mainClass>io.agentscope.browser.BrowserAgentApplication</mainClass>
95-
</configuration>
96-
</plugin>
97-
9890
<plugin>
9991
<groupId>org.apache.maven.plugins</groupId>
10092
<artifactId>maven-compiler-plugin</artifactId>

0 commit comments

Comments
 (0)