Creates a function to navigate to a specified agent for a given client, handling navigation, message execution, emission, and tool output.
The factory generates a handler that checks navigation state, retrieves the last user message, commits tool outputs, and triggers execution or emission based on provided parameters.
It validates the presence of either emitMessage or executeMessage to ensure proper navigation behavior.
Logs the navigation operation if logging is enabled in the global configuration.
Throws
If neither emitMessage nor executeMessage is provided, or if any internal operation (e.g., navigation, commit, or execution) fails.
Example
// Create a navigation handler with static messages constnavigate = awaitcreateNavigateToAgent({ flushMessage:"Session reset.", toolOutput:"Navigation completed.", emitMessage:"Navigation event triggered.", }); awaitnavigate("tool-123", "client-456", "WeatherAgent"); // Navigates to WeatherAgent, commits tool output, and emits the message.
Example
// Create a navigation handler with dynamic messages constnavigate = awaitcreateNavigateToAgent({ executeMessage: (clientId, lastMessage, agent) =>`Processing ${lastMessage} for ${clientId} on ${agent}`, toolOutput: (clientId, agent) =>`Navigated ${clientId} to ${agent}`, }); awaitnavigate("tool-789", "client-012", "SupportAgent"); // Navigates to SupportAgent, commits dynamic tool output, and executes the message with the last user message.
Creates a function to navigate to a specified agent for a given client, handling navigation, message execution, emission, and tool output. The factory generates a handler that checks navigation state, retrieves the last user message, commits tool outputs, and triggers execution or emission based on provided parameters. It validates the presence of either
emitMessageorexecuteMessageto ensure proper navigation behavior. Logs the navigation operation if logging is enabled in the global configuration.Throws
If neither
emitMessagenorexecuteMessageis provided, or if any internal operation (e.g., navigation, commit, or execution) fails.Example
Example