AS AgentScopeAPI 手册 / API Reference

SubagentEventBus

public interface SubagentEventBus
源码Source io/agentscope/core/agent/SubagentEventBus.java:37–69

定义子智能体事件总线契约的接口。位于 io.agentscope.core.agent 包。核心成员包括 emit、fromContext、CONTEXT_KEY。

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 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 returns Optional#empty(), allowing callers to fall back gracefully to the blocking path.

字段摘要Field Summary

字段Field类型Type说明Description
CONTEXT_KEY
String
上下文键字段。
Reactor Context key under which the bus instance is stored.

方法摘要Method Summary

方法Method说明Description
public void emit(Event event)
设置发出。
Emits a subagent event into the parent stream.
static public Optional<SubagentEventBus> fromContext(ContextView ctx)
static
设置来自上下文。
Retrieves the `SubagentEventBus` from the Reactor Context, if present.

字段详情Field Detail

CONTEXT_KEY

String CONTEXT_KEY

上下文键字段。声明为 String CONTEXT_KEY。

Reactor Context key under which the bus instance is stored.

源码Source io/agentscope/core/agent/SubagentEventBus.java:43

方法详情Method Detail

emit

public void emit(Event event)

设置发出。

Emits a subagent event into the parent stream.

参数Parameters
名称Name类型Type说明Description
eventEvent事件(类型 `Event`)。the event to forward (must have `EventSource` set)
源码Source io/agentscope/core/agent/SubagentEventBus.java:54

fromContext

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

设置来自上下文。

Retrieves the SubagentEventBus from the Reactor Context, if present.

参数Parameters
名称Name类型Type说明Description
ctxContextView运行时上下文(类型 `ContextView`)。the current Reactor subscriber context
返回Returns Optional<SubagentEventBus>
返回可选。an `Optional` containing the bus, or empty when running outside a streaming pipeline
源码Source io/agentscope/core/agent/SubagentEventBus.java:63–68
基于官方固定版本源码静态生成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.