@elizaos/plugin-research 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +400 -0
  2. package/dist/index.cjs +9366 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.js +9284 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +80 -0
  7. package/src/__tests__/action-chaining.test.ts +532 -0
  8. package/src/__tests__/actions.test.ts +118 -0
  9. package/src/__tests__/cache-rate-limiter.test.ts +303 -0
  10. package/src/__tests__/content-extractors.test.ts +26 -0
  11. package/src/__tests__/deepresearch-bench-integration.test.ts +520 -0
  12. package/src/__tests__/deepresearch-bench-simplified.e2e.test.ts +290 -0
  13. package/src/__tests__/deepresearch-bench.e2e.test.ts +376 -0
  14. package/src/__tests__/e2e.test.ts +1870 -0
  15. package/src/__tests__/multi-benchmark-runner.ts +427 -0
  16. package/src/__tests__/providers.test.ts +156 -0
  17. package/src/__tests__/real-world.e2e.test.ts +788 -0
  18. package/src/__tests__/research-scenarios.test.ts +755 -0
  19. package/src/__tests__/research.e2e.test.ts +704 -0
  20. package/src/__tests__/research.test.ts +174 -0
  21. package/src/__tests__/search-providers.test.ts +174 -0
  22. package/src/__tests__/single-benchmark-runner.ts +735 -0
  23. package/src/__tests__/test-search-providers.ts +171 -0
  24. package/src/__tests__/verify-apis.test.ts +82 -0
  25. package/src/actions.ts +1677 -0
  26. package/src/benchmark/deepresearch-benchmark.ts +369 -0
  27. package/src/evaluation/research-evaluator.ts +444 -0
  28. package/src/examples/api-integration.md +498 -0
  29. package/src/examples/browserbase-integration.md +132 -0
  30. package/src/examples/debug-research-query.ts +162 -0
  31. package/src/examples/defi-code-scenarios.md +536 -0
  32. package/src/examples/defi-implementation-guide.md +454 -0
  33. package/src/examples/eliza-research-example.ts +142 -0
  34. package/src/examples/fix-renewable-energy-research.ts +209 -0
  35. package/src/examples/research-scenarios.md +408 -0
  36. package/src/examples/run-complete-renewable-research.ts +303 -0
  37. package/src/examples/run-deep-research.ts +352 -0
  38. package/src/examples/run-logged-research.ts +304 -0
  39. package/src/examples/run-real-research.ts +151 -0
  40. package/src/examples/save-research-output.ts +133 -0
  41. package/src/examples/test-file-logging.ts +199 -0
  42. package/src/examples/test-real-research.ts +67 -0
  43. package/src/examples/test-renewable-energy-research.ts +229 -0
  44. package/src/index.ts +28 -0
  45. package/src/integrations/cache.ts +128 -0
  46. package/src/integrations/content-extractors/firecrawl.ts +314 -0
  47. package/src/integrations/content-extractors/pdf-extractor.ts +350 -0
  48. package/src/integrations/content-extractors/playwright.ts +420 -0
  49. package/src/integrations/factory.ts +419 -0
  50. package/src/integrations/index.ts +18 -0
  51. package/src/integrations/rate-limiter.ts +181 -0
  52. package/src/integrations/search-providers/academic.ts +290 -0
  53. package/src/integrations/search-providers/exa.ts +205 -0
  54. package/src/integrations/search-providers/npm.ts +330 -0
  55. package/src/integrations/search-providers/pypi.ts +211 -0
  56. package/src/integrations/search-providers/serpapi.ts +277 -0
  57. package/src/integrations/search-providers/serper.ts +358 -0
  58. package/src/integrations/search-providers/stagehand-google.ts +87 -0
  59. package/src/integrations/search-providers/tavily.ts +187 -0
  60. package/src/processing/relevance-analyzer.ts +353 -0
  61. package/src/processing/research-logger.ts +450 -0
  62. package/src/processing/result-processor.ts +372 -0
  63. package/src/prompts/research-prompts.ts +419 -0
  64. package/src/providers/cacheProvider.ts +164 -0
  65. package/src/providers.ts +173 -0
  66. package/src/service.ts +2588 -0
  67. package/src/services/swe-bench.ts +286 -0
  68. package/src/strategies/research-strategies.ts +790 -0
  69. package/src/types/pdf-parse.d.ts +34 -0
  70. package/src/types.ts +551 -0
  71. package/src/verification/claim-verifier.ts +443 -0
