The type of tool calls, defaults to DefaultToolCall. Provide a discriminated union for type-safe tool call handling.
// Define typed tool calls as a discriminated union
type MyToolCalls =
| { name: "get_weather"; args: { location: string }; id?: string }
| { name: "search"; args: { query: string; limit?: number }; id?: string };
// Use with AIMessage
const message: AIMessage<MyToolCalls> = ...;
// Now tool.name === "get_weather" narrows tool.args type
if (message.tool_calls) {
for (const tool of message.tool_calls) {
if (tool.name === "get_weather") {
// tool.args is now { location: string }
console.log(tool.args.location);
}
}
}
AI message type that can be parameterized with custom tool call types.