Skip to main content

Function: route()

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

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

Create a multi-way routing step: the classifier's routeField picks the route. A value that names no route falls back to defaultRoute, else throws.

Type Parameters​

TInput​

TInput

TOutput​

TOutput

Parameters​

config​

RouteConfig<TInput, TOutput>

Returns​

Processable<TInput, TOutput>

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
})
);