Interface: ToolExecutionOptions
Defined in: packages/core/src/utils/tools.ts:60
Tool execution context (AI SDK v6 pattern)
Extended options passed to tool functions during execution. Includes the original ProcessOptions plus tool-specific context.
Example
const myTool = defineZodTool({
name: 'my_tool',
description: 'A tool with context',
inputSchema: z.object({ data: z.string() }),
execute: async (params, options) => {
console.log('Tool call ID:', options?.toolCallId);
console.log('Message history:', options?.messages?.length);
return { processed: params.data };
},
});
Extends
Properties
abortSignal?
optionalabortSignal?:AbortSignal
Defined in: packages/core/src/utils/tools.ts:66
Abort signal for cancellation
conversationHistory?
optionalconversationHistory?:object[]
Defined in: packages/core/src/types.ts:596
Conversation history for multi-turn conversations (uses OpenAI ChatMessage format from providers)
content
content:
string|MessageContentBlock[]
role
role:
"system"|"user"|"assistant"|"tool"
tool_call_id?
optionaltool_call_id?:string
tool_calls?
optionaltool_calls?:object[]
Inherited from
ProcessOptions.conversationHistory
enableCaching?
optionalenableCaching?:boolean
Defined in: packages/core/src/types.ts:477
Enable prompt caching for multi-agent pipelines. When true, each agent's system message gets cache control markers, allowing shared document context to be cached across parallel agent calls.
Especially beneficial for extraction pipelines where multiple agents process the same document simultaneously — cached reads cost only 10% (Anthropic) or 50% (OpenAI) of normal input price.
Inherited from
extraVars?
optionalextraVars?:Record<string,unknown>
Defined in: packages/core/src/types.ts:617
Extra variable bindings injected at process-time (used by BAL map/for iterators).
Inherited from
hooks?
optionalhooks?:ProcessHooks
Defined in: packages/core/src/types.ts:643
Per-step lifecycle hooks. Awaitable — the runner awaits each hook before proceeding, so persistence can land before the next step runs.
For single-step Processables (e.g. a lone Baleybot), hooks fire around the whole invocation. For multi-step Processables (pipeline, graph, ParallelMerge), they fire per step with the appropriate nodeId / nodeLabel.
Zero-cost when unset: the runner skips event construction entirely if hooks is absent AND no subscription is active.
See ProcessHooks in ./graph/types.ts for the full callback shape and
ordering contract.
Inherited from
hooksAreFatal?
optionalhooksAreFatal?:boolean
Defined in: packages/core/src/types.ts:650
If true, a throwing hook rejects the run. Default (false) logs the error and continues execution — observability should not be able to break a pipeline by accident.
Inherited from
maxTokens?
optionalmaxTokens?:number
Defined in: packages/core/src/types.ts:624
Override maxTokens for this call only. Takes precedence over construction-time maxTokens.
Inherited from
messages?
optionalmessages?:ChatMessage[]
Defined in: packages/core/src/utils/tools.ts:64
Current message history (for context-aware tools)
model?
optionalmodel?:string|ModelConfig
Defined in: packages/core/src/types.ts:620
Override the model for this call only. Takes precedence over construction-time model.
Inherited from
onApprovalRequired?
optionalonApprovalRequired?: (botName,toolCall,toolDefinition) =>Promise<ToolApprovalResult>
Defined in: packages/core/src/types.ts:590
Request approval for individual tool calls (v6 pattern)
Called when a tool has requiresApproval: true or returns true from
its requiresApproval function. This is called per-tool, not per-batch.
Parameters
botName
string
toolCall
toolDefinition
ZodToolDefinition<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>, unknown>
Returns
Promise<ToolApprovalResult>
Example
const bot = new Baleybot({
name: 'bot',
goal: 'Help with files',
tools: {
deleteFile: defineZodTool({
name: 'delete_file',
description: 'Delete a file',
inputSchema: z.object({ path: z.string() }),
requiresApproval: true, // Always require approval
execute: async ({ path }) => { ... },
}),
},
});
await bot.process('Delete temp.txt', {
onApprovalRequired: async (botName, toolCall, toolDef) => {
// Show approval UI
const approved = await showApprovalDialog(toolCall);
return approved
? { approved: true }
: { approved: false, reason: 'User cancelled' };
},
});
Inherited from
ProcessOptions.onApprovalRequired
onComplete?
optionalonComplete?: (botName,result) =>void
Defined in: packages/core/src/types.ts:555
Called when processing completes with final result
Note: You can also get the final result from process() return value.
This callback is provided for convenience when you need both streaming and completion notification.
Parameters
botName
string
result
unknown
Returns
void
Inherited from
onError?
optionalonError?: (botName,error) =>void
Defined in: packages/core/src/types.ts:556
Parameters
botName
string
error
Error
Returns
void
Inherited from
onStart?
optionalonStart?: (botName) =>void
Defined in: packages/core/src/types.ts:479
Parameters
botName
string
Returns
void
Inherited from
onToken?
optionalonToken?:TokenHandlers| ((botName,event) =>void)
Defined in: packages/core/src/types.ts:548
Streaming event handlers - receive events in real-time during execution
You can use BOTH streaming events AND final results together:
- Streaming events: Provide
onTokenhandlers to receive real-time updates via callbacks - Final result: Also available when
process()Promise resolves (see return value)
Accepts either:
- A callback function that receives all events
- An object with specific handlers for each event type (recommended for type safety)
Examples
// Stream events in real-time AND get final result
const result = await bot.process(input, {
onToken: {
// Real-time streaming events
onTextDelta(botName, event) {
process.stdout.write(event.content); // Stream as it generates
},
onToolExecutionStart(botName, event) {
console.log(`🔧 ${event.toolName} starting...`); // Real-time tool status
},
onToolExecutionOutput(botName, event) {
console.log(`✅ Tool result:`, event.result); // Final tool result event
},
onToolExecutionStream(botName, event) {
// Nested streaming from child bots
const nested = event.nestedEvent;
if (nested.type === 'text_delta') {
process.stdout.write(nested.content); // Child bot streaming
}
}
}
});
// Final result available when Promise resolves
console.log('Final response:', result); // Complete parsed response
await bot.process(input, {
onToken: (botName, event) => {
if (event.type === 'text_delta') {
process.stdout.write(event.content);
}
}
});
// Don't await or use return value if you only care about streaming
const result = await bot.process(input);
// No onToken = no streaming, just wait for final result
console.log('Response:', result);
onToken(botName, event) {
if (event.type === 'tool_execution_start') {
console.log(`Starting ${event.toolName}`);
}
}
Inherited from
signal?
optionalsignal?:AbortSignal
Defined in: packages/core/src/types.ts:466
AbortSignal to cancel the request
Inherited from
stopWhen?
optionalstopWhen?:StopCondition
Defined in: packages/core/src/types.ts:626
Override stopWhen for this call only. Takes precedence over construction-time stopWhen.
Inherited from
temperature?
optionaltemperature?:number
Defined in: packages/core/src/types.ts:622
Override temperature for this call only (0–2). Takes precedence over construction-time temperature.
Inherited from
toolCallId
toolCallId:
string
Defined in: packages/core/src/utils/tools.ts:62
Unique ID of this tool call
Overrides
verbose?
optionalverbose?:boolean
Defined in: packages/core/src/types.ts:463
Enable verbose logging for debugging