market_intelligence_aggregator
Aggregate market intelligence from financial, news, and social sources to analyze topics or companies, extracting insights from stock data, news analysis, and social sentiment.
Instructions
Aggregate market intelligence from financial, news, and social sources
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeCrypto | No | Include cryptocurrency data if relevant | |
| includeNews | No | Include news analysis | |
| includeSocial | No | Include social media sentiment | |
| includeStock | No | Include stock/financial data | |
| topic | Yes | Market topic or company to analyze (e.g., "Apple", "AI market", "cryptocurrency") |
Input Schema (JSON Schema)
{
"properties": {
"includeCrypto": {
"default": false,
"description": "Include cryptocurrency data if relevant",
"type": "boolean"
},
"includeNews": {
"default": true,
"description": "Include news analysis",
"type": "boolean"
},
"includeSocial": {
"default": true,
"description": "Include social media sentiment",
"type": "boolean"
},
"includeStock": {
"default": true,
"description": "Include stock/financial data",
"type": "boolean"
},
"topic": {
"description": "Market topic or company to analyze (e.g., \"Apple\", \"AI market\", \"cryptocurrency\")",
"type": "string"
}
},
"required": [
"topic"
],
"type": "object"
}
Implementation Reference
- The core handler function that executes the market_intelligence_aggregator tool. It aggregates intelligence from financial (Alpha Vantage), news (NewsAPI), social (Reddit), and optionally crypto sources using parallel promises, processes results, generates summary and metadata.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' }; } }
- Input schema defining the parameters for the market_intelligence_aggregator tool, including required 'topic' and optional flags for different data sources.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 market_intelligence_aggregator tool into the ToolRegistry within the registerSmartSearchTools function.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)Main server initialization calls registerSmartSearchTools, which registers the market_intelligence_aggregator among others.registerSmartSearchTools(this.toolRegistry); // 2 tools: intelligent_research, market_intelligence_aggregator