Function: route()
route<
TInput,TOutput>(config):RouteStep<TInput,TOutput>
Defined in: packages/core/src/pipeline/helpers.ts:421
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
RouteStep<TInput, TOutput>
RouteStep object for use in pipelines
Example
const contentClassifier = Baleybot.create({
name: 'contentClassifier',
model: openai('gpt-4o-mini'),
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
})
);