Skip to content

Commit 0163583

Browse files
authored
Merge branch 'main' into 0626-yuluo/add-worksapce-interface
2 parents a8a3ae6 + a5ce01a commit 0163583

261 files changed

Lines changed: 9051 additions & 2738 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.

SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static void main(String[] args) {
172172
import io.agentscope.core.model.DashScopeChatModel;
173173

174174
// OpenAI
175-
import io.agentscope.core.model.OpenAIChatModel;
175+
import io.agentscope.extensions.model.openai.OpenAIChatModel;
176176

177177
// Gemini (Google)
178178
import io.agentscope.core.model.GeminiChatModel;

agentscope-core/pom.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,6 @@
107107
</exclusions>
108108
</dependency>
109109

110-
<!-- Google Gemini Java SDK -->
111-
<dependency>
112-
<groupId>com.google.genai</groupId>
113-
<artifactId>google-genai</artifactId>
114-
</dependency>
115-
116-
<!-- Anthropic Java SDK -->
117-
<dependency>
118-
<groupId>com.anthropic</groupId>
119-
<artifactId>anthropic-java</artifactId>
120-
</dependency>
121-
122110
<!-- Model Context Protocol (MCP) SDK -->
123111
<dependency>
124112
<groupId>io.modelcontextprotocol.sdk</groupId>
@@ -163,6 +151,10 @@
163151
<artifactId>opentelemetry-api</artifactId>
164152
</dependency>
165153

154+
<dependency>
155+
<groupId>io.opentelemetry.instrumentation</groupId>
156+
<artifactId>opentelemetry-reactor-3.1</artifactId>
157+
</dependency>
166158
<dependency>
167159
<groupId>io.opentelemetry</groupId>
168160
<artifactId>opentelemetry-sdk</artifactId>

agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java

Lines changed: 267 additions & 173 deletions
Large diffs are not rendered by default.

agentscope-core/src/main/java/io/agentscope/core/agent/AgentBase.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.concurrent.atomic.AtomicBoolean;
3939
import java.util.function.Function;
4040
import java.util.function.Supplier;
41+
import reactor.core.Disposable;
4142
import reactor.core.publisher.Flux;
4243
import reactor.core.publisher.FluxSink;
4344
import reactor.core.publisher.Mono;
@@ -996,33 +997,37 @@ private Flux<Event> createEventStream(StreamOptions options, Supplier<Mono<Msg>>
996997

997998
// Use Mono.defer to ensure trace context propagation
998999
// while maintaining streaming hook functionality
999-
Mono.defer(() -> callSupplier.get())
1000-
.contextWrite(
1001-
context ->
1002-
context.put(
1003-
SubagentEventBus
1004-
.CONTEXT_KEY,
1005-
bus)
1006-
.putAll(ctxView))
1007-
.doFinally(
1008-
signalType -> {
1009-
// Remove temporary hook
1010-
hooks.remove(streamingHook);
1011-
})
1012-
.subscribe(
1013-
finalMsg -> {
1014-
if (options.shouldStream(
1015-
EventType.AGENT_RESULT)) {
1016-
sink.next(
1017-
new Event(
1018-
EventType
1019-
.AGENT_RESULT,
1020-
finalMsg,
1021-
true));
1022-
}
1023-
},
1024-
sink::error,
1025-
sink::complete);
1000+
Disposable callDisposable =
1001+
Mono.defer(() -> callSupplier.get())
1002+
.contextWrite(
1003+
context ->
1004+
context.put(
1005+
SubagentEventBus
1006+
.CONTEXT_KEY,
1007+
bus)
1008+
.putAll(
1009+
ctxView))
1010+
.doFinally(
1011+
signalType -> {
1012+
// Remove temporary hook
1013+
hooks.remove(streamingHook);
1014+
})
1015+
.subscribe(
1016+
finalMsg -> {
1017+
if (options.shouldStream(
1018+
EventType
1019+
.AGENT_RESULT)) {
1020+
sink.next(
1021+
new Event(
1022+
EventType
1023+
.AGENT_RESULT,
1024+
finalMsg,
1025+
true));
1026+
}
1027+
},
1028+
sink::error,
1029+
sink::complete);
1030+
sink.onCancel(callDisposable);
10261031
},
10271032
FluxSink.OverflowStrategy.BUFFER)
10281033
.publishOn(Schedulers.boundedElastic()));

