Skip to content

Commit 46cd78a

Browse files
authored
Merge branch 'main' into feat(models)_Kimi_Model_Adaptation
2 parents 6c4eb6a + 194fe2d commit 46cd78a

43 files changed

Lines changed: 2976 additions & 426 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agentscope-core/src/main/java/io/agentscope/core/model/ModelContextWindows.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ private ModelContextWindows() {}
7575
Map.entry("deepseek-v4-flash", 1_000_000),
7676
Map.entry("deepseek-v4-pro", 1_000_000));
7777

78+
public static final Map<String, Integer> GLM =
79+
Map.ofEntries(
80+
Map.entry("glm-5.2", 1_000_000),
81+
Map.entry("glm-5.1", 200_000),
82+
Map.entry("glm-5-turbo", 200_000),
83+
Map.entry("glm-5", 200_000),
84+
Map.entry("glm-4.7-flashx", 200_000),
85+
Map.entry("glm-4.7-flash", 200_000),
86+
Map.entry("glm-4.7", 200_000),
87+
Map.entry("glm-4.6", 200_000),
88+
Map.entry("glm-4.5-airx", 128_000),
89+
Map.entry("glm-4.5-air", 128_000),
90+
Map.entry("glm-4-flashx-250414", 128_000),
91+
Map.entry("glm-4-flash-250414", 128_000),
92+
Map.entry("glm-4-long", 1_000_000));
93+
7894
public static final Map<String, Integer> ANTHROPIC =
7995
Map.ofEntries(
8096
Map.entry("claude-opus-4", 200_000),

agentscope-examples/agents/agentscope-paw/src/main/java/io/agentscope/claw2/runtime/ClawBootstrap.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
* <li>{@link #start()} — initialize and start all pre-registered channel adapters.
8181
* </ol>
8282
*/
83-
public final class ClawBootstrap {
83+
public final class ClawBootstrap implements AutoCloseable {
8484

8585
private static final Logger log = LoggerFactory.getLogger(ClawBootstrap.class);
8686
private static final String DEFAULT_MAIN_ID = "default";
@@ -200,6 +200,32 @@ public void stop() {
200200
}
201201
}
202202

203+
/**
204+
* Stops managed channels and closes all agents created by this bootstrap.
205+
*
206+
* <p>Closing agents releases background task repositories and workspace indexes associated
207+
* with the claw home directory.
208+
*/
209+
@Override
210+
public void close() {
211+
stop();
212+
RuntimeException failure = null;
213+
for (HarnessAgent agent : new LinkedHashSet<>(agents.values())) {
214+
try {
215+
agent.close();
216+
} catch (RuntimeException e) {
217+
if (failure == null) {
218+
failure = e;
219+
} else {
220+
failure.addSuppressed(e);
221+
}
222+
}
223+
}
224+
if (failure != null) {
225+
throw failure;
226+
}
227+
}
228+
203229
// -----------------------------------------------------------------
204230
// Public / package-private accessors
205231
// -----------------------------------------------------------------

agentscope-examples/agents/agentscope-paw/src/test/java/io/agentscope/builder/BuilderBootstrapSmokeTest.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,60 +47,62 @@ class BuilderBootstrapSmokeTest {
4747
@Test
4848
void singleAgent_chatUiChannel() throws Exception {
4949
Model model = stubModel("single-agent-reply");
50-
ClawBootstrap bootstrap =
50+
try (ClawBootstrap bootstrap =
5151
ClawBootstrap.builder()
5252
.skipConfigFile(true)
5353
.cwd(tempDir)
5454
.model(model)
5555
.configureAgent("main", b -> b.name("main").description("main"))
5656
.mainAgent("main")
57-
.build();
58-
59-
ChatUiChannel chat = bootstrap.chatUiChannel();
60-
Msg reply = chat.send("Hello from test").block();
61-
assertTrue(reply.getTextContent().contains("single-agent-reply"));
57+
.build()) {
58+
ChatUiChannel chat = bootstrap.chatUiChannel();
59+
Msg reply = chat.send("Hello from test").block();
60+
assertTrue(reply.getTextContent().contains("single-agent-reply"));
61+
}
6262
}
6363

6464
@Test
6565
void singleAgent_chatUiChannel_perPeer() throws Exception {
6666
Model model = stubModel("per-peer-reply");
67-
ClawBootstrap bootstrap =
67+
try (ClawBootstrap bootstrap =
6868
ClawBootstrap.builder()
6969
.skipConfigFile(true)
7070
.cwd(tempDir)
7171
.model(model)
7272
.configureAgent("main", b -> b.name("main"))
7373
.mainAgent("main")
74-
.build();
75-
76-
ChannelConfig perPeerConfig =
77-
ChannelConfig.builder(ChatUiChannel.CHANNEL_ID).dmScope(DmScope.PER_PEER).build();
78-
ChatUiChannel chat = bootstrap.chatUiChannel(perPeerConfig);
74+
.build()) {
75+
ChannelConfig perPeerConfig =
76+
ChannelConfig.builder(ChatUiChannel.CHANNEL_ID)
77+
.dmScope(DmScope.PER_PEER)
78+
.build();
79+
ChatUiChannel chat = bootstrap.chatUiChannel(perPeerConfig);
7980

80-
Msg reply1 = chat.send("alice", "Hi!").block();
81-
Msg reply2 = chat.send("bob", "Hi!").block();
82-
assertTrue(reply1.getTextContent().contains("per-peer-reply"));
83-
assertTrue(reply2.getTextContent().contains("per-peer-reply"));
81+
Msg reply1 = chat.send("alice", "Hi!").block();
82+
Msg reply2 = chat.send("bob", "Hi!").block();
83+
assertTrue(reply1.getTextContent().contains("per-peer-reply"));
84+
assertTrue(reply2.getTextContent().contains("per-peer-reply"));
85+
}
8486
}
8587

8688
@Test
8789
void multiAgent_defaultRoutesToMain() throws Exception {
8890
Model mainModel = stubModel("from-main");
8991
Model supportModel = stubModel("from-support");
9092

91-
ClawBootstrap bootstrap =
93+
try (ClawBootstrap bootstrap =
9294
ClawBootstrap.builder()
9395
.skipConfigFile(true)
9496
.cwd(tempDir)
9597
.model(mainModel)
9698
.configureAgent("main", b -> b.name("main-agent").model(mainModel))
9799
.configureAgent("support", b -> b.name("support-agent").model(supportModel))
98100
.mainAgent("main")
99-
.build();
100-
101-
ChatUiChannel chat = bootstrap.chatUiChannel();
102-
Msg reply = chat.send("hello").block();
103-
assertTrue(reply.getTextContent().contains("from-main"));
101+
.build()) {
102+
ChatUiChannel chat = bootstrap.chatUiChannel();
103+
Msg reply = chat.send("hello").block();
104+
assertTrue(reply.getTextContent().contains("from-main"));
105+
}
104106
}
105107

106108
private static Model stubModel(String assistantText) {

agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-e2e-tests/src/test/java/io/agentscope/core/e2e/providers/GLMProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import io.agentscope.core.ReActAgent;
1919
import io.agentscope.core.tool.Toolkit;
2020
import io.agentscope.extensions.model.openai.OpenAIChatModel;
21-
import io.agentscope.extensions.model.openai.formatter.GLMFormatter;
22-
import io.agentscope.extensions.model.openai.formatter.GLMMultiAgentFormatter;
21+
import io.agentscope.extensions.model.openai.compat.glm.GLMFormatter;
22+
import io.agentscope.extensions.model.openai.compat.glm.GLMMultiAgentFormatter;
2323
import java.util.HashSet;
2424
import java.util.Set;
2525

agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-ollama/src/main/java/io/agentscope/extensions/model/ollama/OllamaChatModel.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class OllamaChatModel extends ChatModelBase {
6464
private static final Logger log = LoggerFactory.getLogger(OllamaChatModel.class);
6565

6666
private final String modelName;
67+
private final boolean stream;
6768
private final OllamaHttpClient httpClient;
6869
private final OllamaOptions defaultOptions;
6970
private final Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter;
@@ -72,7 +73,7 @@ public class OllamaChatModel extends ChatModelBase {
7273
* Creates a new OllamaChatModel.
7374
*
7475
* @param modelName The name of the model to use (e.g., "llama2", "mistral").
75-
* @param baseUrl The base URL of the Ollama server (e.g., "http://localhost:11434").
76+
* @param baseUrl The base URL of the Ollama server (e.g. "http://localhost:11434").
7677
* @param defaultOptions Default configuration options.
7778
* @param formatter The message formatter to use.
7879
* @param httpTransport The HTTP transport to use.
@@ -83,10 +84,24 @@ public OllamaChatModel(
8384
OllamaOptions defaultOptions,
8485
Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter,
8586
HttpTransport httpTransport) {
87+
this(modelName, baseUrl, defaultOptions, formatter, httpTransport, true);
88+
}
89+
90+
/**
91+
* Creates a new OllamaChatModel with an explicit streaming mode.
92+
*/
93+
public OllamaChatModel(
94+
String modelName,
95+
String baseUrl,
96+
OllamaOptions defaultOptions,
97+
Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter,
98+
HttpTransport httpTransport,
99+
boolean stream) {
86100
this.modelName = modelName;
87101
this.defaultOptions =
88102
defaultOptions != null ? defaultOptions : OllamaOptions.builder().build();
89103
this.formatter = formatter != null ? formatter : new OllamaChatFormatter();
104+
this.stream = stream;
90105

91106
HttpTransport transport =
92107
httpTransport != null ? httpTransport : HttpTransportFactory.getDefault();
@@ -118,6 +133,10 @@ public String getModelName() {
118133
return this.modelName;
119134
}
120135

136+
public boolean isStreaming() {
137+
return this.stream;
138+
}
139+
121140
/**
122141
* Chat with the model using Ollama-specific options.
123142
* <p>
@@ -145,12 +164,14 @@ public ChatResponse chat(List<Msg> messages, GenerateOptions options) {
145164
@Override
146165
protected Flux<ChatResponse> doStream(
147166
List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) {
167+
boolean effectiveStream =
168+
options != null && options.getStream() != null ? options.getStream() : this.stream;
148169
return streamWithHttpClient(
149170
messages,
150171
tools,
151172
options != null ? options.getToolChoice() : null,
152173
OllamaOptions.fromGenerateOptions(options),
153-
true);
174+
effectiveStream);
154175
}
155176

156177
/**
@@ -250,6 +271,7 @@ public static class Builder {
250271
private HttpTransport httpTransport;
251272
private ProxyConfig proxyConfig;
252273
private int contextWindowSize = -1;
274+
private boolean stream = true;
253275

254276
public Builder modelName(String modelName) {
255277
this.modelName = modelName;
@@ -261,6 +283,15 @@ public Builder baseUrl(String baseUrl) {
261283
return this;
262284
}
263285

286+
/**
287+
* Sets whether streaming should be enabled.
288+
* <p>Default is {@code true}
289+
*/
290+
public Builder stream(boolean stream) {
291+
this.stream = stream;
292+
return this;
293+
}
294+
264295
public Builder defaultOptions(OllamaOptions defaultOptions) {
265296
this.defaultOptions = defaultOptions;
266297
return this;
@@ -348,7 +379,8 @@ public OllamaChatModel build() {
348379
HttpTransport transport = resolveTransport();
349380

350381
OllamaChatModel model =
351-
new OllamaChatModel(modelName, baseUrl, finalOptions, formatter, transport);
382+
new OllamaChatModel(
383+
modelName, baseUrl, finalOptions, formatter, transport, stream);
352384
if (contextWindowSize >= 0) {
353385
model.setContextWindowSize(contextWindowSize);
354386
}

agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-ollama/src/main/java/io/agentscope/extensions/model/ollama/OllamaModelProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public Model create(String modelId, ModelCreationContext context) {
6161
}
6262
OllamaChatModel.Builder builder =
6363
OllamaChatModel.builder().modelName(modelName).baseUrl(baseUrl);
64+
if (context.getStream() != null) {
65+
builder.stream(context.getStream());
66+
}
6467
applyAdvancedOptions(builder, context);
6568
return builder.build();
6669
}

0 commit comments

Comments
 (0)