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(io.agentscope.core.message.Msg message) Sends a pre-builtMsg(text or multimodal) in single-session mode.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, io.agentscope.core.message.Msg message) Sends a pre-builtMsgwith explicit routing identity.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>send(SendOptions options, List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs 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 pre-builtMsgfrom a specific peer.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>Sends a plain-text message from a specific peer.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>Sends one or more pre-builtMsgs from a specific peer.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>Sends one or more pre-builtMsgs in single-session mode.reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendStream(io.agentscope.core.message.Msg message) Streaming variant ofsend(Msg).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, io.agentscope.core.message.Msg message) Streaming variant ofsend(SendOptions, Msg).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(SendOptions options, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(SendOptions, List).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, io.agentscope.core.message.Msg message) Streaming variant ofsend(String, Msg).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendStream(String peerId, String text) Streaming variant ofsend(String, String).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendStream(String peerId, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(String, List).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendStream(List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(List).reactor.core.publisher.Mono<io.agentscope.core.message.Msg>sendToSubagent(String subagentId, io.agentscope.core.message.Msg message) Sends a pre-builtMsgdirectly to an exposed subagent.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.Mono<io.agentscope.core.message.Msg>sendToSubagent(String subagentId, List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs directly to an exposed subagent.reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendToSubagentStream(String subagentId, io.agentscope.core.message.Msg message) Streaming variant ofsendToSubagent(String, Msg).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendToSubagentStream(String subagentId, String text) Streaming variant ofsendToSubagent(String, String).reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>sendToSubagentStream(String subagentId, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsendToSubagent(String, List).voidstart()Connects to the external event source and starts dispatching inbound messages.voidstop()Disconnects from the external event source and releases resources.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.harness.agent.gateway.channel.Channel
deliverWithReceipt
-
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
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(io.agentscope.core.message.Msg message) Sends a pre-builtMsg(text or multimodal) in single-session mode.Msg multimodal = Msg.builder() .role(MsgRole.USER) .content( TextBlock.builder().text("Describe this").build(), ImageBlock.builder() .source(URLSource.builder().url(imageUrl).build()) .build()) .build(); chat.send(multimodal).block(); -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs in single-session mode. Use this for multimodal content or multi-part user turns. -
send
Sends a plain-text message from a specific peer. -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(String peerId, io.agentscope.core.message.Msg message) Sends a pre-builtMsgfrom a specific peer. -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(String peerId, List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs 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. -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(SendOptions options, io.agentscope.core.message.Msg message) Sends a pre-builtMsgwith explicit routing identity. Prefer this overload for multimodal content (images, audio, …) while still usingSendOptionsfor session routing. -
send
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> send(SendOptions options, List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs with explicit routing identity. Useful for multimodal or multi-part user turns. -
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. -
sendToSubagent
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> sendToSubagent(String subagentId, io.agentscope.core.message.Msg message) Sends a pre-builtMsgdirectly to an exposed subagent. -
sendToSubagent
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> sendToSubagent(String subagentId, List<io.agentscope.core.message.Msg> messages) Sends one or more pre-builtMsgs directly to an exposed subagent. -
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(io.agentscope.core.message.Msg message) Streaming variant ofsend(Msg). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(List). -
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(String peerId, io.agentscope.core.message.Msg message) Streaming variant ofsend(String, Msg). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(String peerId, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(String, List). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(SendOptions options, String text) Streaming variant ofsend(SendOptions, String). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(SendOptions options, io.agentscope.core.message.Msg message) Streaming variant ofsend(SendOptions, Msg). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(SendOptions options, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsend(SendOptions, List). -
sendToSubagentStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendToSubagentStream(String subagentId, String text) Streaming variant ofsendToSubagent(String, String). -
sendToSubagentStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendToSubagentStream(String subagentId, io.agentscope.core.message.Msg message) Streaming variant ofsendToSubagent(String, Msg). -
sendToSubagentStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendToSubagentStream(String subagentId, List<io.agentscope.core.message.Msg> messages) Streaming variant ofsendToSubagent(String, List). -
sendStream
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> sendStream(ChatUiRequest request) Streaming variant ofsend(ChatUiRequest).
-