Function createNavigateToAgent

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.

If neither emitMessage nor executeMessage is provided, or if any internal operation (e.g., navigation, commit, or execution) fails.

// Create a navigation handler with static messages
const navigate = await createNavigateToAgent({
flushMessage: "Session reset.",
toolOutput: "Navigation completed.",
emitMessage: "Navigation event triggered.",
});
await navigate("tool-123", "client-456", "WeatherAgent");
// Navigates to WeatherAgent, commits tool output, and emits the message.
// Create a navigation handler with dynamic messages
const navigate = await createNavigateToAgent({
executeMessage: (clientId, lastMessage, agent) => `Processing ${lastMessage} for ${clientId} on ${agent}`,
toolOutput: (clientId, agent) => `Navigated ${clientId} to ${agent}`,
});
await navigate("tool-789", "client-012", "SupportAgent");
// Navigates to SupportAgent, commits dynamic tool output, and executes the message with the last user message.
  • Parameters

    Returns (toolId: string, clientId: string, agentName: string) => Promise<void>