WorkbenchEventMiddleware
public class WorkbenchEventMiddleware implements MiddlewareBase
io/agentscope/examples/copilotkit/workbench/WorkbenchEventMiddleware.java:70–212Workbench 事件中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.examples.copilotkit.workbench 包,实现 MiddlewareBase。核心成员包括 onAgent、WorkbenchEventMiddleware、CONTEXT_INLINE_CATALOG。
Turns agent progress into shared-state frames while the run is still streaming.
Three things happen here, and each of them is what makes a panel in the browser move:
-
Seeding — the
stateobject and thecontextentries the client sent with the run are folded into the thread'sWorkbenchState, so shared state is genuinely bidirectional instead of server-push only. -
Task mirroring — after every tool result the live
AgentState.getTasksContext()task list (maintained by the built-intodo_writetool) is diffed into shared state, which is how the plan board updates mid-run rather than at the end. -
Permission auditing —
RequireUserConfirmEventandUserConfirmResultEventare recorded so the audit panel shows the full ask → decide trail. The interrupt itself is emitted by the framework's own lifecycle converter.
Queued CustomEvents are spliced into the event stream around each upstream event.
Ordering matters: the opening snapshot goes out immediately after
AgentStartEvent so it lands behind RUN_STARTED, open steps are closed and
everything still queued is flushed before AgentEndEvent so every
STEP_STARTED has a matching STEP_FINISHED and nothing arrives after
RUN_FINISHED.
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
CONTEXT_INLINE_CATALOGstaticfinal | String | 上下文 INLINE 目录字段。 `description` the browser uses to advertise its A2UI catalog through
`useAgentContext`. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public WorkbenchEventMiddleware(WorkbenchStateRegistry registry) | 初始化 `WorkbenchEventMiddleware` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Flux<AgentEvent> onAgent(Agent agent, RuntimeContext ctx, AgentInput input, Function<AgentInput, Flux<AgentEvent>> next) | 处理智能体事件。 Performs the on agent operation. |
字段详情Field Detail
CONTEXT_INLINE_CATALOG
public static final String CONTEXT_INLINE_CATALOG
上下文 INLINE 目录字段。声明为 public static final String CONTEXT_INLINE_CATALOG。
description the browser uses to advertise its A2UI catalog through useAgentContext.
io/agentscope/examples/copilotkit/workbench/WorkbenchEventMiddleware.java:76构造器详情Constructor Detail
WorkbenchEventMiddleware
public WorkbenchEventMiddleware(WorkbenchStateRegistry registry)
初始化 WorkbenchEventMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
registry | WorkbenchStateRegistry | 注册表(类型 `WorkbenchStateRegistry`)。The registry. |
io/agentscope/examples/copilotkit/workbench/WorkbenchEventMiddleware.java:82–84方法详情Method Detail
onAgent
public Flux<AgentEvent> onAgent(Agent agent, RuntimeContext ctx, AgentInput input, Function<AgentInput, Flux<AgentEvent>> next)
处理智能体事件。
Performs the on agent operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
input | AgentInput | 输入消息(类型 `AgentInput`)。The input. |
next | Function<AgentInput, Flux<AgentEvent>> | 下一个(类型 `Function >`)。The next. |
Flux<AgentEvent>io/agentscope/examples/copilotkit/workbench/WorkbenchEventMiddleware.java:86–111