Class: CrewSession
Defined in: packages/orchestration/src/crew/crew-session.ts:22
Implements
Processable<string,string>
Constructors
Constructor
new CrewSession(
coordinator,notificationBus,orchestrator,config):CrewSession
Defined in: packages/orchestration/src/crew/crew-session.ts:37
Parameters
coordinator
Baleybot
notificationBus
NotificationBus
orchestrator
config
autoStop?
boolean | { afterMs?: number; }
See CrewConfig.autoStop.
proactiveIntervalMs
number
proactiveUpdates
boolean
snapshotIntervalMs?
number
See CrewConfig.snapshotIntervalMs.
Returns
CrewSession
Properties
events
readonlyevents:EventBus<CrewEventMap>
Defined in: packages/orchestration/src/crew/crew-session.ts:23
Accessors
isPaused
Get Signature
get isPaused():
boolean
Defined in: packages/orchestration/src/crew/crew-session.ts:127
Returns
boolean
status
Get Signature
get status():
CrewSessionStatus
Defined in: packages/orchestration/src/crew/crew-session.ts:131
Returns
Methods
close()
close():
Promise<void>
Defined in: packages/orchestration/src/crew/crew-session.ts:183
Clear the session's timers (proactive updates, auto-stop, the snapshot
throttle), which otherwise keep a Node process from exiting. Unlike
stop(), makes no model call, so it is safe on a teardown path.
Idempotent per the describe().close contract, and does not end the
session: send() still works afterwards, minus the unprompted updates.
The coordinator is left alone: it may be the caller's
(CrewConfig.coordinator), and whoever built it closes it.
Returns
Promise<void>
describe()
describe():
ProcessableStructure
Defined in: packages/orchestration/src/crew/crew-session.ts:165
Only the coordinator is a child. Workers are reached through the orchestrator at runtime: which ones run depends on what the coordinator delegates, so they are not fixed by the composition.
Returns
ProcessableStructure
Implementation of
Processable.describe
getId()
getId():
string
Defined in: packages/orchestration/src/crew/crew-session.ts:152
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/orchestration/src/crew/crew-session.ts:156
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
pause()
pause():
void
Defined in: packages/orchestration/src/crew/crew-session.ts:109
Pause the crew — stops the scheduler so no new tickets are dispatched. Active runs continue to completion. Call resume() to restart scheduling.
Returns
void
process()
process(
input,options?):Promise<string>
Defined in: packages/orchestration/src/crew/crew-session.ts:148
Run once and resolve to the final output. Events stream to
options.onToken while it runs; see ProcessOptions.onToken.
Parameters
input
string
options?
ProcessOptions
Returns
Promise<string>
Implementation of
Processable.process
resume()
resume():
void
Defined in: packages/orchestration/src/crew/crew-session.ts:120
Resume a paused crew — restarts the scheduler which picks up queued tickets and dispatches them.
Returns
void
send()
send(
message,options?):Promise<string>
Defined in: packages/orchestration/src/crew/crew-session.ts:70
Send a message to the coordinator. Worker completion/failure notifications are automatically injected as context.
Parameters
message
string
options?
ProcessOptions
Returns
Promise<string>
snapshot()
snapshot():
CrewSnapshot
Defined in: packages/orchestration/src/crew/crew-session.ts:135
Returns
stop()
stop(
options?):Promise<CrewResult>
Defined in: packages/orchestration/src/crew/crew-session.ts:144
End the session: cancel active runs, take the coordinator's closing
summary (or use summary, which skips that model call), then emit the
last crew.snapshot and crew.done. Throws if the session already ended.
Parameters
options?
summary?
string
Returns
Promise<CrewResult>
subscribeToAll()
subscribeToAll(
_options?):object
Defined in: packages/orchestration/src/crew/crew-session.ts:191
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?
onComplete?
(botId, botName, output) => void
onError?
(botId, botName, event) => void
onStreamEvent?
(botId, botName, event) => void
Returns
object
unsubscribe
unsubscribe: () =>
void
Returns
void
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