类 Event

java.lang.Object
io.agentscope.core.agent.Event

@Deprecated(since="2.0.0") public class Event extends Object
已过时。
since 2.0.0. This is the v1 coarse-grained event type, kept as the return type of the deprecated stream(...) API and as the wire format consumed by the harness, AGUI, A2A, chat-completions-web, and Kotlin extension modules. New code should use io.agentscope.core.event.AgentEvent via ReActAgent#streamEvents(...), which exposes the fine-grained event hierarchy (28 typed events covering the full agent lifecycle and HITL flow). The class will be marked forRemoval = true once the dependent internal modules migrate to AgentEvent.
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());
             }
         }
     });
 
  • 构造器详细资料

    • Event

      public Event(EventType type, Msg message, boolean isLast)
      已过时。
      Creates a new event (top-level agent — no source).
      参数:
      type - The event type (REASONING, TOOL_RESULT, etc.)
      message - The message content
      isLast - Whether this is the last/complete message for this event
    • Event

      public Event(EventType type, Msg message, boolean isLast, EventSource source)
      已过时。
      Creates a new event with optional source.
      参数:
      type - The event type
      message - The message content
      isLast - Whether this is the last/complete message
      source - The originating subagent, or null for the top-level agent
  • 方法详细资料

    • withSource

      public Event withSource(EventSource source)
      已过时。
      Returns a copy of this event with the given source attached. The original event is not modified (immutable copy).
      参数:
      source - the originating subagent descriptor
      返回:
      new Event with source set
    • getType

      public EventType getType()
      已过时。
      Get the event type.

      Use this to determine what kind of message this is and how to process it.

      返回:
      The event type
    • getMessage

      public Msg 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 isLast is always true.

      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
    • getSource

      public EventSource getSource()
      已过时。
      Returns the originating subagent descriptor, or null if this event was emitted by the top-level agent.

      Consumers can use this to route subagent events to the correct UI card or log channel without needing out-of-band metadata.

      返回:
      the event source, or null for the top-level agent
    • getMessageId

      public String getMessageId()
      已过时。
      Get the message ID (delegates to Msg.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

      public String toString()
      已过时。
      覆盖:
      toString 在类中 Object