agentscope-core/src/main/java/io/agentscope/core/agent/StreamableAgent.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ default Flux<Event> stream(List<Msg> msgs) {
165165
@Deprecated(since = "2.0.0", forRemoval = true)
166166
Flux<Event> stream(List<Msg> msgs, StreamOptions options);
167167

168+
/**
169+
* Stream execution events with a caller-supplied per-call runtime context.
170+
*
171+
* <p>Implementations that do not consume {@link RuntimeContext} can rely on this default
172+
* bridge and continue using the original two-argument stream method.
173+
*
174+
* @param msgs Input messages
175+
* @param options Stream configuration options
176+
* @param context Runtime metadata for this call
177+
* @return Flux of events emitted during execution
178+
* @deprecated since 2.0.0, for removal. Use {@code ReActAgent#streamEvents(...)} for the
179+
* fine-grained {@code AgentEvent} stream.
180+
*/
181+
@Deprecated(since = "2.0.0", forRemoval = true)
182+
default Flux<Event> stream(List<Msg> msgs, StreamOptions options, RuntimeContext context) {
183+
return stream(msgs, options);
184+
}
185+
168186
/**
169187
* Stream execution events with structured output support.
170188
*

agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ReasoningContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class ReasoningContext {
5555
// ChatUsage
5656
private int inputTokens = 0;
5757
private int outputTokens = 0;
58+
private int cachedTokens = 0;
5859
private double time = 0;
5960

6061
public ReasoningContext(String agentName) {
@@ -83,6 +84,7 @@ public List<Msg> processChunk(ChatResponse chunk) {
8384
if (usage != null) {
8485
inputTokens = usage.getInputTokens();
8586
outputTokens = usage.getOutputTokens();
87+
cachedTokens = usage.getCachedTokens();
8688
time = usage.getTime();
8789
}
8890

@@ -172,6 +174,7 @@ public Msg buildFinalMessage() {
172174
ChatUsage.builder()
173175
.inputTokens(inputTokens)
174176
.outputTokens(outputTokens)
177+
.cachedTokens(cachedTokens)
175178
.time(time)
176179
.build();
177180
metadata.put(MessageMetadataKeys.CHAT_USAGE, chatUsage);
@@ -278,6 +281,7 @@ public ChatUsage getChatUsage() {
278281
return ChatUsage.builder()
279282
.inputTokens(inputTokens)
280283
.outputTokens(outputTokens)
284+
.cachedTokens(cachedTokens)
281285
.time(time)
282286
.build();
283287
}

agentscope-core/src/main/java/io/agentscope/core/credential/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* <p>{@link io.agentscope.core.credential.CredentialBase} carries the {@code id} field and exposes
2121
* {@code getChatModelClass()} (the consuming {@link io.agentscope.core.model.ChatModelBase}
2222
* subclass) plus {@code listModels()} (model catalog discovery). Concrete subclasses cover
23-
* Anthropic, OpenAI, DashScope, Gemini, Ollama, DeepSeek, Kimi, and xAI. Credentials whose Java
23+
* DashScope, Ollama, DeepSeek, Kimi, and xAI. Credentials whose Java
2424
* model class is not yet implemented throw {@link UnsupportedOperationException} from {@code
2525
* getChatModelClass()} while still round-tripping through JSON for storage compatibility.
2626
*/

agentscope-core/src/main/java/io/agentscope/core/formatter/openai/dto/JsonSchema.java renamed to agentscope-core/src/main/java/io/agentscope/core/formatter/JsonSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.agentscope.core.formatter.openai.dto;
16+
package io.agentscope.core.formatter;
1717

1818
import com.fasterxml.jackson.annotation.JsonInclude;
1919
import com.fasterxml.jackson.annotation.JsonProperty;

agentscope-core/src/main/java/io/agentscope/core/formatter/ResponseFormat.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717

1818
import com.fasterxml.jackson.annotation.JsonInclude;
1919
import com.fasterxml.jackson.annotation.JsonProperty;
20-
import io.agentscope.core.formatter.openai.dto.JsonSchema;
2120

2221
/**
23-
* Response format configuration for OpenAI API.
22+
* Response format configuration for model APIs.
2423
*
2524
* <p>This class supports three response format types:
2625
* <ul>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public abstract class ChatModelBase implements Model {
3030

3131
private int contextWindowSize;
3232

33+
private Boolean nativeStructuredOutputWithTools;
34+
3335
@Override
3436
public int getContextWindowSize() {
3537
return contextWindowSize;
@@ -39,6 +41,17 @@ protected void setContextWindowSize(int contextWindowSize) {
3941
this.contextWindowSize = contextWindowSize;
4042
}
4143

44+
@Override
45+
public boolean supportsNativeStructuredOutputWithTools() {
46+
return nativeStructuredOutputWithTools != null
47+
? nativeStructuredOutputWithTools
48+
: supportsNativeStructuredOutput();
49+
}
50+
51+
protected void setNativeStructuredOutputWithTools(boolean nativeStructuredOutputWithTools) {
52+
this.nativeStructuredOutputWithTools = nativeStructuredOutputWithTools;
53+
}
54+
4255
/**
4356
* Stream chat completion responses.
4457
* The model internally handles message formatting using its configured formatter.

0 commit comments

Comments
 (0)