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.