Skip to main content

Function: route()

route<TInput, TOutput>(config): Processable<TInput, TOutput>

Defined in: packages/core/src/pipeline/branches.ts:170

Create a multi-way routing step based on AI classification. Classifier bot determines which route to take.

Type Parameters

TInput

TInput

Input type for classifier and routes

TOutput

TOutput

Output type from route processors

Parameters

config

RouteConfig<TInput, TOutput>

Configuration object with classifier, routes, and routing options

Returns

Processable<TInput, TOutput>

Processable that routes by classifier output

Example

const contentClassifier = Baleybot.create({
name: 'contentClassifier',
model: openai('gpt-5.6-luna'),
goal: 'Classify the type of blog post',
output: Output.object({ schema: z.object({
type: z.enum(['article', 'tutorial', 'review', 'news', 'other']),
confidence: z.number()
}) })
});

const processContent = pipeline(
loadPost,
route({
classifier: contentClassifier,
routes: {
article: processArticle,
tutorial: processTutorial,
review: processReview,
news: processNews,
other: processDefault
},
routeField: 'type',
defaultRoute: 'other'
}),
savePost
);

// Pass classifier output to route
const intelligentRouter = pipeline(
analyzeInput,
route({
classifier: determineStrategy,
routes: {
fast: quickProcess,
thorough: deepProcess,
custom: customProcess
},
routeField: 'strategy',
passClassifierOutput: true // Route receives classifier output instead of original input
})
);