接口 SubagentEventBus


public interface SubagentEventBus
A lightweight channel that allows synchronously-invoked subagents to push their Events into the parent agent's Flux<Event> stream.

An instance is created inside AgentBase.createEventStream(io.agentscope.core.agent.StreamOptions, java.util.function.Supplier<reactor.core.publisher.Mono<io.agentscope.core.message.Msg>>) and stored in the Reactor Context under CONTEXT_KEY. When a tool method (e.g. agent_spawn) runs inside that stream pipeline, it can retrieve the bus via fromContext(ContextView) and forward each child event to the parent sink.

Events emitted through the bus must already carry an EventSource (attached by the caller) so downstream consumers can identify the originating subagent.

When the parent agent is invoked via call() (non-streaming), no bus is present in the context and fromContext(reactor.util.context.ContextView) returns Optional.empty(), allowing callers to fall back gracefully to the blocking path.

  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    Reactor Context key under which the bus instance is stored.
  • 方法概要

    修饰符和类型
    方法
    说明
    void
    emit(Event event)
    Emits a subagent event into the parent stream.
    fromContext(reactor.util.context.ContextView ctx)
    Retrieves the SubagentEventBus from the Reactor Context, if present.
  • 字段详细资料

  • 方法详细资料

    • emit

      void emit(Event event)
      Emits a subagent event into the parent stream. The event should carry a non-null EventSource identifying the originating subagent.

      This method is safe to call from any thread; the underlying FluxSink.next is thread-safe.

      参数:
      event - the event to forward (must have EventSource set)
    • fromContext

      static Optional<SubagentEventBus> fromContext(reactor.util.context.ContextView ctx)
      Retrieves the SubagentEventBus from the Reactor Context, if present.
      参数:
      ctx - the current Reactor subscriber context
      返回:
      an Optional containing the bus, or empty when running outside a streaming pipeline