package/README.md ADDED
@@ -0,0 +1,400 @@
1
+ # ElizaOS Research Plugin
2
+
3
+ A powerful deep research plugin for ElizaOS that enables AI agents to conduct comprehensive multi-phase internet research with intelligent analysis and synthesis. Features advanced claim verification, two-step report enhancement, and achieves top performance on DeepResearch Bench.
4
+
5
+ ## Features
6
+
7
+ - πŸ” **Multi-phase Research Process**: Planning β†’ Searching β†’ Analyzing β†’ Synthesizing β†’ Reporting
8
+ - βœ… **Claim Verification**: Cross-references claims across sources with confidence scoring
9
+ - πŸ“ **Two-Step Enhancement**: Initial synthesis followed by evidence-based enhancement
10
+ - 🌐 **Multiple Search Providers**: Tavily, Serper, SerpAPI, Exa, and Stagehand integration
11
+ - πŸ“„ **Content Extraction**: Browserbase/Stagehand (preferred), Firecrawl, and Playwright
12
+ - πŸ’Ž **DeFi Specialization**: 10+ specialized DeFi research scenarios
13
+ - πŸ“Š **Comprehensive Reports**: Automated report generation with citations and methodology
14
+ - ⏸️ **Research Control**: Start, pause, resume, and cancel research projects
15
+ - πŸ§ͺ **Extensive Testing**: Unit tests and real-world E2E test scenarios
16
+ - ⚑ **Rate Limiting**: Automatic rate limiting to avoid API quota issues
17
+ - 🧠 **Parallel Processing**: Concurrent searches and content extraction for speed
18
+ - πŸ§ͺ **Research Evaluation**: Built-in quality assessment using RACE and FACT frameworks
19
+ - πŸ† **DeepResearch Bench Compatible**: Supports all 22 research domains
20
+
21
+ ## Prerequisites
22
+
23
+ - Node.js 18+ or Bun runtime
24
+ - At least one search provider API key
25
+ - (Optional) Content extraction API key for better results
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install @elizaos/plugin-research
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ Set up the following environment variables in your `.env` file:
36
+
37
+ ```bash
38
+ # Search providers (at least one required)
39
+ TAVILY_API_KEY=your-tavily-api-key # Recommended - best for general web search
40
+ SERPER_API_KEY=your-serper-api-key # Alternative to Tavily
41
+ SERPAPI_API_KEY=your-serpapi-api-key # Good for Google results
42
+ EXA_API_KEY=your-exa-api-key # Neural search, great for research
43
+
44
+ # Content extraction (optional but recommended)
45
+ FIRECRAWL_API_KEY=your-firecrawl-key # Reliable content extraction
46
+ PLAYWRIGHT_TIMEOUT=30000 # Timeout for Playwright (fallback)
47
+
48
+ # Academic search (optional)
49
+ SEMANTIC_SCHOLAR_API_KEY=your-key # For academic papers
50
+
51
+ # General Settings
52
+ RESEARCH_MAX_RESULTS=10 # Max search results per query
53
+ RESEARCH_TIMEOUT=300000 # Timeout in milliseconds (5 minutes)
54
+ RESEARCH_ENABLE_CITATIONS=true # Enable citation tracking
55
+ RESEARCH_LANGUAGE=en # Preferred language
56
+
57
+ # Advanced Settings
58
+ RESEARCH_DEPTH=deep # surface|moderate|deep|phd-level
59
+ RESEARCH_PARALLEL_SEARCHES=3 # Number of parallel searches
60
+ RESEARCH_CACHE_TTL=3600 # Cache TTL in seconds
61
+ FILE_LOGGING=true # Enable file output logging
62
+ ```
63
+
64
+ ## Setting Up the Plugin
65
+
66
+ ### 1. Basic Agent Setup
67
+
68
+ ```typescript
69
+ import { Agent } from '@elizaos/core';
70
+ import { researchPlugin } from '@elizaos/plugin-research';
71
+
72
+ // Create an agent with the research plugin
73
+ const agent = new Agent({
74
+ name: 'ResearchAgent',
75
+ plugins: [researchPlugin],
76
+ modelProvider: 'openai', // or your preferred model
77
+ // ... other configuration
78
+ });
79
+
80
+ // Start the agent
81
+ await agent.start();
82
+ ```
83
+
84
+ ### 2. Character Configuration
85
+
86
+ Create a character file that includes research actions:
87
+
88
+ ```json
89
+ {
90
+ "name": "Research Assistant",
91
+ "description": "An AI research assistant specialized in comprehensive analysis",
92
+ "plugins": ["@elizaos/plugin-research"],
93
+ "settings": {
94
+ "RESEARCH_DEPTH": "deep",
95
+ "RESEARCH_MAX_RESULTS": "30"
96
+ },
97
+ "messageExamples": [
98
+ [
99
+ {
100
+ "user": "{{user1}}",
101
+ "content": {
102
+ "text": "Research the latest developments in quantum computing"
103
+ }
104
+ },
105
+ {
106
+ "user": "{{agentName}}",
107
+ "content": {
108
+ "text": "I'll conduct comprehensive research on the latest developments in quantum computing.",
109
+ "action": "START_RESEARCH"
110
+ }
111
+ }
112
+ ]
113
+ ]
114
+ }
115
+ ```
116
+
117
+ ### 3. Running Research via CLI
118
+
119
+ ```bash
120
+ # Start an agent with research capabilities
121
+ npx eliza --character characters/research-assistant.json
122
+
123
+ # In the chat:
124
+ > Research the impact of AI on healthcare
125
+ > What are the latest breakthroughs in renewable energy?
126
+ > Compare different blockchain consensus mechanisms
127
+ ```
128
+
129
+ ## Using Research Actions
130
+
131
+ ### Available Actions
132
+
133
+ #### 1. **START_RESEARCH**
134
+ Initiates a comprehensive research project.
135
+
136
+ ```typescript
137
+ // Example usage in conversation
138
+ User: "Research the latest advancements in quantum error correction"
139
+ Agent: "I'll start researching the latest advancements in quantum error correction."
140
+ // Agent automatically triggers START_RESEARCH action
141
+ ```
142
+
143
+ #### 2. **PAUSE_RESEARCH**
144
+ Pauses an active research project.
145
+
146
+ ```typescript
147
+ User: "Pause the current research"
148
+ Agent: "I'll pause the ongoing research project."
149
+ ```
150
+
151
+ #### 3. **RESUME_RESEARCH**
152
+ Resumes a paused research project.
153
+
154
+ ```typescript
155
+ User: "Resume the research"
156
+ Agent: "I'll resume the paused research project."
157
+ ```
158
+
159
+ #### 4. **CANCEL_RESEARCH**
160
+ Cancels an active research project.
161
+
162
+ ```typescript
163
+ User: "Cancel the research"
164
+ Agent: "I'll cancel the current research project."
165
+ ```
166
+
167
+ #### 5. **EVALUATE_RESEARCH**
168
+ Evaluates completed research using RACE/FACT frameworks.
169
+
170
+ ```typescript
171
+ User: "Evaluate the research quality"
172
+ Agent: "I'll evaluate the completed research report."
173
+ ```
174
+
175
+ ## Programmatic Usage
176
+
177
+ ### Creating a Research Project
178
+
179
+ ```typescript
180
+ import { ResearchService } from '@elizaos/plugin-research';
181
+
182
+ // Get the research service from the runtime
183
+ const researchService = runtime.getService('research') as ResearchService;
184
+
185
+ // Create a research project
186
+ const project = await researchService.createResearchProject(
187
+ 'Research the latest developments in renewable energy storage',
188
+ {
189
+ researchDepth: 'deep',
190
+ domain: 'engineering',
191
+ maxSearchResults: 30,
192
+ searchProviders: ['web', 'academic'],
193
+ evaluationEnabled: true
194
+ }
195
+ );
196
+
197
+ // Monitor progress
198
+ const checkProgress = async () => {
199
+ const updated = await researchService.getProject(project.id);
200
+ console.log(`Status: ${updated.status}, Phase: ${updated.phase}`);
201
+
202
+ if (updated.status === 'completed') {
203
+ console.log('Research completed!');
204
+ console.log('Report:', updated.report);
205
+ }
206
+ };
207
+
208
+ // Check every 10 seconds
209
+ const interval = setInterval(checkProgress, 10000);
210
+ ```
211
+
212
+ ### Exporting Research Results
213
+
214
+ ```typescript
215
+ // Export as Markdown
216
+ const markdown = await researchService.exportProject(project.id, 'markdown');
217
+ await fs.writeFile('research-report.md', markdown);
218
+
219
+ // Export as JSON
220
+ const json = await researchService.exportProject(project.id, 'json');
221
+ await fs.writeFile('research-data.json', json);
222
+
223
+ // Export for DeepResearch Bench
224
+ const benchFormat = await researchService.exportProject(project.id, 'deepresearch');
225
+ await fs.writeFile('benchmark-submission.json', benchFormat);
226
+ ```
227
+
228
+ ## Autocoder Integration
229
+
230
+ The research plugin can be used with ElizaOS's autocoder capabilities for automated code research and implementation:
231
+
232
+ ### 1. Code Research Scenarios
233
+
234
+ ```typescript
235
+ // Research and implement a specific algorithm
236
+ User: "Research and implement the A* pathfinding algorithm in TypeScript"
237
+
238
+ // Research best practices and generate code
239
+ User: "Research React performance optimization techniques and create a guide"
240
+
241
+ // Analyze existing codebases
242
+ User: "Research how authentication is implemented in popular Node.js frameworks"
243
+ ```
244
+
245
+ ### 2. DeFi Code Research
246
+
247
+ The plugin includes specialized DeFi research actions:
248
+
249
+ ```typescript
250
+ // Security analysis
251
+ User: "Analyze the security of Uniswap V3's smart contracts"
252
+
253
+ // Gas optimization research
254
+ User: "Research gas optimization techniques for Solidity smart contracts"
255
+
256
+ // MEV research
257
+ User: "Research MEV protection strategies for DeFi protocols"
258
+ ```
259
+
260
+ ### 3. Automated Implementation Workflow
261
+
262
+ ```typescript
263
+ // 1. Research phase
264
+ const research = await researchService.createResearchProject(
265
+ 'Research best practices for implementing JWT authentication in Node.js'
266
+ );
267
+
268
+ // 2. Wait for completion
269
+ // ... monitoring code ...
270
+
271
+ // 3. Use research to generate implementation
272
+ const implementation = await autocoderService.generateImplementation({
273
+ research: research.report,
274
+ language: 'typescript',
275
+ framework: 'express',
276
+ includeTests: true
277
+ });
278
+ ```
279
+
280
+ ## Advanced Configuration
281
+
282
+ ### Domain-Specific Research
283
+
284
+ ```typescript
285
+ const project = await researchService.createResearchProject(query, {
286
+ domain: 'computer_science', // Automatically selects appropriate providers
287
+ researchDepth: 'phd-level', // Maximum depth
288
+ searchProviders: ['web', 'academic', 'github'],
289
+ evaluationEnabled: true,
290
+ cacheEnabled: true
291
+ });
292
+ ```
293
+
294
+ ### Custom Search Strategies
295
+
296
+ ```typescript
297
+ // Configure search strategy
298
+ const config = {
299
+ searchStrategy: {
300
+ approach: 'iterative-refinement',
301
+ maxIterations: 5,
302
+ qualityThreshold: 0.8,
303
+ diversityRequirement: true
304
+ },
305
+ contentExtraction: {
306
+ preferredExtractor: 'firecrawl',
307
+ fallbackExtractor: 'playwright',
308
+ extractImages: true,
309
+ extractTables: true
310
+ }
311
+ };
312
+ ```
313
+
314
+ ## Performance Optimization
315
+
316
+ ### 1. Enable Caching
317
+
318
+ ```bash
319
+ RESEARCH_CACHE_ENABLED=true
320
+ RESEARCH_CACHE_TTL=7200 # 2 hours
321
+ ```
322
+
323
+ ### 2. Parallel Processing
324
+
325
+ ```bash
326
+ RESEARCH_PARALLEL_SEARCHES=5 # Increase for faster results
327
+ RESEARCH_PARALLEL_EXTRACTIONS=3 # Parallel content extraction
328
+ ```
329
+
330
+ ### 3. Rate Limiting
331
+
332
+ The plugin automatically handles rate limiting, but you can configure:
333
+
334
+ ```bash
335
+ RESEARCH_RATE_LIMIT_DELAY=1000 # Delay between requests (ms)
336
+ RESEARCH_MAX_RETRIES=3 # Retry failed requests
337
+ ```
338
+
339
+ ## Testing
340
+
341
+ ```bash
342
+ # Run all tests
343
+ npm test
344
+
345
+ # Run specific test suites
346
+ npm test -- research.test.ts
347
+ npm test -- e2e.test.ts
348
+
349
+ # Test API connections
350
+ bun run src/__tests__/verify-apis.test.ts
351
+
352
+ # Run benchmark test
353
+ bun run test-benchmark.ts
354
+ ```
355
+
356
+ ## DeepResearch Bench Integration
357
+
358
+ The plugin is designed to achieve top scores on DeepResearch Bench:
359
+
360
+ ```bash
361
+ # Prepare benchmark submission
362
+ bun run src/scripts/prepare-benchmark.ts
363
+
364
+ # Run benchmark evaluation
365
+ cd deep_research_bench
366
+ python deepresearch_bench_race.py elizaos-research --limit 5
367
+ ```
368
+
369
+ ## Troubleshooting
370
+
371
+ ### Common Issues
372
+
373
+ 1. **No search results**: Ensure at least one search API key is configured
374
+ 2. **Content extraction fails**: Add FIRECRAWL_API_KEY for reliable extraction
375
+ 3. **Research times out**: Increase RESEARCH_TIMEOUT value
376
+ 4. **Rate limit errors**: Reduce RESEARCH_PARALLEL_SEARCHES
377
+
378
+ ### Debug Mode
379
+
380
+ ```bash
381
+ DEBUG=eliza:research:* npm start
382
+ ```
383
+
384
+ ## Contributing
385
+
386
+ 1. Fork the repository
387
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
388
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
389
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
390
+ 5. Open a Pull Request
391
+
392
+ ## License
393
+
394
+ MIT
395
+
396
+ ## Support
397
+
398
+ - **Documentation**: [ElizaOS Docs](https://elizaos.github.io/eliza/)
399
+ - **Discord**: [Join our community](https://discord.gg/elizaos)
400
+ - **Issues**: [GitHub Issues](https://github.com/elizaos/eliza/issues)