Package io.agentscope.harness.agent.bus
Interface MessageBus
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
WorkspaceMessageBus
Live message transport for coordinating work across sessions and processes.
Three consumption modes are exposed:
- Drain queue (Mode A) — single-consumer, ack-on-read. Each entry is returned at most once; storage drops it the moment it is read.
- Replay log (Mode C) — multi-consumer, externally bounded. Each reader tracks its own cursor; entries persist until trimmed or capped by maxLen.
- Transient broadcast (Mode D) — fire-and-forget pub/sub. Only currently-subscribed listeners receive a payload; no history is retained.
Domain helpers (inboxPush(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>), inboxDrain(java.lang.String, int), enqueueWakeup(java.lang.String, java.lang.String, java.lang.String)) map
higher-level concepts onto these primitives with a fixed key-naming convention.
Implementations:
WorkspaceMessageBus— single-process, no external dependencies
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Release underlying transport resources.default reactor.core.publisher.Mono<Void>enqueueWakeup(String sessionId, String agentId) Convenience overload without userId.default reactor.core.publisher.Mono<Void>enqueueWakeup(String userId, String sessionId, String agentId) Enqueue a wakeup request and signal dispatchers.inboxDrain(String sessionId, int maxCount) Drain pending inbox messages for a session.default reactor.core.publisher.Mono<Boolean>inboxHasMessages(String sessionId) Check whether a session's inbox has pending messages without consuming them.default reactor.core.publisher.Mono<Void>Push a message into a session's inbox queue.reactor.core.publisher.Mono<String>Append a payload to the replay log at the given key.Read up tomaxCountentries from the replay log, starting aftersince.reactor.core.publisher.Mono<Void>Delete the replay log at the given key and all of its entries.reactor.core.publisher.Mono<Void>Publish a payload on the broadcast channel.reactor.core.publisher.Mono<Void>queueDelete(String key) Delete the drain queue at the given key and all of its entries.queueDrain(String key, int maxCount) Drain up tomaxCountentries from the queue at the given key.reactor.core.publisher.Mono<Boolean>Check whether the drain queue at the given key has any entries, without consuming them.reactor.core.publisher.Mono<String>Append a payload to the drain queue at the given key.default reactor.core.publisher.Mono<String>sessionPublishEvent(String sessionId, Map<String, Object> event) Append a session event to the replay log and fan it out live.sessionReadEvents(String sessionId, String since, int maxCount) Read events from a session's replay log for catch-up / reconnection.sessionSubscribeEvents(String sessionId) Live-subscribe to a session's published events.default reactor.core.publisher.Mono<Void>sessionTrimEvents(String sessionId) Trim the session's event replay log.Subscribe to a broadcast channel.Subscribe to the shared wakeup signal channel.
-
Field Details
-
SESSION_EVENTS_KEY_PREFIX
- See Also:
-
SESSION_REPLAY_MAX_LEN
static final int SESSION_REPLAY_MAX_LEN- See Also:
-
-
Method Details
-
queuePush
Append a payload to the drain queue at the given key.- Parameters:
key- queue identifier (caller-defined naming convention)payload- JSON-serializable dict to enqueue- Returns:
- the transport-level entry id
-
queueDrain
Drain up tomaxCountentries from the queue at the given key. Returned entries are removed from the queue atomically. A subsequent call returns only entries that arrived after this one.- Parameters:
key- queue identifiermaxCount- maximum number of entries to return- Returns:
- entries in arrival order; empty list when the queue is empty
-
queueDelete
Delete the drain queue at the given key and all of its entries. Idempotent.- Parameters:
key- queue identifier
-
queuePeek
Check whether the drain queue at the given key has any entries, without consuming them.- Parameters:
key- queue identifier- Returns:
- true if the queue has at least one entry
-
inboxHasMessages
Check whether a session's inbox has pending messages without consuming them.- Parameters:
sessionId- the session to check- Returns:
- true if the inbox has at least one message
-
logAppend
Append a payload to the replay log at the given key. Readers track their own cursor; entries persist until trimmed or capped bymaxLen.- Parameters:
key- log identifierpayload- JSON-serializable dict to appendmaxLen- cap the log at approximately this many entries; older entries are trimmed when exceeded. Use0or negative for no cap.- Returns:
- the transport-level entry id (usable as a cursor for subsequent reads)
-
logRead
Read up tomaxCountentries from the replay log, starting aftersince. Non-destructive: the same entries can be returned to any number of readers.- Parameters:
key- log identifiersince- cursor — return entries strictly newer than this id.nullreads from the beginning.maxCount- maximum number of entries to return- Returns:
- entries in append order; empty list when no entries are newer than
since
-
logTrim
Delete the replay log at the given key and all of its entries. Idempotent.- Parameters:
key- log identifier
-
publish
Publish a payload on the broadcast channel. Only currently-subscribed listeners receive it.- Parameters:
key- channel identifierpayload- JSON-serializable dict
-
subscribe
Subscribe to a broadcast channel. Yields payloads published after subscription is established. The caller owns the subscription's lifetime — cancelling the Flux ends it.- Parameters:
key- channel identifier- Returns:
- stream of payloads
-
inboxPush
Push a message into a session's inbox queue.- Parameters:
sessionId- the recipient sessionmsg- JSON-serializable payload (typically a serialized HintBlock)
-
inboxDrain
Drain pending inbox messages for a session.- Parameters:
sessionId- the session whose inbox to drainmaxCount- maximum entries to drain- Returns:
- entries in arrival order
-
enqueueWakeup
default reactor.core.publisher.Mono<Void> enqueueWakeup(String userId, String sessionId, String agentId) Enqueue a wakeup request and signal dispatchers.- Parameters:
userId- the owning user id (for multi-user isolation)sessionId- the session to wakeagentId- the agent that owns the session
-
enqueueWakeup
Convenience overload without userId. Delegates to the three-parameter form with an empty userId. -
subscribeWakeup
Subscribe to the shared wakeup signal channel.- Returns:
- stream of signal payloads (each indicates "drain the wakeup queue now")
-
sessionPublishEvent
default reactor.core.publisher.Mono<String> sessionPublishEvent(String sessionId, Map<String, Object> event) Append a session event to the replay log and fan it out live. Late-joining subscribers can replay from the log; already-connected subscribers receive it immediately via pub/sub.- Parameters:
sessionId- the session this event belongs toevent- JSON-serializable event payload- Returns:
- the replay-log entry id
-
sessionReadEvents
default reactor.core.publisher.Mono<List<BusEntry>> sessionReadEvents(String sessionId, String since, int maxCount) Read events from a session's replay log for catch-up / reconnection.- Parameters:
sessionId- the session whose events to readsince- cursor — return entries strictly newer than this id;nullreads allmaxCount- maximum events to return- Returns:
- entries in append order
-
sessionSubscribeEvents
Live-subscribe to a session's published events. Yields only payloads delivered after the subscription is established.- Parameters:
sessionId- the session to subscribe to- Returns:
- stream of event payloads
-
sessionTrimEvents
Trim the session's event replay log. Called after a session run completes so late subscribers don't replay stale events from a previous run.- Parameters:
sessionId- the session whose event log to clear
-
close
default void close()Release underlying transport resources. Default is a no-op.- Specified by:
closein interfaceAutoCloseable
-