const apiTools = [
{
type: "function",
function: {
name: "send_email",
description: "Send an email to a recipient",
parameters: {
type: "object",
properties: {
to: { type: "string", description: "Email address" },
subject: { type: "string", description: "Email subject" },
body: { type: "string", description: "Email content" },
},
required: ["to", "subject", "body"],
},
},
},
{
type: "function",
function: {
name: "create_calendar_event",
description: "Create a calendar event",
parameters: {
type: "object",
properties: {
title: { type: "string" },
start_time: { type: "string", format: "date-time" },
duration: { type: "integer", description: "Duration in minutes" },
attendees: { type: "array", items: { type: "string" } },
},
required: ["title", "start_time"],
},
},
},
];
const executeApiTool = async (toolCall) => {
const { name } = toolCall.function;
const args = JSON.parse(toolCall.function.arguments);
switch (name) {
case "send_email":
return await emailAPI.send(args);
case "create_calendar_event":
return await calendarAPI.createEvent(args);
default:
throw new Error(`Unknown API tool: ${name}`);
}
};