类 Event
java.lang.Object
io.agentscope.core.agent.Event
An event emitted during streaming agent execution.
Events provide a structured way to observe agent execution, with clear type identification and completion status for each message.
Example usage:
agent.stream(userMsg, options)
.subscribe(event -> {
switch (event.getType()) {
case REASONING -> {
if (event.isLast()) {
System.out.println("✓ Reasoning complete");
} else {
System.out.print("..."); // Progress indicator
}
}
case TOOL_RESULT -> {
System.out.println("Tool: " + event.getMessage().getTextContent());
}
}
});
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Get the message content.Get the message ID (delegates toMsg.getId()).getType()Get the event type.booleanisLast()Check if this is the last/complete message for this event.toString()
-
构造器详细资料
-
Event
Creates a new event.- 参数:
type- The event type (REASONING, TOOL_RESULT, etc.)message- The message contentisLast- Whether this is the last/complete message for this event
-
-
方法详细资料
-
getType
Get the event type.Use this to determine what kind of message this is and how to process it.
- 返回:
- The event type
-
getMessage
Get the message content.The message contains the actual data - inspect
Msg.getRole(),Msg.getContent(), and other fields for details.- 返回:
- The message
-
isLast
public boolean isLast()Check if this is the last/complete message for this event.Return values:
true: Complete message or final chunk. Safe to persist, display as final, or trigger downstream processing.false: Intermediate chunk. More events with the same message ID will follow. Useful for real-time UI updates.
Streaming behavior: For streaming events (e.g., LLM streaming output), multiple events will be emitted with the same
Msg.getId():Event(type=REASONING, msg(id="abc", content=[...]), isLast=false) Event(type=REASONING, msg(id="abc", content=[...]), isLast=false) Event(type=REASONING, msg(id="abc", content=[...]), isLast=true) ← Final
Non-streaming behavior: For non-streaming events, there will be only one event and
isLastis alwaystrue.Example usage:
agent.stream(userMsg, options) .subscribe(event -> { if (event.isLast()) { // Complete message - safe to persist or process database.save(event.getMessage()); } else { // Intermediate chunk - update UI ui.append(event.getMessage().getTextContent()); } });- 返回:
- true if this is the last chunk, false if more chunks will follow
-
getMessageId
Get the message ID (delegates toMsg.getId()).Events with the same message ID are parts of the same logical message. Use this to group streaming chunks together.
- 返回:
- The message ID
-
toString
-