Skip to main content

Execute Tool

You can directly invoke a tool with executeTool. It enables tracing and error handling compared to calling the execute function of the tool directly. The result is typed.

Example

const result = await executeTool({
tool: calculator,
args: {
a: 14,
b: 12,
operator: "*",
},
});

Error Handling

When the tool execution fails, executeTool will throw a ToolExecutionError that contains the tool name, the inputs, and the cause.