Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a4d041

Browse files
authored
[Feat]: enhanced subagent support for HarnessAgent (agentscope-ai#1384)
1 parent 9e83aa7 commit 1a4d041

82 files changed

Lines changed: 10159 additions & 914 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.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ build/
3737
.flattened-pom.xml
3838
**/dependency-reduced-pom.xml
3939

40+
### Python
41+
__pycache__/
42+
*.py[cod]
43+
*$py.class
44+
*.egg-info/
45+
4046
### Docs
4147
docs/_build
48+
.venv/
4249

4350

4451
# vibe coding

.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ header:
7272
- 'CNAME'
7373
- 'Jenkinsfile'
7474
- '**/vendor/**'
75+
- '**/docs/**'
7576
- '**/.prettierrc'
7677
comment: on-failure
7778

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,20 @@ private Flux<Event> createEventStream(StreamOptions options, Supplier<Mono<Msg>>
906906
// Add temporary hook
907907
addHook(streamingHook);
908908

909+
// Bus that subagent tools use to push child events
910+
// into this parent sink without an extra Flux layer.
911+
SubagentEventBus bus = sink::next;
912+
909913
// Use Mono.defer to ensure trace context propagation
910914
// while maintaining streaming hook functionality
911915
Mono.defer(() -> callSupplier.get())
912916
.contextWrite(
913-
context -> context.putAll(ctxView))
917+
context ->
918+
context.put(
919+
SubagentEventBus
920+
.CONTEXT_KEY,
921+
bus)
922+
.putAll(ctxView))
914923
.doFinally(
915924
signalType -> {
916925
// Remove temporary hook

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.fasterxml.jackson.annotation.JsonCreator;
1919
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20+
import com.fasterxml.jackson.annotation.JsonInclude;
2021
import com.fasterxml.jackson.annotation.JsonProperty;
2122
import io.agentscope.core.message.Msg;
2223

@@ -46,27 +47,60 @@
4647
* }</pre>
4748
*/
4849
@JsonIgnoreProperties(ignoreUnknown = true)
50+
@JsonInclude(JsonInclude.Include.NON_NULL)
4951
public class Event {
5052

5153
private final EventType type;
5254
private final Msg message;
5355
private final boolean isLast;
5456

5557
/**
56-
* Creates a new event.
58+
* Identifies the originating (sub)agent when this event was emitted by a nested subagent
59+
* during a parent {@code stream()} call. {@code null} for events emitted by the top-level
60+
* agent itself.
61+
*/
62+
private final EventSource source;
63+
64+
/**
65+
* Creates a new event (top-level agent — no source).
5766
*
5867
* @param type The event type (REASONING, TOOL_RESULT, etc.)
5968
* @param message The message content
6069
* @param isLast Whether this is the last/complete message for this event
6170
*/
71+
public Event(EventType type, Msg message, boolean isLast) {
72+
this(type, message, isLast, null);
73+
}
74+
75+
/**
76+
* Creates a new event with optional source.
77+
*
78+
* @param type The event type
79+
* @param message The message content
80+
* @param isLast Whether this is the last/complete message
81+
* @param source The originating subagent, or {@code null} for the top-level agent
82+
*/
6283
@JsonCreator
6384
public Event(
6485
@JsonProperty("type") EventType type,
6586
@JsonProperty("message") Msg message,
66-
@JsonProperty("isLast") boolean isLast) {
87+
@JsonProperty("isLast") boolean isLast,
88+
@JsonProperty("source") EventSource source) {
6789
this.type = type;
6890
this.message = message;
6991
this.isLast = isLast;
92+
this.source = source;
93+
}
94+
95+
/**
96+
* Returns a copy of this event with the given source attached. The original event is not
97+
* modified (immutable copy).
98+
*
99+
* @param source the originating subagent descriptor
100+
* @return new Event with {@code source} set
101+
*/
102+
public Event withSource(EventSource source) {
103+
return new Event(this.type, this.message, this.isLast, source);
70104
}
71105

72106
/**
@@ -137,6 +171,19 @@ public boolean isLast() {
137171
return isLast;
138172
}
139173

174+
/**
175+
* Returns the originating subagent descriptor, or {@code null} if this event was emitted by
176+
* the top-level agent.
177+
*
178+
* <p>Consumers can use this to route subagent events to the correct UI card or log channel
179+
* without needing out-of-band metadata.
180+
*
181+
* @return the event source, or {@code null} for the top-level agent
182+
*/
183+
public EventSource getSource() {
184+
return source;
185+
}
186+
140187
/**
141188
* Get the message ID (delegates to {@link Msg#getId()}).
142189
*
@@ -151,6 +198,11 @@ public String getMessageId() {
151198

152199
@Override
153200
public String toString() {
201+
if (source != null) {
202+
return String.format(
203+
"Event{type=%s, isLast=%s, msgId=%s, contentBlocks=%d, source=%s}",
204+
type, isLast, message.getId(), message.getContent().size(), source);
205+
}
154206
return String.format(
155207
"Event{type=%s, isLast=%s, msgId=%s, contentBlocks=%d}",
156208
type, isLast, message.getId(), message.getContent().size());

0 commit comments

Comments
 (0)