import { createGrantexFunction } from '@grantex/autogen';
const readCalendar = createGrantexFunction({
name: 'read_calendar',
description: 'Read upcoming calendar events',
parameters: {
type: 'object',
properties: {
date: { type: 'string', description: 'Date in YYYY-MM-DD format' },
},
required: ['date'],
},
grantToken, // JWT from Grantex token exchange
requiredScope: 'calendar:read', // must be in token's scp claim
func: async (args) => {
return await getCalendarEvents(args.date);
},
});
// Pass definition to the LLM
const response = await openai.chat.completions.create({
model: 'gpt-4',
tools: [readCalendar.definition],
messages,
});
// Execute when the LLM selects the tool
const result = await readCalendar.execute({ date: '2026-03-01' });