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

    • params: INavigateToAgentParams

      Configuration parameters for the navigation handler.

      Configuration parameters for creating a navigation handler to a specific agent. Defines optional messages or functions to handle flush, emission, execution, and tool output scenarios during navigation, incorporating the last user message where applicable.

      INavigateToAgentParams

      • OptionalemitMessage?:
            | string
            | (
                clientId: string,
                lastMessage: string,
                lastAgent: string,
                agentName: string,
            ) => string | Promise<string>

        Optional message or function to emit when navigation occurs without execution. If a function, it receives the client ID, last user message, and agent name, returning a string or promise of a string.

      • OptionalexecuteMessage?:
            | string
            | (
                clientId: string,
                lastMessage: string,
                lastAgent: string,
                agentName: string,
            ) => string | Promise<string>

        Optional message or function to execute when navigation occurs with execution. If a function, it receives the client ID, last user message, and agent name, returning a string or promise of a string.

      • OptionalflushMessage?: string | (clientId: string, defaultAgent: string) => string | Promise<string>

        Optional message or function to emit after flushing the session. If a function, it receives the client ID and agent name, returning a string or promise of a string. Defaults to a generic retry message.

      • OptionaltoolOutput?: string | (clientId: string, agentName: string) => string | Promise<string>

        Optional message or function for tool output when navigation occurs. If a function, it receives the client ID and agent name, returning a string or promise of a string. Defaults to a message indicating successful navigation.

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

    A promise resolving to a function that handles navigation to the specified agent.