Skip to main content

Function: customCondition()

customCondition(predicate): StopCondition

Defined in: packages/core/src/utils/stop-conditions.ts:229

Create a custom stop condition from a predicate function

Parameters

predicate

(ctx) => boolean

Function that returns true to stop

Returns

StopCondition

StopCondition wrapping the predicate

Example

const bot = new Baleybot({
stopWhen: custom(ctx => {
// Stop if the last message contains "DONE"
const lastMsg = ctx.messages[ctx.messages.length - 1];
return lastMsg?.content?.includes('DONE') ?? false;
}),
});