Skip to content

Commit 789a9e1

Browse files
Merge branch 'main' into fix/background-subagent-cancel
2 parents 914c87c + 297e985 commit 789a9e1

189 files changed

Lines changed: 24302 additions & 2607 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.

‎.github/scripts/check-shade-and-bom-sync.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ get_packaging() {
7979

8080
# Scan agentscope-extensions directory for jar modules
8181
echo "Scanning agentscope-extensions/ for jar modules..."
82-
for pom in $(find "agentscope-extensions" -name "pom.xml" -type f); do
82+
for pom in $(find "agentscope-extensions" -type d -name target -prune -o -name "pom.xml" -type f -print); do
8383
packaging=$(get_packaging "$pom")
8484

8585
# Skip pom packaging (aggregator modules)

‎.licenserc.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ header:
1616
See the License for the specific language governing permissions and
1717
limitations under the License.
1818
19+
language:
20+
Diff:
21+
extensions: [".patch"]
22+
comment_style_id: SlashAsterisk
23+
1924
paths-ignore:
2025
# Configuration files (including example configurations)
2126
- '**/.env'

‎agentscope-core/src/main/java/io/agentscope/core/model/FinishReasons.java‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,28 @@
2323
*
2424
* <p>Providers report termination with raw strings (for example {@code "stop"}, {@code "length"},
2525
* {@code "MAX_TOKENS"}), and some report no reason at all. This helper identifies the one case
26-
* callers must treat as incomplete output: the provider explicitly stopped at an output-token
27-
* limit. A missing or unrecognized reason never indicates truncation, so callers keep accepting
28-
* providers that do not report one.
26+
* callers must treat as incomplete output: the provider stopped at an output-token limit or filled
27+
* the context window. A missing or unrecognized reason never indicates truncation, so callers keep
28+
* accepting providers that do not report one.
2929
*/
3030
public final class FinishReasons {
3131

3232
private FinishReasons() {}
3333

3434
/**
35-
* Returns whether the reported termination means the output was cut at an output-token limit.
35+
* Returns whether the reported termination means the output was cut short.
3636
*
3737
* @param finishReason the last reported finish reason, or {@code null} when none was
3838
* @param responseMetadata response metadata accompanying that report, or {@code null}
3939
*/
4040
public static boolean indicatesOutputLimit(
4141
String finishReason, Map<String, Object> responseMetadata) {
4242
// OpenAI Chat Completions and DashScope report "length"; Anthropic and Gemini report
43-
// "max_tokens" or "MAX_TOKENS".
43+
// "max_tokens" or "MAX_TOKENS"; Anthropic reports "model_context_window_exceeded" when the
44+
// response fills the context window instead of reaching its own output limit.
4445
if ("length".equalsIgnoreCase(finishReason)
45-
|| "max_tokens".equalsIgnoreCase(finishReason)) {
46+
|| "max_tokens".equalsIgnoreCase(finishReason)
47+
|| "model_context_window_exceeded".equalsIgnoreCase(finishReason)) {
4648
return true;
4749
}
4850
// The OpenAI Responses API reports "incomplete" and names the cause in metadata; only the

‎agentscope-core/src/main/java/io/agentscope/core/model/GenerateOptions.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ public static Builder builder() {
421421
* <p><b>Merge Behavior:</b>
422422
* <ul>
423423
* <li>Primitive fields (temperature, topP, etc.): primary != null ? primary : fallback</li>
424+
* <li>Output limits: maxTokens and maxCompletionTokens are one override group, so a primary
425+
* value in either field replaces both fallback limits</li>
424426
* <li>Map fields (additionalHeaders, etc.): merges both maps, with primary values overriding fallback</li>
425427
* <li>If primary is null, returns fallback directly</li>
426428
* <li>If fallback is null, returns primary directly</li>
@@ -472,11 +474,10 @@ public static GenerateOptions mergeOptions(GenerateOptions primary, GenerateOpti
472474
builder.temperature(
473475
primary.temperature != null ? primary.temperature : fallback.temperature);
474476
builder.topP(primary.topP != null ? primary.topP : fallback.topP);
475-
builder.maxTokens(primary.maxTokens != null ? primary.maxTokens : fallback.maxTokens);
477+
boolean outputOverride = primary.maxTokens != null || primary.maxCompletionTokens != null;
478+
builder.maxTokens(outputOverride ? primary.maxTokens : fallback.maxTokens);
476479
builder.maxCompletionTokens(
477-
primary.maxCompletionTokens != null
478-
? primary.maxCompletionTokens
479-
: fallback.maxCompletionTokens);
480+
outputOverride ? primary.maxCompletionTokens : fallback.maxCompletionTokens);
480481
builder.frequencyPenalty(
481482
primary.frequencyPenalty != null
482483
? primary.frequencyPenalty

‎agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ private Mono<ToolResultBlock> executeCore(
370370
}
371371
final RuntimeContext effectiveRuntimeContext = runtimeContext;
372372

373-
// Create emitter for streaming
373+
// Preserve an emitter supplied for this call alongside the Toolkit callbacks.
374+
var callerEmitter = param.getEmitter();
374375
ToolEmitter toolEmitter =
375376
new DefaultToolEmitter(
376377
toolCall,
@@ -390,6 +391,12 @@ private Mono<ToolResultBlock> executeCore(
390391
if (executionCallback != null)
391392
invokeChunkCallback(
392393
"internal", executionCallback::onProgress, use, chunk);
394+
if (callerEmitter != NoOpToolEmitter.INSTANCE)
395+
invokeChunkCallback(
396+
"caller",
397+
(ignored, value) -> callerEmitter.emit(value),
398+
use,
399+
chunk);
393400
if (userChunkCallback != null)
394401
invokeChunkCallback("user", userChunkCallback, use, chunk);
395402
});

‎agentscope-core/src/test/java/io/agentscope/core/model/FinishReasonsTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void recognizesExplicitOutputLimitFinishReasons() {
2929
assertTrue(FinishReasons.indicatesOutputLimit("length", Map.of()));
3030
assertTrue(FinishReasons.indicatesOutputLimit("MAX_TOKENS", Map.of()));
3131
assertTrue(FinishReasons.indicatesOutputLimit("max_tokens", Map.of()));
32+
assertTrue(FinishReasons.indicatesOutputLimit("model_context_window_exceeded", Map.of()));
3233
}
3334

3435
@Test

‎agentscope-core/src/test/java/io/agentscope/core/model/GenerateOptionsTest.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,55 @@
3131
@DisplayName("GenerateOptions Tests")
3232
class GenerateOptionsTest {
3333

34+
@Test
35+
@DisplayName("A request maxTokens replaces either inherited output limit")
36+
void requestMaxTokensReplacesInheritedCompletionLimit() {
37+
GenerateOptions merged =
38+
GenerateOptions.mergeOptions(
39+
GenerateOptions.builder().maxTokens(64).build(),
40+
GenerateOptions.builder().maxCompletionTokens(16000).build());
41+
42+
assertEquals(64, merged.getMaxTokens());
43+
assertNull(merged.getMaxCompletionTokens());
44+
}
45+
46+
@Test
47+
@DisplayName("A request maxCompletionTokens replaces either inherited output limit")
48+
void requestCompletionLimitReplacesInheritedMaxTokens() {
49+
GenerateOptions merged =
50+
GenerateOptions.mergeOptions(
51+
GenerateOptions.builder().maxCompletionTokens(64).build(),
52+
GenerateOptions.builder().maxTokens(16000).build());
53+
54+
assertEquals(64, merged.getMaxCompletionTokens());
55+
assertNull(merged.getMaxTokens());
56+
}
57+
58+
@Test
59+
@DisplayName("Request options without an output limit keep both inherited limits")
60+
void requestWithoutOutputLimitKeepsInheritedLimits() {
61+
GenerateOptions merged =
62+
GenerateOptions.mergeOptions(
63+
GenerateOptions.builder().temperature(0.1).build(),
64+
GenerateOptions.builder().maxCompletionTokens(16000).build());
65+
66+
assertEquals(16000, merged.getMaxCompletionTokens());
67+
assertNull(merged.getMaxTokens());
68+
assertEquals(0.1, merged.getTemperature());
69+
}
70+
71+
@Test
72+
@DisplayName("A request supplying both output limits keeps both")
73+
void requestSupplyingBothLimitsKeepsBoth() {
74+
GenerateOptions merged =
75+
GenerateOptions.mergeOptions(
76+
GenerateOptions.builder().maxTokens(64).maxCompletionTokens(128).build(),
77+
GenerateOptions.builder().maxTokens(16000).build());
78+
79+
assertEquals(64, merged.getMaxTokens());
80+
assertEquals(128, merged.getMaxCompletionTokens());
81+
}
82+
3483
@Test
3584
@DisplayName("Should build GenerateOptions with all parameters using builder")
3685
void testBuilderAllParameters() {

‎agentscope-durable/README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ checks that its controlled file effect happens once:
273273
bash agentscope-examples/durable/integrated/tool-in-sandbox/run.sh
274274
```
275275

276-
For separate Brain and Hands processes, start with the
276+
For separate Brain and Hands processes, try the [SSE/HTTP echo example](../agentscope-examples/durable/brain-hands/sse-echo-tool/README.en.md) or the
277277
[RocketMQ echo example](../agentscope-examples/durable/brain-hands/echo-tool/README.en.md), then
278-
the [queued Sandbox example](../agentscope-examples/durable/brain-hands/tool-in-sandbox/README.en.md).
278+
the [RocketMQ or SSE Sandbox example](../agentscope-examples/durable/brain-hands/tool-in-sandbox/README.en.md).
279279
Brain–Hands separation is optional; it does not require every tool to become a
280280
remote service.
281281

@@ -412,11 +412,11 @@ bash agentscope-examples/durable/brain-hands/tool-in-sandbox/run.sh --compile-on
412412

413413
`integrated` includes quickstart, API-only http-server and colocated tool-in-sandbox.
414414
The tool-in-sandbox launcher runs sequential `start` and `resume` JVMs, each colocating
415-
Brain and Hands. `brain-hands` includes echo-tool and tool-in-sandbox, with independent
416-
Brain/Hands processes communicating through MQ. Each module packages `${artifact}-brain.jar`
415+
Brain and Hands. `brain-hands` includes sse-echo-tool, echo-tool and tool-in-sandbox, with independent
416+
Brain/Hands processes communicating over SSE/HTTP or RocketMQ. Each module packages `${artifact}-brain.jar`
417417
and `${artifact}-hands.jar` with separate Java main classes and runners, without a Java role
418418
argument or enum. Use `run.sh <brain|hands> <endpoint> [data-directory]` to select the JAR;
419-
there is no `worker` alias. Start Hands first, then Brain in another terminal.
419+
there is no `worker` alias. For RocketMQ, start Hands first, then Brain in another terminal.
420420
Offline fixtures need no model credentials. Local Sandbox requires POSIX shell and Python 3
421421
and runs with host permissions, not production isolation. Real queued runs also require
422422
RocketMQ 5, topics/groups and authorization. `--compile-only` checks packaging, not broker

‎agentscope-durable/durable-adapters/durable-adapter-agui/src/main/java/io/agentscope/durable/agui/DurableAguiEventAdapter.java‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ public List<AguiEvent> map(SessionStreamEvent event) {
5050
preview.threadId(), require(preview.runId(), "runId"), preview.data());
5151
}
5252
if (event instanceof SessionStreamEvent.EventDelta delta) {
53+
if (delta.deltaType() == EventDeltaType.TOOL_PROGRESS)
54+
return toolPreview(
55+
delta.threadId(),
56+
delta.runId(),
57+
"agentscope.tool_progress_delta",
58+
delta.data());
5359
if (delta.deltaType() == EventDeltaType.TOOL_OUTPUT)
54-
return toolOutput(delta.threadId(), delta.runId(), delta.data());
60+
return toolPreview(
61+
delta.threadId(),
62+
delta.runId(),
63+
"agentscope.tool_output_delta",
64+
delta.data());
5565
String runId = require(delta.runId(), "runId");
5666
if (delta.deltaType() == EventDeltaType.MESSAGE)
5767
return messageDelta(delta.threadId(), runId, delta.data());
@@ -83,6 +93,28 @@ List<AguiEvent> committed(PublicEvent event) {
8393
require(event.stepId(), "stepId")));
8494
case "message.completed" -> message(event);
8595
case "tool.call.updated" -> tool(event);
96+
case "turn.delegated",
97+
"tool.delegated",
98+
"turn.waiting",
99+
"turn.resumed",
100+
"turn.cancel_requested",
101+
"turn.cancelled",
102+
"turn.succeeded",
103+
"turn.failed",
104+
"interaction.requested",
105+
"interaction.resolved",
106+
"x.remote-subagent.admitted",
107+
"x.remote-subagent.progress",
108+
"x.remote-subagent.control",
109+
"x.remote-subagent.outcome" ->
110+
List.of(
111+
new AguiEvent.Custom(
112+
threadId,
113+
runId == null ? require(event.turnId(), "turnId") : runId,
114+
"agentscope." + event.type(),
115+
DurableJson.convert(DurableJson.value(event), Object.class),
116+
event.occurredAt(),
117+
null));
86118
default -> List.of();
87119
};
88120
}
@@ -91,7 +123,11 @@ List<AguiEvent> live(LiveEvent event) {
91123
Objects.requireNonNull(event);
92124
String threadId = event.threadId();
93125
if (ToolOutputDelta.TYPE.equals(event.type()))
94-
return toolOutput(threadId, event.runId(), event.data());
126+
return toolPreview(
127+
threadId, event.runId(), "agentscope.tool_output_delta", event.data());
128+
if ("tool.progress.delta".equals(event.type()))
129+
return toolPreview(
130+
threadId, event.runId(), "agentscope.tool_progress_delta", event.data());
95131
String runId = require(event.runId(), "runId");
96132
var data = event.data();
97133
return switch (event.type()) {
@@ -102,14 +138,12 @@ List<AguiEvent> live(LiveEvent event) {
102138
};
103139
}
104140

105-
private static List<AguiEvent> toolOutput(String threadId, String runId, JsonNode data) {
141+
private static List<AguiEvent> toolPreview(
142+
String threadId, String runId, String name, JsonNode data) {
106143
if (runId == null) return List.of();
107144
return List.of(
108145
new AguiEvent.Custom(
109-
threadId,
110-
runId,
111-
"agentscope.tool_output_delta",
112-
DurableJson.convert(data, Object.class)));
146+
threadId, runId, name, DurableJson.convert(data, Object.class)));
113147
}
114148

115149
private List<AguiEvent> runEnded(PublicEvent event) {

‎agentscope-durable/durable-adapters/durable-adapter-agui/src/test/java/io/agentscope/durable/agui/DurableAguiEventAdapterTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ void committedResultApplicationDoesNotRepeatTheToolResult() {
7676
assertEquals(List.of(), adapter.committed(applied));
7777
}
7878

79+
@Test
80+
void childApprovalKeepsDurableIdentityWithoutAnInvocation() {
81+
var approval =
82+
new PublicEvent(
83+
"1",
84+
"approval",
85+
session,
86+
"child",
87+
"child-turn",
88+
null,
89+
null,
90+
"3",
91+
"approval-cursor",
92+
0,
93+
"interaction.requested",
94+
DurableJson.value(Map.of("id", "confirm", "kind", "confirmation")));
95+
var mapped = assertInstanceOf(AguiEvent.Custom.class, adapter.committed(approval).get(0));
96+
assertEquals("agentscope.interaction.requested", mapped.name());
97+
assertEquals("child", mapped.threadId());
98+
assertEquals("child-turn", mapped.runId());
99+
var payload = DurableJson.value(mapped.value());
100+
assertEquals("approval-cursor", payload.path("cursor").asText());
101+
assertEquals("confirm", payload.path("data").path("id").asText());
102+
}
103+
79104
@Test
80105
void toolOutputPreviewDoesNotBecomeAnAguiToolResult() {
81106
var data = new ToolOutputDelta("call", "execution", 1, 0, 0, 3, "YWJj");

0 commit comments

Comments
 (0)