Function createNavigateToTriageAgent

Creates a function to navigate to a triage agent for a specific client, handling navigation, message execution, and tool output. The factory generates a handler that checks navigation state, commits tool outputs with accept/reject messages, and triggers execution or emission based on provided parameters. It operates outside any existing method or execution contexts to ensure isolation, leveraging beginContext for a clean execution scope. Logs the navigation operation if logging is enabled in the global configuration.

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

// Create a navigation handler with a static flush message
const navigate = await createNavigateToTriageAgent({
flushMessage: "Session reset for triage.",
toolOutputAccept: "Navigation completed.",
});
await navigate("tool-123", "client-456");
// Navigates to default agent, commits custom tool output, and emits the flush message if applicable.
// Create a navigation handler with dynamic messages
const navigate = await createNavigateToTriageAgent({
executeMessage: (clientId, agent) => `Processing ${clientId} on ${agent}`,
toolOutputReject: (clientId, agent) => `No navigation needed for ${clientId}`,
});
await navigate("tool-789", "client-012");
// Commits dynamic reject message and executes the message if already on the default agent.
  • Parameters

    • params: INavigateToTriageParams

      Configuration parameters for the navigation handler.

      Configuration parameters for creating a navigation handler to a triage agent. Defines optional messages or functions to handle flush, execution, and tool output scenarios during navigation.

      INavigateToTriageParams

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

        Optional message or function to execute when no navigation is needed. If a function, it receives the client ID and default 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 default agent name, returning a string or promise of a string.

      • OptionallastMessage?: (
            clientId: string,
            lastMessage: string,
            lastAgent: string,
            defaultAgent: string,
        ) => string | Promise<string>
      • OptionaltoolOutputAccept?: string | (clientId: string, defaultAgent: string) => string | Promise<string>

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

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

        Optional message or function for tool output when already on the default agent. If a function, it receives the client ID and default agent name, returning a string or promise of a string. Defaults to a message indicating no navigation was needed.

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

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