AgentEventEmitter
@FunctionalInterface public interface AgentEventEmitter
io/agentscope/core/event/AgentEventEmitter.java:38–97定义智能体事件 Emitter契约的接口。位于 io.agentscope.core.event 包。核心成员包括 emit、fromContext、fromForwardingContext、CONTEXT_KEY、FORWARDING_CONTEXT_KEY。
Public interface for emitting AgentEvents into the parent agent's streamEvents()
event stream from within tool execution code.
An instance is created inside io.agentscope.core.ReActAgent#streamEvents 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 returns Optional#empty(), allowing callers to
fall back gracefully.
This is the AgentEvent counterpart of
io.agentscope.core.agent.SubagentEventBus, which serves the deprecated
io.agentscope.core.agent.Event type.
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
CONTEXT_KEY | String | 上下文键字段。 Reactor Context key under which the emitter instance is stored. |
FORWARDING_CONTEXT_KEY | String | FORWARDING 上下文键字段。 Reactor Context key for a forwarding emitter injected by a parent tool (e.g. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void emit(AgentEvent event) | 设置发出。 Emits an `AgentEvent` into the parent's `streamEvents()` stream. |
static public Optional<AgentEventEmitter> fromContext(ContextView ctx)static | 设置来自上下文。 Retrieves the `AgentEventEmitter` from the Reactor Context, if present. |
static public Optional<AgentEventEmitter> fromForwardingContext(ContextView ctx)static | 设置该参数。 Retrieves the forwarding `AgentEventEmitter` from the Reactor Context, if present. |
字段详情Field Detail
CONTEXT_KEY
String CONTEXT_KEY
上下文键字段。声明为 String CONTEXT_KEY。
Reactor Context key under which the emitter instance is stored.
io/agentscope/core/event/AgentEventEmitter.java:45FORWARDING_CONTEXT_KEY
String FORWARDING_CONTEXT_KEY
FORWARDING 上下文键字段。声明为 String FORWARDING_CONTEXT_KEY。
Reactor Context key for a forwarding emitter injected by a parent tool (e.g.
io/agentscope/core/event/AgentEventEmitter.java:58方法详情Method Detail
emit
public void emit(AgentEvent event)
设置发出。
Emits an AgentEvent into the parent's streamEvents() stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | AgentEvent | 事件到发出。the event to emit |
io/agentscope/core/event/AgentEventEmitter.java:68fromContext
static public Optional<AgentEventEmitter> fromContext(ContextView ctx)
设置来自上下文。
Retrieves the AgentEventEmitter from the Reactor Context, if present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
ctx | ContextView | 运行时上下文(类型 `ContextView`)。the current Reactor subscriber context |
Optional<AgentEventEmitter>io/agentscope/core/event/AgentEventEmitter.java:77–82fromForwardingContext
static public Optional<AgentEventEmitter> fromForwardingContext(ContextView ctx)
设置该参数。
Retrieves the forwarding AgentEventEmitter from the Reactor Context, if present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
ctx | ContextView | 运行时上下文(类型 `ContextView`)。the current Reactor subscriber context |
Optional<AgentEventEmitter>io/agentscope/core/event/AgentEventEmitter.java:91–96