Interface: ToolExecutionOptions
Defined in: packages/core/src/utils/tools.ts:55
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:61
Abort signal for cancellation
activeTools?
optionalactiveTools?: readonlystring[]
Defined in: packages/core/src/types.ts:664
Override AI SDK activeTools for this call only (restrict callable tools). Thin passthrough.
Inherited from
approvalResponses?
optionalapprovalResponses?:object[]
Defined in: packages/core/src/types.ts:627
Resume a paused tool-approval turn (resumable approvals).
When a gated tool (requiresApproval) is reached without an in-process
onApprovalRequired handler, the loop pauses and emits a
tool_approval_request event carrying an approvalId. Collect the user's
decision out-of-band, then call process() again with the same input plus
these responses — each is threaded straight into AI SDK's native
approval-response message so the loop continues where it left off.
The prior turn's messages (the assistant turn containing the approval
request) must be supplied via conversationHistory or keepHistory.
approvalId
approvalId:
string
approved
approved:
boolean
reason?
optionalreason?:string
Example
await bot.process('Delete temp.txt', {
conversationHistory: priorMessages,
approvalResponses: [{ approvalId, approved: true }],
});
Inherited from
ProcessOptions.approvalResponses
cacheControl?
optionalcacheControl?:boolean
Defined in: packages/core/src/types.ts:674
Override prompt-cache-control for this call only. Takes precedence over construction-time model.cacheControl and the enableCaching shorthand above.
Inherited from
conversationHistory?
optionalconversationHistory?:object[]
Defined in: packages/core/src/types.ts:629
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:488
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:650
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:696
Per-step lifecycle hooks. Awaitable — the runner awaits each hook before proceeding, so persistence can land before the next step runs.
Currently only honored by graph()-built Processables, which fire
hooks per node with that node's nodeId/nodeLabel. A lone Baleybot
or a pipeline() chain does not read this option — step-boundary
semantics (what counts as "a step", what NodeContext means) don't
generalize cleanly to a single-step invocation or a plain sequential
chain, so this stays graph-scoped rather than half-implemented
elsewhere. Use subscribeToAll() (universally supported) for
cross-Processable event observation instead.
onStepEvent rides on the same categorized subscribeToAll contract
every Processable implements — there is no separate event-emission
path, just this graph-specific ordering/batching layer on top of it.
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:703
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:657
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:59
Current message history (for context-aware tools)
model?
optionalmodel?:string|ModelConfig
Defined in: packages/core/src/types.ts:653
Override the model for this call only. Takes precedence over construction-time model. Independent of providerOptions/cacheControl below — overriding the model no longer drops them.
Inherited from
onApprovalRequired?
optionalonApprovalRequired?: (botName,toolCall,toolDefinition) =>Promise<ToolApprovalResult>
Defined in: packages/core/src/types.ts:601
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:566
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:567
Parameters
botName
string
error
Error
Returns
void
Inherited from
onStart?
optionalonStart?: (botName) =>void
Defined in: packages/core/src/types.ts:490
Parameters
botName
string
Returns
void
Inherited from
onStepEnd?
optionalonStepEnd?:GenerateTextOnStepEndCallback<ToolSet,Context>
Defined in: packages/core/src/types.ts:668
Override AI SDK onStepEnd for this call only. Thin passthrough.
Inherited from
onToken?
optionalonToken?:TokenHandlers| ((botName,event) =>void)
Defined in: packages/core/src/types.ts:559
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
Using both streaming AND final result (recommended)
// 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
Streaming-only (ignore final result)
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
Final-only (ignore streaming)
const result = await bot.process(input);
// No onToken = no streaming, just wait for final result
console.log('Response:', result);
Function approach
onToken(botName, event) {
if (event.type === 'tool_execution_start') {
console.log(`Starting ${event.toolName}`);
}
}
Inherited from
providerOptions?
optionalproviderOptions?:Record<string,Record<string,unknown>>
Defined in: packages/core/src/types.ts:661
Override provider-specific options for this call only. Takes precedence over construction-time model.config.providerOptions.
Inherited from
ProcessOptions.providerOptions
repairToolCall?
optionalrepairToolCall?:ToolCallRepairFunction<ToolSet>
Defined in: packages/core/src/types.ts:670
Override AI SDK experimental_repairToolCall for this call only. Thin passthrough.
Inherited from
runtimeContext?
optionalruntimeContext?:unknown
Defined in: packages/core/src/types.ts:672
Override AI SDK runtimeContext for this call only. Thin passthrough.
Inherited from
signal?
optionalsignal?:AbortSignal
Defined in: packages/core/src/types.ts:477
AbortSignal to cancel the request
Inherited from
stopWhen?
optionalstopWhen?:StopCondition
Defined in: packages/core/src/types.ts:659
Override stopWhen for this call only. Takes precedence over construction-time stopWhen.
Inherited from
temperature?
optionaltemperature?:number
Defined in: packages/core/src/types.ts:655
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:57
Unique ID of this tool call
Overrides
toolOrder?
optionaltoolOrder?: readonlystring[]
Defined in: packages/core/src/types.ts:666
Override AI SDK toolOrder for this call only. Thin passthrough.
Inherited from
verbose?
optionalverbose?:boolean
Defined in: packages/core/src/types.ts:474
Enable verbose logging for debugging