Class ChatUiChannel
java.lang.Object
io.agentscope.harness.agent.gateway.channel.chatui.ChatUiChannel
- All Implemented Interfaces:
Channel
Default
Channel implementation for direct Chat UI interactions: no external transport,
no webhook, no websocket — the caller submits a ChatUiRequest programmatically and
receives the agent reply reactively.
Suitable for:
- Embedded web chat UIs that send HTTP requests to the harness
- CLI tools and integration tests that need a typed API to the agent
- Single-agent single-session scenarios where the default
DmScope.MAINcollapses all conversations into one session
Obtaining an instance
The recommended way is throughGatewayBootstrap.chatUiChannel():
GatewayBootstrap gw = GatewayBootstrap.builder().model(model)
.agent("main", b -> b.name("assistant").sysPrompt("..."))
.build();
ChatUiChannel chat = gw.chatUiChannel();
chat.send("Hello!").block();
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanapplyRoutingConfig(ChannelConfig newConfig) Applies a new routingChannelConfig(bindings, dmScope, defaultAgentId) without tearing down the channel's transport.Logical identifier for this channel (e.g.config()Returns the routing configuration for this channel.static ChatUiChannelcreate()Creates a Chat UI channel with the defaultDmScope.MAINconfig.static ChatUiChannelcreate(ChannelConfig config) Creates a Chat UI channel with an explicit config.static ChatUiChannelCreates a Chat UI channel with a pre-wired gateway.static ChatUiChannelcreate(Gateway gateway, ChannelConfig config) Creates a Chat UI channel with a pre-wired gateway and explicit config.voiddeliver(OutboundAddress address, List<io.agentscope.core.message.Msg> messages) Delivers proactive outbound messages (e.g. subagent completion announces) to this channel's transport.reactor.core.publisher.Mono<io.agentscope.core.message.Msg> dispatch(InboundMessage message) Dispatches a fully constructedInboundMessagethrough routing and returns the agent reply.reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> dispatchStream(InboundMessage message) Streaming variant ofChannel.dispatch(InboundMessage).voidCalled by the gateway bootstrap beforeChannel.start()to supply the auto-wiredGateway.intReturns the number of buffered proactive outbound messages.static ChatUiChannelperPeer()Creates a per-peer Chat UI channel.Drains and returns all buffered proactive outbound messages.previewRoute(InboundMessage message) Returns theRouteResultthis channel would produce formessagewithout dispatching it.reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(ChatUiRequest request) Sends a structuredChatUiRequestand returns the agent reply reactively.reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(SendOptions options, String text) Sends a plain-text message with explicit routing identity.reactor.core.publisher.Mono<io.agentscope.core.message.Msg> Sends a plain-text message in single-session mode (no peer id).reactor.core.publisher.Mono<io.agentscope.core.message.Msg> Sends a plain-text message from a specific peer.reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(ChatUiRequest request) Streaming variant ofsend(ChatUiRequest).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(SendOptions options, String text) Streaming variant ofsend(SendOptions, String).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(String text) Streaming variant ofsend(String).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(String peerId, String text) Streaming variant ofsend(String, String).reactor.core.publisher.Mono<io.agentscope.core.message.Msg> sendToSubagent(String subagentId, String text) Sends a message directly to an exposed subagent, bypassing normal routing.reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendToSubagentStream(String subagentId, String text) Streaming variant ofsendToSubagent(String, String).voidstart()Connects to the external event source and starts dispatching inbound messages.voidstop()Disconnects from the external event source and releases resources.
-
Field Details
-
CHANNEL_ID
- See Also:
-
-
Method Details
-
create
Creates a Chat UI channel with the defaultDmScope.MAINconfig. -
create
Creates a Chat UI channel with an explicit config. -
perPeer
Creates a per-peer Chat UI channel. Each distinct peerId gets its own session. -
create
Creates a Chat UI channel with a pre-wired gateway. -
create
Creates a Chat UI channel with a pre-wired gateway and explicit config. -
init
Description copied from interface:ChannelCalled by the gateway bootstrap beforeChannel.start()to supply the auto-wiredGateway. Implementations that need a gateway but do not receive it at construction time should override this method. The default is a no-op. -
start
public void start()Description copied from interface:ChannelConnects to the external event source and starts dispatching inbound messages. Programmatic channels may make this a no-op. -
stop
public void stop()Description copied from interface:ChannelDisconnects from the external event source and releases resources. Programmatic channels may make this a no-op. -
channelId
Description copied from interface:ChannelLogical identifier for this channel (e.g."chatui","slack","discord"). Must matchChannelConfig.channelId(). -
config
Description copied from interface:ChannelReturns the routing configuration for this channel. -
applyRoutingConfig
Description copied from interface:ChannelApplies a new routingChannelConfig(bindings, dmScope, defaultAgentId) without tearing down the channel's transport. Implementations that hold theirChannel.config()in a mutable / volatile reference can override this to support hot reload of bindings.The default implementation returns
falseto signal that this channel does not support live config swap. Returningtruemeans the swap was applied and subsequent inbound messages will route under the new config.- Specified by:
applyRoutingConfigin interfaceChannel- Parameters:
newConfig- the new routing configuration to install (channelId must matchChannel.channelId())- Returns:
trueif the config was applied live;falseif the channel requires a restart to pick up the new config
-
dispatch
Description copied from interface:ChannelDispatches a fully constructedInboundMessagethrough routing and returns the agent reply. The channel implementation is responsible for:- Calling
ChannelRouter.resolveRoute(io.agentscope.harness.agent.gateway.channel.ChannelConfig, io.agentscope.harness.agent.gateway.channel.InboundMessage)to obtain aRouteResult(which includes theOutboundAddressfor reply routing) - Passing the
RouteResult.context(), messages, andRouteResult.outboundAddress()toGateway.run(io.agentscope.harness.agent.gateway.MsgContext, java.util.List<io.agentscope.core.message.Msg>)
- Calling
-
previewRoute
Returns theRouteResultthis channel would produce formessagewithout dispatching it. Useful for pre-computing the session key before sending. -
deliver
Description copied from interface:ChannelDelivers proactive outbound messages (e.g. subagent completion announces) to this channel's transport. Called by the gateway when an agent produces a reply that needs to be pushed to the originating channel/peer rather than returned synchronously.The default implementation is a no-op, suitable for pull-based channels that do not support proactive push.
-
pollOutbound
Drains and returns all buffered proactive outbound messages. Returns an empty list if no messages are pending. -
outboundQueueSize
public int outboundQueueSize()Returns the number of buffered proactive outbound messages. -
send
Sends a plain-text message in single-session mode (no peer id). -
send
Sends a plain-text message from a specific peer. -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(SendOptions options, String text) Sends a plain-text message with explicit routing identity. TheSendOptionsdetermines the user identity and session key directly — noDmScopeconfiguration required.- See Also:
-
sendToSubagent
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> sendToSubagent(String subagentId, String text) Sends a message directly to an exposed subagent, bypassing normal routing. -
send
Sends a structuredChatUiRequestand returns the agent reply reactively. -
dispatchStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> dispatchStream(InboundMessage message) Description copied from interface:ChannelStreaming variant ofChannel.dispatch(InboundMessage). Returns fine-grainedAgentEvents instead of a single reply.The default delegates to
Gateway.runStream(io.agentscope.harness.agent.gateway.MsgContext, java.util.List<io.agentscope.core.message.Msg>)with the resolved route.- Specified by:
dispatchStreamin interfaceChannel
-
sendStream
Streaming variant ofsend(String). Returns fine-grainedAgentEvents. -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(String peerId, String text) Streaming variant ofsend(String, String). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(SendOptions options, String text) Streaming variant ofsend(SendOptions, String). -
sendToSubagentStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendToSubagentStream(String subagentId, String text) Streaming variant ofsendToSubagent(String, String). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(ChatUiRequest request) Streaming variant ofsend(ChatUiRequest).
-