/** * Local Tools Example - Register and Execute Local Functions * * This example shows how to add local Python/TypeScript functions as tools * that the agent can call during execution. * * Note: No decorators needed! Just pass functions directly. */ import { Studio } from '../src'; // Define some local tools function calculateSum(a: number, b: number): number { return a + b; } function getWeather(city: string): string { // In a real app, this would call a weather API const weatherData: Record = { 'new york': 'Cloudy, 72°F', 'london': 'Rainy, 55°F', 'tokyo': 'Sunny, 68°F', 'paris': 'Clear, 65°F' }; return weatherData[city.toLowerCase()] || 'Weather data not available'; } function readDatabase(query: string): string { // Simulate database query return `Results for query "${query}": [{"id": 1, "name": "John"}, {"id": 2, "name": "Jane"}]`; } async function main() { const studio = new Studio({ apiKey: process.env.LYZR_API_KEY }); try { // Create agent console.log('Creating agent with local tools...'); const agent = await studio.createAgent({ name: 'Tool-Enabled Bot', provider: 'gpt-4o', role: 'Helpful assistant with calculator and weather access', goal: 'Help users with calculations and weather', instructions: 'Use available tools to help answer questions' }); console.log('✓ Agent created\n'); // Add tools to the agent console.log('Adding tools...'); await agent.addTool(calculateSum); await agent.addTool(getWeather); await agent.addTool(readDatabase); console.log(`✓ Added ${agent.listTools().length} tools\n`); // List registered tools console.log('Registered tools:'); agent.listTools().forEach(tool => { console.log(` - ${tool.name}: ${tool.description}`); }); // Run agent with tool usage console.log('\nRunning agent...'); const response = await agent.run( 'What is the weather in London and Paris? Also, what is 25 plus 17?' ); console.log('\nAgent response:'); console.log(response.response); // Clean up await agent.delete(); } catch (error) { console.error('Error:', error); process.exit(1); } } main();