rcrewai 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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +108 -0
  3. data/LICENSE +21 -0
  4. data/README.md +328 -0
  5. data/Rakefile +130 -0
  6. data/bin/rcrewai +7 -0
  7. data/docs/_config.yml +59 -0
  8. data/docs/_layouts/api.html +16 -0
  9. data/docs/_layouts/default.html +78 -0
  10. data/docs/_layouts/example.html +24 -0
  11. data/docs/_layouts/tutorial.html +33 -0
  12. data/docs/api/configuration.md +327 -0
  13. data/docs/api/crew.md +345 -0
  14. data/docs/api/index.md +41 -0
  15. data/docs/api/tools.md +412 -0
  16. data/docs/assets/css/style.css +416 -0
  17. data/docs/examples/human-in-the-loop.md +382 -0
  18. data/docs/examples/index.md +78 -0
  19. data/docs/examples/production-ready-crew.md +485 -0
  20. data/docs/examples/simple-research-crew.md +297 -0
  21. data/docs/index.md +353 -0
  22. data/docs/tutorials/getting-started.md +341 -0
  23. data/examples/async_execution_example.rb +294 -0
  24. data/examples/hierarchical_crew_example.rb +193 -0
  25. data/examples/human_in_the_loop_example.rb +233 -0
  26. data/lib/rcrewai/agent.rb +636 -0
  27. data/lib/rcrewai/async_executor.rb +248 -0
  28. data/lib/rcrewai/cli.rb +39 -0
  29. data/lib/rcrewai/configuration.rb +100 -0
  30. data/lib/rcrewai/crew.rb +292 -0
  31. data/lib/rcrewai/human_input.rb +520 -0
  32. data/lib/rcrewai/llm_client.rb +41 -0
  33. data/lib/rcrewai/llm_clients/anthropic.rb +127 -0
  34. data/lib/rcrewai/llm_clients/azure.rb +158 -0
  35. data/lib/rcrewai/llm_clients/base.rb +82 -0
  36. data/lib/rcrewai/llm_clients/google.rb +158 -0
  37. data/lib/rcrewai/llm_clients/ollama.rb +199 -0
  38. data/lib/rcrewai/llm_clients/openai.rb +124 -0
  39. data/lib/rcrewai/memory.rb +194 -0
  40. data/lib/rcrewai/process.rb +421 -0
  41. data/lib/rcrewai/task.rb +376 -0
  42. data/lib/rcrewai/tools/base.rb +82 -0
  43. data/lib/rcrewai/tools/code_executor.rb +333 -0
  44. data/lib/rcrewai/tools/email_sender.rb +210 -0
  45. data/lib/rcrewai/tools/file_reader.rb +111 -0
  46. data/lib/rcrewai/tools/file_writer.rb +115 -0
  47. data/lib/rcrewai/tools/pdf_processor.rb +342 -0
  48. data/lib/rcrewai/tools/sql_database.rb +226 -0
  49. data/lib/rcrewai/tools/web_search.rb +131 -0
  50. data/lib/rcrewai/version.rb +5 -0
  51. data/lib/rcrewai.rb +36 -0
  52. data/rcrewai.gemspec +54 -0
  53. metadata +365 -0
