Skip to content

Type Alias: ContextAwareToolRun()

@providerprotocol/agents


@providerprotocol/agents / index / ContextAwareToolRun

ContextAwareToolRun = (params, context?) => Promise<unknown>

Defined in: src/execution/types.ts:740

Type for a tool run function that accepts execution context as a second parameter.

Tools can optionally accept ToolExecutionContext for sub-agent inheritance and event propagation. The context parameter is optional to maintain compatibility with standard tools.

Record<string, unknown>

The tool parameters from the model

ToolExecutionContext

Optional execution context for agent features

Promise<unknown>

Promise resolving to the tool result

const contextAwareRun: ContextAwareToolRun = async (params, context) => {
if (context?.onSubagentEvent) {
// This tool can spawn sub-agents
context.onSubagentEvent({
type: 'subagent_start',
subagentId: 'sub-123',
subagentType: 'explorer',
parentToolCallId: context.toolCallId,
prompt: 'Explore the codebase',
timestamp: Date.now(),
});
}
return 'result';
};