接口 AgentEventEmitter
- 函数接口:
- 这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。
AgentEvents into the parent agent's streamEvents()
event stream from within tool execution code.
An instance is created inside ReActAgent.streamEvents(java.util.List<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 emitter via
fromContext(ContextView) and inject custom events (e.g. SubagentExposedEvent).
When the parent agent is invoked via call() (non-streaming), no emitter is present
in the context and fromContext(reactor.util.context.ContextView) returns Optional.empty(), allowing callers to
fall back gracefully.
This is the AgentEvent counterpart of
SubagentEventBus, which serves the deprecated
Event type.
-
字段概要
字段 -
方法概要
修饰符和类型方法说明voidemit(AgentEvent event) Emits anAgentEventinto the parent'sstreamEvents()stream.static Optional<AgentEventEmitter> fromContext(reactor.util.context.ContextView ctx) Retrieves theAgentEventEmitterfrom the Reactor Context, if present.static Optional<AgentEventEmitter> fromForwardingContext(reactor.util.context.ContextView ctx) Retrieves the forwardingAgentEventEmitterfrom the Reactor Context, if present.
-
字段详细资料
-
CONTEXT_KEY
Reactor Context key under which the emitter instance is stored. UsefromContext(ContextView)for retrieval.- 另请参阅:
-
FORWARDING_CONTEXT_KEY
Reactor Context key for a forwarding emitter injected by a parent tool (e.g.agent_spawn) into a child agent's Reactor Context. When present, the child'spublishEvent()uses this emitter instead of the directFluxSink, so every child event is tagged with a source path before entering the parent's stream.This is intentionally separate from
CONTEXT_KEY: the regular key carries the parent's own emitter (used by tools to emit custom events likeSubagentExposedEvent), while this key carries a source-tagging wrapper for the child's internal events.- 另请参阅:
-
-
方法详细资料
-
emit
Emits anAgentEventinto the parent'sstreamEvents()stream.This method is safe to call from any thread; the underlying
FluxSink.nextis thread-safe.- 参数:
event- the event to emit
-
fromContext
Retrieves theAgentEventEmitterfrom the Reactor Context, if present.- 参数:
ctx- the current Reactor subscriber context- 返回:
- an
Optionalcontaining the emitter, or empty when running outside a streaming pipeline
-
fromForwardingContext
Retrieves the forwardingAgentEventEmitterfrom the Reactor Context, if present.- 参数:
ctx- the current Reactor subscriber context- 返回:
- an
Optionalcontaining the forwarding emitter, or empty when not in a child-agent forwarding context
-