Skip to main content

Class: Pipeline

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:69

A compiled DSL pipeline that can be executed multiple times.

Pipeline implements the Processable interface, allowing it to be composed with other Baleybots primitives (chains, parallels, etc.).

Examples​

Basic usage

const pipeline = Pipeline.from(`
writer { "goal": "Write a haiku about the input" }
`);
const result = await pipeline.process('mountains');

With streaming

const result = await pipeline.process(input, {
onToken: (botName, event) => {
if (event.type === 'text_delta') {
process.stdout.write(event.content);
}
}
});

With custom tools

const pipeline = Pipeline.from(code, {
availableTools: { myTool: myCustomTool }
});

Implements​

  • Processable<unknown, unknown>

Methods​

describe()​

describe(): ProcessableStructure

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:129

Delegate to the compiled executable.

A Pipeline is a handle on whatever the DSL compiled to, not a node in its own right — reporting the executable as a child would show a wrapper the developer never wrote, one level above the constructs they did.

Returns​

ProcessableStructure

Implementation of​

Processable.describe


getEntityNames()​

getEntityNames(): string[]

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:137

The entity names the DSL code defines, whether or not its composition uses each one.

Returns​

string[]


getId()​

getId(): string

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:114

This instance's id, unique within the process for its lifetime and different after a restart.

Returns​

string

Example​

const bot1 = Baleybot.create({ name: 'analyzer' });
const bot2 = Baleybot.create({ name: 'analyzer' });

bot1.getId(); // 'baleybot-1-a3f891'
bot2.getId(); // 'baleybot-2-b4c2d3'

// Same semantic name, different IDs
bot1.getName(); // 'analyzer'
bot2.getName(); // 'analyzer'

Implementation of​

Processable.getId


getName()​

getName(): string

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:118

What this processable is called. A label, not a key.

Stable across runs, which getId() is not — an id embeds a timestamp and changes on every restart. That is what makes a name safe to print in a log, show on a node, or hand to a merge function.

Not unique. Two bots may both be called 'analyzer', and every unnamed loop() reports 'loop'. Anything that must address exactly one instance uses getId(), or an address — never this.

Never returns an empty string: where no name was configured, the primitive reports its kind.

Returns​

string

Implementation of​

Processable.getName


getRunInput()​

getRunInput(): string | null

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:147

The input of the DSL's run("...") statement, or null.

Returns​

string | null


getStructure()​

getStructure(): PipelineStructure | null

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:142

Serializable pipeline topology, for visualization.

Returns​

PipelineStructure | null


process()​

process(input, options?): Promise<unknown>

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:109

Execute the pipeline with the given input.

If the DSL code includes a run("...") statement, that input will be used. Otherwise, the provided input parameter is used.

Parameters​

input​

unknown

Input to process (ignored if DSL has run statement)

options?​

ProcessOptions

Returns​

Promise<unknown>

Implementation of​

Processable.process


subscribeToAll()​

subscribeToAll(options?): Subscription

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:151

Subscribe to categorized events from this processable and all nested processables:

  • onStreamEvent: Real-time content streaming (text_delta, structured_output_delta, tool_call_arguments_delta)
  • onProgressUpdate: Status updates (tool_execution_start, tool_call_stream_start, tool_call_stream_complete, reasoning)
  • onComplete: Emitted when each bot finishes processing with final output
  • onError: Error events (error, tool_validation_error)

Callbacks receive both bot ID and name for precise identification:

  • botId: Unique instance identifier (e.g., 'baleybot-1-a3f891')
  • botName: Semantic name (e.g., 'analyzer', 'router', 'processor')

Callbacks run synchronously inside the run they observe. A callback that throws fails that run with its error once every subscriber has heard the notification (see leafEvents).

Parameters​

options?​
omit?​

string[]

onComplete?​

(botId, botName, output) => void

onError?​

(botId, botName, event) => void

onProgressUpdate?​

(botId, botName, event) => void

onStreamEvent?​

(botId, botName, event) => void

Returns​

Subscription

Examples​

Subscribe to all events

const subscription = pipeline.subscribeToAll({
onStreamEvent(botId, botName, event) {
if (event.type === 'text_delta') {
console.log(`[${botId}] ${botName}:`, event.content);
}
},
onProgressUpdate(botId, botName, event) {
if (event.type === 'tool_execution_start') {
console.log(`${botName} (${botId}) executing ${event.toolName}`);
}
},
onComplete(botId, botName, output) {
console.log(`${botName} completed:`, output);
},
onError(botId, botName, event) {
console.error(`${botName} error:`, event);
}
});

await pipeline.process('input');
subscription.unsubscribe();

Filter specific bots by name or ID

const subscription = pipeline.subscribeToAll({
onStreamEvent(botId, botName, event) {
console.log(`${botName}:`, event);
},
omit: ['chat-step', 'processor-42-8a3f91'] // Filter by name or ID
});

Implementation of​

Processable.subscribeToAll


from()​

static from(code, config?): Pipeline

Defined in: packages/tools/src/baleybots-dsl-v2/pipeline.ts:95

Create a pipeline from DSL code.

Parameters​

code​

string

config?​

PipelineConfig

Returns​

Pipeline

Example​

const pipeline = Pipeline.from(`
sentiment { "goal": "Analyze sentiment" }
keywords { "goal": "Extract keywords" }
chain { sentiment keywords }
`);