@@ -0,0 +1,485 @@
1
+ ---
2
+ layout: example
3
+ title: Production-Ready Research Crew
4
+ description: A comprehensive example showing all features of RCrewAI in a production scenario
5
+ ---
6
+
7
+ # Production-Ready Research Crew
8
+
9
+ This example demonstrates a fully-featured, production-ready crew that showcases all of RCrewAI's advanced capabilities including intelligent agents, tool usage, memory, error handling, and monitoring.
10
+
11
+ ## Scenario
12
+
13
+ We'll build a comprehensive market research crew that:
14
+ 1. Researches market trends using web search
15
+ 2. Analyzes competitor data from files
16
+ 3. Generates detailed reports with insights
17
+ 4. Creates presentation materials
18
+ 5. Monitors performance and handles errors
19
+
20
+ ## Complete Implementation
21
+
22
+ ```ruby
23
+ #!/usr/bin/env ruby
24
+
25
+ require 'rcrewai'
26
+ require 'logger'
27
+ require 'fileutils'
28
+
29
+ # Production logging setup
30
+ logger = Logger.new('crew_execution.log')
31
+ logger.level = Logger::INFO
32
+
33
+ puts "🚀 Starting Production Market Research Crew"
34
+ puts "=" * 50
35
+
36
+ # Configuration with error handling
37
+ begin
38
+ RCrewAI.configure do |config|
39
+ config.llm_provider = :openai # Switch to :anthropic, :google as needed
40
+ config.temperature = 0.1 # Low temperature for consistent results
41
+ config.max_tokens = 2000 # Reasonable limit
42
+ config.timeout = 120 # 2 minute timeout
43
+ end
44
+
45
+ puts "✅ LLM Configuration: #{RCrewAI.configuration.llm_provider} (#{RCrewAI.configuration.model})"
46
+ rescue RCrewAI::ConfigurationError => e
47
+ puts "❌ Configuration failed: #{e.message}"
48
+ puts "Please check your API key environment variables"
49
+ exit 1
50
+ end
51
+
52
+ # Create output directory
53
+ FileUtils.mkdir_p('output/reports')
54
+ FileUtils.mkdir_p('output/presentations')
55
+
56
+ # Production-grade agents with comprehensive toolsets
57
+ market_researcher = RCrewAI::Agent.new(
58
+ name: "market_researcher",
59
+ role: "Senior Market Research Analyst",
60
+ goal: "Conduct thorough market research and competitive analysis",
61
+ backstory: "You are a seasoned market researcher with 15 years of experience in technology markets. You excel at finding reliable data sources, identifying market trends, and understanding competitive landscapes.",
62
+ tools: [
63
+ RCrewAI::Tools::WebSearch.new(max_results: 15, timeout: 45),
64
+ RCrewAI::Tools::FileReader.new(
65
+ max_file_size: 50_000_000,
66
+ allowed_extensions: %w[.csv .json .txt .md .pdf]
67
+ )
68
+ ],
69
+ verbose: true,
70
+ max_iterations: 8,
71
+ max_execution_time: 600, # 10 minutes max
72
+ allow_delegation: false
73
+ )
74
+
75
+ data_analyst = RCrewAI::Agent.new(
76
+ name: "data_analyst",
77
+ role: "Senior Data Analyst",
78
+ goal: "Analyze market data and extract actionable insights",
79
+ backstory: "You are an expert data analyst specializing in market intelligence. You can identify patterns, trends, and opportunities from complex datasets and research findings.",
80
+ tools: [
81
+ RCrewAI::Tools::FileReader.new(
82
+ allowed_extensions: %w[.csv .json .xlsx .txt]
83
+ ),
84
+ RCrewAI::Tools::FileWriter.new(
85
+ allowed_extensions: %w[.json .csv .md .txt],
86
+ create_directories: true
87
+ )
88
+ ],
89
+ verbose: true,
90
+ max_iterations: 6,
91
+ allow_delegation: false
92
+ )
93
+
94
+ report_writer = RCrewAI::Agent.new(
95
+ name: "report_writer",
96
+ role: "Strategic Business Writer",
97
+ goal: "Create compelling, professional business reports and presentations",
98
+ backstory: "You are an experienced business writer who creates executive-level reports and presentations. You excel at synthesizing complex information into clear, actionable recommendations.",
99
+ tools: [
100
+ RCrewAI::Tools::FileReader.new,
101
+ RCrewAI::Tools::FileWriter.new(
102
+ max_file_size: 20_000_000,
103
+ create_directories: true
104
+ )
105
+ ],
106
+ verbose: true,
107
+ max_iterations: 5,
108
+ allow_delegation: true
109
+ )
110
+
111
+ # Create production crew
112
+ crew = RCrewAI::Crew.new("market_research_crew")
113
+ crew.add_agent(market_researcher)
114
+ crew.add_agent(data_analyst)
115
+ crew.add_agent(report_writer)
116
+
117
+ puts "👥 Crew created with #{crew.agents.length} agents"
118
+
119
+ # Define comprehensive tasks with callbacks and error handling
120
+
121
+ # Task 1: Market Research
122
+ market_research_task = RCrewAI::Task.new(
123
+ name: "comprehensive_market_research",
124
+ description: <<~DESC,
125
+ Conduct comprehensive market research on the AI/ML tools market for 2024.
126
+ Focus on:
127
+ 1. Market size and growth projections
128
+ 2. Key players and their market share
129
+ 3. Emerging trends and technologies
130
+ 4. Customer segments and use cases
131
+ 5. Pricing models and strategies
132
+
133
+ Use multiple search queries to gather comprehensive data.
134
+ DESC
135
+ agent: market_researcher,
136
+ expected_output: "Detailed market research report with data sources, key findings, and market insights formatted as structured text with clear sections",
137
+ max_retries: 3,
138
+ callback: ->(task, result) {
139
+ logger.info "Market research completed: #{result.length} characters"
140
+ puts "📊 Market research phase completed"
141
+ }
142
+ )
143
+
144
+ # Task 2: Data Analysis
145
+ data_analysis_task = RCrewAI::Task.new(
146
+ name: "market_data_analysis",
147
+ description: <<~DESC,
148
+ Analyze the market research findings to extract key insights and trends.
149
+ Create structured analysis including:
150
+ 1. Market opportunity assessment
151
+ 2. Competitive positioning analysis
152
+ 3. Risk and opportunity matrix
153
+ 4. Strategic recommendations
154
+ 5. Key metrics and KPIs
155
+
156
+ Save analysis results to output/reports/market_analysis.json
157
+ DESC
158
+ agent: data_analyst,
159
+ expected_output: "Structured market analysis saved to JSON file with clear categories, metrics, and actionable insights",
160
+ context: [market_research_task],
161
+ tools: [RCrewAI::Tools::FileWriter.new],
162
+ callback: ->(task, result) {
163
+ logger.info "Data analysis completed"
164
+ puts "🔍 Data analysis phase completed"
165
+ }
166
+ )
167
+
168
+ # Task 3: Executive Report
169
+ executive_report_task = RCrewAI::Task.new(
170
+ name: "executive_report_creation",
171
+ description: <<~DESC,
172
+ Create a comprehensive executive report based on the market research and analysis.
173
+ The report should include:
174
+ 1. Executive Summary (key findings and recommendations)
175
+ 2. Market Overview (size, growth, trends)
176
+ 3. Competitive Analysis (key players, positioning)
177
+ 4. Opportunities and Recommendations
178
+ 5. Risk Assessment
179
+ 6. Next Steps and Action Items
180
+
181
+ Format as professional markdown and save to output/reports/executive_report.md
182
+ DESC
183
+ agent: report_writer,
184
+ expected_output: "Professional executive report in markdown format, 2000-3000 words, saved to file",
185
+ context: [market_research_task, data_analysis_task],
186
+ callback: ->(task, result) {
187
+ logger.info "Executive report created"
188
+ puts "📝 Executive report completed"
189
+ }
190
+ )
191
+
192
+ # Task 4: Presentation Materials
193
+ presentation_task = RCrewAI::Task.new(
194
+ name: "presentation_creation",
195
+ description: <<~DESC,
196
+ Create presentation slides content based on the executive report.
197
+ Create slide-by-slide content for a 15-20 slide presentation including:
198
+ 1. Title slide
199
+ 2. Agenda
200
+ 3. Key findings (3-4 slides)
201
+ 4. Market analysis (3-4 slides)
202
+ 5. Competitive landscape (2-3 slides)
203
+ 6. Recommendations (2-3 slides)
204
+ 7. Next steps
205
+
206
+ Save as structured markdown to output/presentations/market_research_presentation.md
207
+ DESC
208
+ agent: report_writer,
209
+ expected_output: "Presentation content structured as slides, saved to markdown file with clear slide breaks and bullet points",
210
+ context: [executive_report_task],
211
+ async: false, # Sequential execution
212
+ callback: ->(task, result) {
213
+ logger.info "Presentation materials created"
214
+ puts "🎯 Presentation materials completed"
215
+ }
216
+ )
217
+
218
+ # Add all tasks to crew
219
+ crew.add_task(market_research_task)
220
+ crew.add_task(data_analysis_task)
221
+ crew.add_task(executive_report_task)
222
+ crew.add_task(presentation_task)
223
+
224
+ puts "📋 #{crew.tasks.length} tasks defined with dependencies"
225
+
226
+ # Execute with comprehensive monitoring
227
+ start_time = Time.now
228
+
229
+ begin
230
+ puts "\n🎬 Starting crew execution..."
231
+ puts "This may take several minutes as agents research and analyze..."
232
+
233
+ # Execute the crew
234
+ results = crew.execute
235
+
236
+ execution_time = Time.now - start_time
237
+
238
+ # Comprehensive results reporting
239
+ puts "\n" + "="*60
240
+ puts "🎉 EXECUTION COMPLETED SUCCESSFULLY"
241
+ puts "="*60
242
+ puts "Total execution time: #{execution_time.round(2)} seconds"
243
+
244
+ # Task-by-task results
245
+ crew.tasks.each do |task|
246
+ puts "\n📌 Task: #{task.name}"
247
+ puts " Status: #{task.status}"
248
+ puts " Time: #{task.execution_time&.round(2)}s"
249
+ puts " Result size: #{task.result&.length || 0} characters"
250
+
251
+ if task.failed?
252
+ puts " ❌ Error: #{task.result}"
253
+ logger.error "Task #{task.name} failed: #{task.result}"
254
+ else
255
+ puts " ✅ Success"
256
+ end
257
+ end
258
+
259
+ # Memory and performance stats
260
+ puts "\n🧠 Agent Memory Statistics:"
261
+ crew.agents.each do |agent|
262
+ stats = agent.memory.stats
263
+ puts " #{agent.name}:"
264
+ puts " Short-term memories: #{stats[:short_term_count]}"
265
+ puts " Long-term categories: #{stats[:long_term_types]}"
266
+ puts " Success rate: #{stats[:success_rate]}%"
267
+ puts " Tool usages: #{stats[:tool_usage_count]}"
268
+ end
269
+
270
+ # File outputs verification
271
+ puts "\n📁 Generated Files:"
272
+ output_files = [
273
+ 'output/reports/market_analysis.json',
274
+ 'output/reports/executive_report.md',
275
+ 'output/presentations/market_research_presentation.md'
276
+ ]
277
+
278
+ output_files.each do |file|
279
+ if File.exist?(file)
280
+ size = File.size(file)
281
+ puts " ✅ #{file} (#{size} bytes)"
282
+ else
283
+ puts " ❌ #{file} (not found)"
284
+ end
285
+ end
286
+
287
+ puts "\n🎯 All deliverables completed successfully!"
288
+ puts "Check the output/ directory for your market research results."
289
+
290
+ rescue RCrewAI::TaskExecutionError => e
291
+ puts "\n❌ Task execution failed: #{e.message}"
292
+ logger.error "Task execution error: #{e.message}"
293
+
294
+ rescue RCrewAI::AgentError => e
295
+ puts "\n❌ Agent error: #{e.message}"
296
+ logger.error "Agent error: #{e.message}"
297
+
298
+ rescue StandardError => e
299
+ puts "\n💥 Unexpected error: #{e.message}"
300
+ puts e.backtrace.first(5).join("\n") if ENV['DEBUG']
301
+ logger.error "Unexpected error: #{e.message}"
302
+ logger.error e.backtrace.join("\n")
303
+
304
+ ensure
305
+ # Cleanup and final logging
306
+ total_time = Time.now - start_time
307
+ logger.info "Crew execution finished in #{total_time.round(2)}s"
308
+ puts "\n📊 Log file: crew_execution.log"
309
+ end
310
+
311
+ # Performance analysis
312
+ puts "\n⚡ Performance Analysis:"
313
+ puts " Average task time: #{crew.tasks.map(&:execution_time).compact.sum / crew.tasks.length}s"
314
+ puts " Fastest task: #{crew.tasks.map(&:execution_time).compact.min}s"
315
+ puts " Slowest task: #{crew.tasks.map(&:execution_time).compact.max}s"
316
+
317
+ puts "\n🔚 Market Research Crew execution complete!"
318
+ ```
319
+
320
+ ## Running the Production Crew
321
+
322
+ ### Prerequisites
323
+
324
+ 1. **Set up environment variables**:
325
+ ```bash
326
+ export OPENAI_API_KEY="your-openai-key"
327
+ # or
328
+ export ANTHROPIC_API_KEY="your-anthropic-key"
329
+ # or
330
+ export GOOGLE_API_KEY="your-google-key"
331
+ ```
332
+
333
+ 2. **Install dependencies**:
334
+ ```bash
335
+ bundle install
336
+ ```
337
+
338
+ 3. **Run the crew**:
339
+ ```bash
340
+ ruby production_crew.rb
341
+ ```
342
+
343
+ ### Expected Output
344
+
345
+ The crew will generate:
346
+
347
+ ```
348
+ output/
349
+ ├── reports/
350
+ │ ├── market_analysis.json # Structured data analysis
351
+ │ └── executive_report.md # Professional report
352
+ └── presentations/
353
+ └── market_research_presentation.md # Slide content
354
+ ```
355
+
356
+ ### Console Output Example
357
+
358
+ ```
359
+ 🚀 Starting Production Market Research Crew
360
+ ==================================================
361
+ ✅ LLM Configuration: openai (gpt-4)
362
+ 👥 Crew created with 3 agents
363
+ 📋 4 tasks defined with dependencies
364
+
365
+ 🎬 Starting crew execution...
366
+ This may take several minutes as agents research and analyze...
367
+
368
+ INFO Agent market_researcher starting task: comprehensive_market_research
369
+ DEBUG Iteration 1: Sending prompt to LLM
370
+ DEBUG Using tool: websearch with params: {:query=>"AI ML tools market 2024", :max_results=>15}
371
+ DEBUG Tool websearch result: Search Results:
372
+ 1. AI/ML Market Size and Growth 2024
373
+ URL: https://example.com/ai-market-report
374
+ The AI/ML tools market is projected to reach $126 billion...
375
+
376
+ 📊 Market research phase completed
377
+ 📍 Data analysis phase completed
378
+ 📝 Executive report completed
379
+ 🎯 Presentation materials completed
380
+
381
+ ============================================================
382
+ 🎉 EXECUTION COMPLETED SUCCESSFULLY
383
+ ============================================================
384
+ Total execution time: 342.56 seconds
385
+
386
+ 📌 Task: comprehensive_market_research
387
+ Status: completed
388
+ Time: 156.23s
389
+ Result size: 8,432 characters
390
+ ✅ Success
391
+
392
+ 📌 Task: market_data_analysis
393
+ Status: completed
394
+ Time: 89.45s
395
+ Result size: 5,221 characters
396
+ ✅ Success
397
+
398
+ 📌 Task: executive_report_creation
399
+ Status: completed
400
+ Time: 67.33s
401
+ Result size: 12,890 characters
402
+ ✅ Success
403
+
404
+ 📌 Task: presentation_creation
405
+ Status: completed
406
+ Time: 29.55s
407
+ Result size: 6,778 characters
408
+ ✅ Success
409
+
410
+ 🧠 Agent Memory Statistics:
411
+ market_researcher:
412
+ Short-term memories: 4
413
+ Long-term categories: 2
414
+ Success rate: 100.0%
415
+ Tool usages: 12
416
+
417
+ 📁 Generated Files:
418
+ ✅ output/reports/market_analysis.json (5,221 bytes)
419
+ ✅ output/reports/executive_report.md (12,890 bytes)
420
+ ✅ output/presentations/market_research_presentation.md (6,778 bytes)
421
+
422
+ 🎯 All deliverables completed successfully!
423
+ Check the output/ directory for your market research results.
424
+
425
+ ⚡ Performance Analysis:
426
+ Average task time: 85.64s
427
+ Fastest task: 29.55s
428
+ Slowest task: 156.23s
429
+
430
+ 🔚 Market Research Crew execution complete!
431
+ ```
432
+
433
+ ## Production Features Demonstrated
434
+
435
+ ### 1. **Robust Configuration**
436
+ - Environment variable management
437
+ - Error handling for missing API keys
438
+ - Multiple LLM provider support
439
+
440
+ ### 2. **Professional Agents**
441
+ - Specialized roles and expertise
442
+ - Comprehensive tool sets
443
+ - Performance limits and timeouts
444
+
445
+ ### 3. **Advanced Task Management**
446
+ - Task dependencies and context sharing
447
+ - Retry logic with exponential backoff
448
+ - Callbacks for monitoring
449
+ - File output verification
450
+
451
+ ### 4. **Error Handling & Recovery**
452
+ - Graceful error handling at all levels
453
+ - Comprehensive logging
454
+ - Cleanup procedures
455
+
456
+ ### 5. **Monitoring & Analytics**
457
+ - Execution time tracking
458
+ - Memory usage statistics
459
+ - Performance analysis
460
+ - Success rate monitoring
461
+
462
+ ### 6. **File Management**
463
+ - Structured output directories
464
+ - Multiple file formats (JSON, Markdown)
465
+ - File size validation
466
+ - Security controls
467
+
468
+ ### 7. **Memory System**
469
+ - Agent learning from executions
470
+ - Tool usage patterns
471
+ - Performance optimization
472
+
473
+ This example demonstrates how RCrewAI can be used in production environments with proper error handling, monitoring, and output management. The crew produces professional-quality deliverables while maintaining robust performance and reliability.
474
+
475
+ ## Customization Options
476
+
477
+ You can easily modify this example for different use cases:
478
+
479
+ - **Change research domain**: Modify task descriptions for different markets
480
+ - **Add more agents**: Include specialists like financial analysts, technical writers
481
+ - **Different output formats**: JSON reports, CSV data, PDF generation
482
+ - **Integration points**: Add database connections, API integrations, email notifications
483
+ - **Monitoring**: Add metrics collection, alerting, performance dashboards
484
+
485
+ The production-ready structure scales to handle complex, multi-agent workflows in enterprise environments.