/ examples / typescript / tools / exa-search.ts
exa-search.ts
 1  /**
 2   * Exa Web Search Tool Example
 3   * 
 4   * Demonstrates semantic web search with Exa AI.
 5   * 
 6   * Prerequisites:
 7   *   npm install praisonai-ts @exalabs/ai-sdk
 8   *   export EXA_API_KEY=your-api-key
 9   *   export OPENAI_API_KEY=your-api-key
10   */
11  
12  // For local development, use relative imports
13  // For production, use: import { Agent, exaSearch } from 'praisonai-ts'
14  import { Agent } from '../../../src/praisonai-ts/src';
15  import { exaSearch } from '../../../src/praisonai-ts/src/tools/builtins';
16  
17  async function main() {
18    console.log('=== Exa Web Search Tool Example ===\n');
19  
20    // Example 1: Basic Semantic Search
21    console.log('1. Basic Semantic Search');
22    console.log('------------------------');
23    
24    const searchAgent = new Agent({
25      name: 'SemanticSearcher',
26      instructions: 'You search the web using semantic search and provide detailed summaries.',
27      tools: [exaSearch({ numResults: 5, type: 'auto' })],
28    });
29  
30    const searchResult = await searchAgent.chat('Find the latest AI research breakthroughs');
31    console.log('Search Result:', searchResult);
32    console.log();
33  
34    // Example 2: Company Research
35    console.log('2. Company Research');
36    console.log('-------------------');
37    
38    const companyAgent = new Agent({
39      name: 'CompanyResearcher',
40      instructions: 'You research companies and provide analysis.',
41      tools: [
42        exaSearch({
43          type: 'auto',
44          numResults: 5,
45          category: 'company',
46          contents: {
47            text: { maxCharacters: 1000 },
48            summary: true,
49            livecrawl: 'preferred',
50          },
51        }),
52      ],
53    });
54  
55    const companyResult = await companyAgent.chat(
56      'Find AI startups in Europe founded after 2020'
57    );
58    console.log('Company Result:', companyResult);
59    console.log();
60  
61    // Example 3: Academic Paper Search
62    console.log('3. Academic Paper Search');
63    console.log('------------------------');
64    
65    const academicAgent = new Agent({
66      name: 'AcademicResearcher',
67      instructions: 'You search for academic papers and summarize findings.',
68      tools: [
69        exaSearch({
70          type: 'neural',
71          category: 'research paper',
72          numResults: 5,
73          includeDomains: ['arxiv.org', 'nature.com', 'science.org'],
74        }),
75      ],
76    });
77  
78    const academicResult = await academicAgent.chat(
79      'Find recent papers on transformer architectures and attention mechanisms'
80    );
81    console.log('Academic Result:', academicResult);
82  }
83  
84  main().catch(console.error);