Package dev.agenor.tools.agents
Class MessageSnifferAgent
java.lang.Object
dev.agenor.runtime.agent.BaseAgent
dev.agenor.tools.agents.MessageSnifferAgent
- All Implemented Interfaces:
Agent,LifecycleHooks
System agent that captures and stores messages for monitoring purposes.
The sniffer subscribes to messages matching a configurable filter and stores them in a ring buffer for later retrieval via CLI or WebConsole.
For live streaming via WebSocket, set a ConsoleEventListener:
sniffer.setEventListener(console.getWebSocketHandler());
Usage:
// Capture all messages
var sniffer = new MessageSnifferAgent();
runtime.registerAgent(sniffer);
// Capture only order-related messages
var filter = TopicFilter.startsWith("order.");
var sniffer = new MessageSnifferAgent(filter, 1000);
runtime.registerAgent(sniffer);
// Query captured messages
List<StoredMessage> recent = sniffer.getRecent(50);
List<StoredMessage> orders = sniffer.findByTopic("order.*");
- Since:
- 0.4.0
-
Field Summary
FieldsFields inherited from class dev.agenor.runtime.agent.BaseAgent
agentDescriptor, agentDirectory, behaviorScheduler, log, memoryStore -
Constructor Summary
ConstructorsConstructorDescriptionCreates a sniffer that captures all messages with default history size.MessageSnifferAgent(int historySize) Creates a sniffer with custom history size, capturing all messages.MessageSnifferAgent(MessageFilter filter) Creates a sniffer with custom filter and default history size.MessageSnifferAgent(MessageFilter filter, int historySize) Creates a sniffer with custom filter and history size.MessageSnifferAgent(MessageFilter filter, MessageHistoryService history) Creates a sniffer with external history service. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all stored messages.findByConversation(String conversationId) Gets one conversation's messages, oldest first.findBySender(String senderId) Finds messages by sender.findByTopic(String topicPattern) Finds messages by topic pattern.Lists the conversations captured so far, with each one's message count.Gets the current event listener.Gets the active filter.Gets the underlying history service.intGets the current message count.getRecent(int count) Gets the most recent messages.booleanChecks if sniffer is actively capturing.protected voidonStart()Lifecycle hook called when agent startsprotected voidonStop()Lifecycle hook called when agent stopsvoidsetEventListener(ConsoleEventListener eventListener) Sets the event listener for WebSocket notifications.Methods inherited from class dev.agenor.runtime.agent.BaseAgent
addBehavior, clearMemory, clearStartHooks, clearStopHooks, createMailbox, forget, getAgentId, getAgentName, getBehaviors, getMemoryStats, getMessageDispatcher, getStatus, getTelemetry, handleDirectMessage, initializeServices, isRunning, mailbox, mailboxConfig, onDirectMessage, onStartHook, onStopHook, recall, recallShared, registerDirectTopicHandler, registerTopicSubscription, rememberLong, rememberLong, rememberShort, rememberShort, removeBehavior, removeStartHook, removeStopHook, replyTo, requestFrom, requestFrom, searchMemory, searchMemory, sendTo, setAgentDescriptor, setAgentDirectory, setBehaviorScheduler, setMemoryStore, setMessageDispatcher, setTelemetry, shareMemory, start, stop
-
Field Details
-
AGENT_ID
- See Also:
-
AGENT_NAME
- See Also:
-
DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_SIZE- See Also:
-
-
Constructor Details
-
MessageSnifferAgent
public MessageSnifferAgent()Creates a sniffer that captures all messages with default history size. -
MessageSnifferAgent
public MessageSnifferAgent(int historySize) Creates a sniffer with custom history size, capturing all messages.- Parameters:
historySize- max messages to retain
-
MessageSnifferAgent
Creates a sniffer with custom filter and default history size.- Parameters:
filter- message filter to apply
-
MessageSnifferAgent
Creates a sniffer with custom filter and history size.- Parameters:
filter- message filter to applyhistorySize- max messages to retain
-
MessageSnifferAgent
Creates a sniffer with external history service.Use this when sharing history with WebConsole.
- Parameters:
filter- message filter to applyhistory- external history service
-
-
Method Details
-
onStart
protected void onStart()Description copied from class:BaseAgentLifecycle hook called when agent starts -
onStop
protected void onStop()Description copied from class:BaseAgentLifecycle hook called when agent stops -
setEventListener
Sets the event listener for WebSocket notifications.When set, the sniffer will notify the listener for each captured message, enabling live streaming via WebSocket.
- Parameters:
eventListener- the listener, or null to disable notifications
-
getEventListener
Gets the current event listener. -
getHistory
Gets the underlying history service. -
getRecent
Gets the most recent messages.- Parameters:
count- max messages to return- Returns:
- list of stored messages, newest first
-
findByTopic
Finds messages by topic pattern.- Parameters:
topicPattern- wildcard pattern (e.g., "order.*")- Returns:
- matching messages
-
findBySender
Finds messages by sender.- Parameters:
senderId- the sender agent ID- Returns:
- messages from this sender
-
findByConversation
Gets one conversation's messages, oldest first.- Parameters:
conversationId- the conversation to collect- Returns:
- the conversation, in the order it happened
- Since:
- 0.31.0
-
getConversations
Lists the conversations captured so far, with each one's message count.- Returns:
- conversation id to message count, most recently active first
- Since:
- 0.31.0
-
getMessageCount
public int getMessageCount()Gets the current message count. -
clear
public void clear()Clears all stored messages. -
getFilter
Gets the active filter. -
isCapturing
public boolean isCapturing()Checks if sniffer is actively capturing.
-