market_intelligence_aggregator
Aggregate market intelligence from financial, news, and social sources to analyze topics like companies, industries, or cryptocurrency.
Instructions
Aggregate market intelligence from financial, news, and social sources
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic | Yes | Market topic or company to analyze (e.g., "Apple", "AI market", "cryptocurrency") | |
| includeStock | No | Include stock/financial data | |
| includeNews | No | Include news analysis | |
| includeSocial | No | Include social media sentiment | |
| includeCrypto | No | Include cryptocurrency data if relevant |
Implementation Reference
- Main handler function that performs parallel tool executions for financial (alpha_vantage_symbol_search), news (newsapi_search), social (reddit_post_search), and optional crypto (coingecko_coin_search) data aggregation, processes results into structured intelligence report with summary.
execute: async (args: any) => { try { const startTime = Date.now(); const intelligence: any = { topic: args.topic, timestamp: new Date().toISOString(), financial_data: null, news_analysis: null, social_sentiment: null, crypto_data: null, summary: {}, metadata: {} }; const promises = []; // 金融数据 if (args.includeStock) { const stockTool = registry.getTool('alpha_vantage_symbol_search'); if (stockTool) { promises.push( stockTool.execute({ keywords: args.topic }) .then(result => ({ type: 'financial', data: result })) .catch(error => ({ type: 'financial', error: error.message })) ); } } // 新闻分析 if (args.includeNews) { const newsTool = registry.getTool('newsapi_search'); if (newsTool) { promises.push( newsTool.execute({ query: args.topic, maxResults: 10 }) .then(result => ({ type: 'news', data: result })) .catch(error => ({ type: 'news', error: error.message })) ); } } // 社交媒体情感 if (args.includeSocial) { const socialTool = registry.getTool('reddit_post_search'); if (socialTool) { promises.push( socialTool.execute({ query: args.topic, maxResults: 10 }) .then(result => ({ type: 'social', data: result })) .catch(error => ({ type: 'social', error: error.message })) ); } } // 加密货币数据 if (args.includeCrypto) { const cryptoTool = registry.getTool('coingecko_coin_search'); if (cryptoTool) { promises.push( cryptoTool.execute({ query: args.topic }) .then(result => ({ type: 'crypto', data: result })) .catch(error => ({ type: 'crypto', error: error.message })) ); } } // 等待所有数据收集完成 const results = await Promise.all(promises); // 处理结果 for (const result of results) { if ('error' in result) { intelligence[`${result.type}_data`] = { error: result.error }; continue; } if (result.data.success) { intelligence[`${result.type}_data`] = result.data.data; } else { intelligence[`${result.type}_data`] = { error: result.data.error }; } } // 生成摘要 intelligence.summary = { topic: intelligence.topic, data_availability: { financial: !!intelligence.financial_data && !intelligence.financial_data.error, news: !!intelligence.news_data && !intelligence.news_data.error, social: !!intelligence.social_data && !intelligence.social_data.error, crypto: !!intelligence.crypto_data && !intelligence.crypto_data.error }, key_insights: ['Market intelligence aggregated from multiple sources'] }; intelligence.metadata = { analysis_time: Date.now() - startTime, data_sources: results.filter(r => !('error' in r)).length, timestamp: Date.now() }; return { success: true, data: intelligence }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Market intelligence aggregation failed' }; } } - JSON schema defining input parameters: topic (required), includeStock, includeNews, includeSocial, includeCrypto.
inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Market topic or company to analyze (e.g., "Apple", "AI market", "cryptocurrency")' }, includeStock: { type: 'boolean', description: 'Include stock/financial data', default: true }, includeNews: { type: 'boolean', description: 'Include news analysis', default: true }, includeSocial: { type: 'boolean', description: 'Include social media sentiment', default: true }, includeCrypto: { type: 'boolean', description: 'Include cryptocurrency data if relevant', default: false } }, required: ['topic'] }, - src/tools/aggregation/smart-search-tools.ts:250-395 (registration)Registration of the tool via registry.registerTool, including name, description, category, source, inputSchema, and execute handler.
registry.registerTool({ name: 'market_intelligence_aggregator', description: 'Aggregate market intelligence from financial, news, and social sources', category: 'aggregation', source: 'multiple', inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Market topic or company to analyze (e.g., "Apple", "AI market", "cryptocurrency")' }, includeStock: { type: 'boolean', description: 'Include stock/financial data', default: true }, includeNews: { type: 'boolean', description: 'Include news analysis', default: true }, includeSocial: { type: 'boolean', description: 'Include social media sentiment', default: true }, includeCrypto: { type: 'boolean', description: 'Include cryptocurrency data if relevant', default: false } }, required: ['topic'] }, execute: async (args: any) => { try { const startTime = Date.now(); const intelligence: any = { topic: args.topic, timestamp: new Date().toISOString(), financial_data: null, news_analysis: null, social_sentiment: null, crypto_data: null, summary: {}, metadata: {} }; const promises = []; // 金融数据 if (args.includeStock) { const stockTool = registry.getTool('alpha_vantage_symbol_search'); if (stockTool) { promises.push( stockTool.execute({ keywords: args.topic }) .then(result => ({ type: 'financial', data: result })) .catch(error => ({ type: 'financial', error: error.message })) ); } } // 新闻分析 if (args.includeNews) { const newsTool = registry.getTool('newsapi_search'); if (newsTool) { promises.push( newsTool.execute({ query: args.topic, maxResults: 10 }) .then(result => ({ type: 'news', data: result })) .catch(error => ({ type: 'news', error: error.message })) ); } } // 社交媒体情感 if (args.includeSocial) { const socialTool = registry.getTool('reddit_post_search'); if (socialTool) { promises.push( socialTool.execute({ query: args.topic, maxResults: 10 }) .then(result => ({ type: 'social', data: result })) .catch(error => ({ type: 'social', error: error.message })) ); } } // 加密货币数据 if (args.includeCrypto) { const cryptoTool = registry.getTool('coingecko_coin_search'); if (cryptoTool) { promises.push( cryptoTool.execute({ query: args.topic }) .then(result => ({ type: 'crypto', data: result })) .catch(error => ({ type: 'crypto', error: error.message })) ); } } // 等待所有数据收集完成 const results = await Promise.all(promises); // 处理结果 for (const result of results) { if ('error' in result) { intelligence[`${result.type}_data`] = { error: result.error }; continue; } if (result.data.success) { intelligence[`${result.type}_data`] = result.data.data; } else { intelligence[`${result.type}_data`] = { error: result.data.error }; } } // 生成摘要 intelligence.summary = { topic: intelligence.topic, data_availability: { financial: !!intelligence.financial_data && !intelligence.financial_data.error, news: !!intelligence.news_data && !intelligence.news_data.error, social: !!intelligence.social_data && !intelligence.social_data.error, crypto: !!intelligence.crypto_data && !intelligence.crypto_data.error }, key_insights: ['Market intelligence aggregated from multiple sources'] }; intelligence.metadata = { analysis_time: Date.now() - startTime, data_sources: results.filter(r => !('error' in r)).length, timestamp: Date.now() }; return { success: true, data: intelligence }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Market intelligence aggregation failed' }; } } }); - src/index.ts:254-254 (registration)Invocation of registerSmartSearchTools(this.toolRegistry) which registers market_intelligence_aggregator and intelligent_research.
registerSmartSearchTools(this.toolRegistry); // 2 tools: intelligent_research, market_intelligence_aggregator