AS AgentScopeAPI 手册 / API Reference

AgentEventEmitter

@FunctionalInterface public interface AgentEventEmitter
源码Source 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.

源码Source io/agentscope/core/event/AgentEventEmitter.java:45

FORWARDING_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.

源码Source io/agentscope/core/event/AgentEventEmitter.java:58

方法详情Method Detail

emit

public void emit(AgentEvent event)

设置发出。

Emits an AgentEvent into the parent's streamEvents() stream.

参数Parameters
名称Name类型Type说明Description
eventAgentEvent事件到发出。the event to emit
源码Source io/agentscope/core/event/AgentEventEmitter.java:68

fromContext

static public Optional<AgentEventEmitter> fromContext(ContextView ctx)
static

设置来自上下文。

Retrieves the AgentEventEmitter from the Reactor Context, if present.

参数Parameters
名称Name类型Type说明Description
ctxContextView运行时上下文(类型 `ContextView`)。the current Reactor subscriber context
返回Returns Optional<AgentEventEmitter>
返回可选。an `Optional` containing the emitter, or empty when running outside a streaming pipeline
源码Source io/agentscope/core/event/AgentEventEmitter.java:77–82

fromForwardingContext

static public Optional<AgentEventEmitter> fromForwardingContext(ContextView ctx)
static

设置该参数。

Retrieves the forwarding AgentEventEmitter from the Reactor Context, if present.

参数Parameters
名称Name类型Type说明Description
ctxContextView运行时上下文(类型 `ContextView`)。the current Reactor subscriber context
返回Returns Optional<AgentEventEmitter>
返回可选。an `Optional` containing the forwarding emitter, or empty when not in a child-agent forwarding context
源码Source io/agentscope/core/event/AgentEventEmitter.java:91–96
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.