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,341 @@
1
+ ---
2
+ layout: tutorial
3
+ title: Getting Started with RCrewAI
4
+ description: Learn how to install and use RCrewAI to build your first AI crew
5
+ ---
6
+
7
+ # Getting Started with RCrewAI
8
+
9
+ This tutorial will walk you through installing RCrewAI and creating your first AI crew.
10
+
11
+ ## Prerequisites
12
+
13
+ Before you begin, ensure you have:
14
+ - Ruby 3.0 or higher installed
15
+ - Bundler gem installed (`gem install bundler`)
16
+ - An API key from one of the supported providers:
17
+ - **OpenAI** (recommended for beginners): Get from [platform.openai.com](https://platform.openai.com)
18
+ - **Anthropic (Claude)**: Get from [console.anthropic.com](https://console.anthropic.com)
19
+ - **Google (Gemini)**: Get from [ai.google.dev](https://ai.google.dev)
20
+ - **Azure OpenAI**: Set up through Azure portal
21
+
22
+ ## Installation
23
+
24
+ ### Method 1: Add to your Gemfile
25
+
26
+ Add RCrewAI to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'rcrewai'
30
+ ```
31
+
32
+ Then run:
33
+
34
+ ```bash
35
+ bundle install
36
+ ```
37
+
38
+ ### Method 2: Direct Installation
39
+
40
+ Install the gem directly:
41
+
42
+ ```bash
43
+ gem install rcrewai
44
+ ```
45
+
46
+ ## Configuration
47
+
48
+ RCrewAI supports multiple LLM providers. Choose the one that works best for you:
49
+
50
+ ### OpenAI (Recommended for beginners)
51
+
52
+ Set your API key as an environment variable:
53
+ ```bash
54
+ export OPENAI_API_KEY="your-openai-key-here"
55
+ ```
56
+
57
+ Configure RCrewAI:
58
+ ```ruby
59
+ RCrewAI.configure do |config|
60
+ config.llm_provider = :openai
61
+ config.openai_model = 'gpt-4' # or 'gpt-3.5-turbo' for lower cost
62
+ end
63
+ ```
64
+
65
+ ### Anthropic (Claude)
66
+
67
+ ```bash
68
+ export ANTHROPIC_API_KEY="your-anthropic-key-here"
69
+ ```
70
+
71
+ ```ruby
72
+ RCrewAI.configure do |config|
73
+ config.llm_provider = :anthropic
74
+ config.anthropic_model = 'claude-3-sonnet-20240229'
75
+ end
76
+ ```
77
+
78
+ ### Google (Gemini)
79
+
80
+ ```bash
81
+ export GOOGLE_API_KEY="your-google-key-here"
82
+ ```
83
+
84
+ ```ruby
85
+ RCrewAI.configure do |config|
86
+ config.llm_provider = :google
87
+ config.google_model = 'gemini-pro'
88
+ end
89
+ ```
90
+
91
+ ### Azure OpenAI
92
+
93
+ ```bash
94
+ export AZURE_OPENAI_API_KEY="your-azure-key"
95
+ export AZURE_API_VERSION="2023-05-15"
96
+ export AZURE_DEPLOYMENT_NAME="your-deployment"
97
+ ```
98
+
99
+ ```ruby
100
+ RCrewAI.configure do |config|
101
+ config.llm_provider = :azure
102
+ config.base_url = "https://your-resource.openai.azure.com/"
103
+ config.azure_model = 'gpt-4'
104
+ end
105
+ ```
106
+
107
+ For more configuration options, see the [Configuration Documentation]({{ site.baseurl }}/api/configuration).
108
+
109
+ ## Creating Your First Crew
110
+
111
+ Let's create an intelligent research crew that can actually search the web, analyze information, and write reports.
112
+
113
+ ### Step 1: Create the Crew and Configure
114
+
115
+ ```ruby
116
+ require 'rcrewai'
117
+
118
+ # Configure RCrewAI with your chosen provider
119
+ RCrewAI.configure do |config|
120
+ config.llm_provider = :openai # or :anthropic, :google, :azure
121
+ # API keys are loaded from environment variables automatically
122
+ end
123
+
124
+ # Create a new crew
125
+ crew = RCrewAI::Crew.new("ai_research_crew")
126
+ ```
127
+
128
+ ### Step 2: Create Intelligent Agents with Tools
129
+
130
+ Create specialized agents with actual capabilities:
131
+
132
+ ```ruby
133
+ # Research Agent with web search capabilities
134
+ researcher = RCrewAI::Agent.new(
135
+ name: "alex_researcher",
136
+ role: "Senior Research Analyst",
137
+ goal: "Uncover cutting-edge developments in AI and data science",
138
+ backstory: "You are a seasoned researcher with a knack for uncovering the latest trends and technologies in AI and data science. You excel at finding reliable sources and extracting key insights.",
139
+ tools: [RCrewAI::Tools::WebSearch.new], # Can search the web!
140
+ verbose: true, # Shows reasoning process
141
+ max_iterations: 5 # Limit reasoning loops
142
+ )
143
+
144
+ # Writer Agent with file writing capabilities
145
+ writer = RCrewAI::Agent.new(
146
+ name: "emma_writer",
147
+ role: "Tech Content Strategist",
148
+ goal: "Craft compelling content on tech advancements",
149
+ backstory: "You are a renowned Content Strategist, known for your insightful and engaging articles on technology and innovation. You transform complex research into compelling narratives.",
150
+ tools: [
151
+ RCrewAI::Tools::FileWriter.new, # Can write files!
152
+ RCrewAI::Tools::FileReader.new # Can read reference materials
153
+ ],
154
+ verbose: true,
155
+ allow_delegation: false
156
+ )
157
+
158
+ # Add agents to the crew
159
+ crew.add_agent(researcher)
160
+ crew.add_agent(writer)
161
+ ```
162
+
163
+ ### Step 3: Create Advanced Tasks with Dependencies
164
+
165
+ Define tasks with specific outputs and dependencies:
166
+
167
+ ```ruby
168
+ # Research Task - Agent will actually search the web!
169
+ research_task = RCrewAI::Task.new(
170
+ name: "research_ai_trends_2024",
171
+ description: "Research the latest AI developments and breakthroughs in 2024. Focus on identifying key trends, major companies involved, and potential impacts on different industries.",
172
+ agent: researcher,
173
+ expected_output: "A comprehensive research report covering: 1) Top 5 AI trends in 2024, 2) Key companies and their innovations, 3) Industry impact analysis, 4) Future predictions",
174
+ max_retries: 2 # Retry if web search fails
175
+ )
176
+
177
+ # Writing Task - Agent will use research results and save to file!
178
+ writing_task = RCrewAI::Task.new(
179
+ name: "write_ai_trends_article",
180
+ description: "Write a compelling, informative article about AI trends based on the research. Make it engaging for a tech-savvy audience. Save the final article to a file named 'ai_trends_2024.md'.",
181
+ agent: writer,
182
+ expected_output: "A well-structured 1000-1500 word article covering the research findings, saved to ai_trends_2024.md file",
183
+ context: [research_task], # Uses research results as input
184
+ callback: ->(task, result) { puts "Article completed: #{result.length} characters written!" }
185
+ )
186
+
187
+ # Add tasks to the crew
188
+ crew.add_task(research_task)
189
+ crew.add_task(writing_task)
190
+ ```
191
+
192
+ ### Step 4: Execute and Monitor
193
+
194
+ Run the crew and monitor the intelligent agents at work:
195
+
196
+ ```ruby
197
+ puts "šŸš€ Starting AI Research Crew..."
198
+ puts "The agents will now research and write about AI trends!"
199
+
200
+ # Execute the crew - this will:
201
+ # 1. Research agent searches web for AI trends
202
+ # 2. Research agent analyzes and summarizes findings
203
+ # 3. Writer agent receives research context
204
+ # 4. Writer agent creates article and saves to file
205
+ result = crew.execute
206
+
207
+ # Check results and status
208
+ puts "\n" + "="*50
209
+ puts "šŸ“Š EXECUTION SUMMARY"
210
+ puts "="*50
211
+
212
+ puts "Research Task Status: #{research_task.status}"
213
+ puts "Research Execution Time: #{research_task.execution_time&.round(2)}s"
214
+ puts "Research Result Preview:"
215
+ puts research_task.result[0..200] + "..." if research_task.result
216
+
217
+ puts "\nWriting Task Status: #{writing_task.status}"
218
+ puts "Writing Execution Time: #{writing_task.execution_time&.round(2)}s"
219
+ puts "Article Preview:"
220
+ puts writing_task.result[0..200] + "..." if writing_task.result
221
+
222
+ # Check if file was actually created
223
+ if File.exist?('ai_trends_2024.md')
224
+ puts "\nāœ… Article successfully saved to ai_trends_2024.md"
225
+ puts "File size: #{File.size('ai_trends_2024.md')} bytes"
226
+ else
227
+ puts "\nāŒ Article file not found"
228
+ end
229
+
230
+ # Check agent memory stats
231
+ puts "\n🧠 Agent Memory Stats:"
232
+ puts "Researcher memory: #{researcher.memory.stats}"
233
+ puts "Writer memory: #{writer.memory.stats}"
234
+ ```
235
+
236
+ ### What Just Happened?
237
+
238
+ When you run this code with a valid API key, here's what actually happens:
239
+
240
+ 1. **Researcher Agent**:
241
+ - Uses reasoning loops to plan the research approach
242
+ - Executes web searches using DuckDuckGo
243
+ - Analyzes search results to identify key trends
244
+ - Synthesizes findings into a comprehensive report
245
+ - Stores successful strategies in memory
246
+
247
+ 2. **Writer Agent**:
248
+ - Receives research findings as context
249
+ - Plans article structure and key points
250
+ - Creates engaging, well-structured content
251
+ - Saves the final article to a markdown file
252
+ - Learns from successful writing patterns
253
+
254
+ 3. **System Features**:
255
+ - Automatic retry if web search fails
256
+ - Security controls on file operations
257
+ - Memory persistence between executions
258
+ - Comprehensive logging and monitoring
259
+
260
+ ## Using the CLI
261
+
262
+ RCrewAI also provides a command-line interface for managing crews:
263
+
264
+ ### Create a New Crew
265
+
266
+ ```bash
267
+ $ rcrewai new research_team
268
+ Creating new crew: research_team
269
+ Crew 'research_team' created successfully!
270
+ ```
271
+
272
+ ### List Available Crews
273
+
274
+ ```bash
275
+ $ rcrewai list
276
+ Available crews:
277
+ - research_team
278
+ - marketing_crew
279
+ - development_crew
280
+ ```
281
+
282
+ ### Run a Crew
283
+
284
+ ```bash
285
+ $ rcrewai run --crew research_team
286
+ Running crew: research_team
287
+ Executing tasks...
288
+ ```
289
+
290
+ ## Working with Tools
291
+
292
+ Agents can be equipped with tools to enhance their capabilities:
293
+
294
+ ```ruby
295
+ # Create a web search tool
296
+ search_tool = RCrewAI::Tools::WebSearch.new
297
+
298
+ # Create an agent with tools
299
+ analyst = RCrewAI::Agent.new(
300
+ name: "data_analyst",
301
+ role: "Data Analyst",
302
+ goal: "Analyze data and provide insights",
303
+ tools: [search_tool]
304
+ )
305
+ ```
306
+
307
+ ## Best Practices
308
+
309
+ 1. **Define Clear Roles**: Give each agent a specific, well-defined role
310
+ 2. **Set Specific Goals**: Make agent goals measurable and achievable
311
+ 3. **Create Detailed Tasks**: Provide clear descriptions and expected outputs
312
+ 4. **Use Task Dependencies**: Link related tasks using the context parameter
313
+ 5. **Leverage Tools**: Equip agents with appropriate tools for their tasks
314
+
315
+ ## Next Steps
316
+
317
+ Now that you've created your first crew, explore these topics:
318
+
319
+ - [Advanced Agent Configuration]({{ site.baseurl }}/tutorials/advanced-agents)
320
+ - [Custom Tools Development]({{ site.baseurl }}/tutorials/custom-tools)
321
+ - [Working with Multiple Crews]({{ site.baseurl }}/tutorials/multiple-crews)
322
+ - [Production Deployment]({{ site.baseurl }}/tutorials/deployment)
323
+
324
+ ## Troubleshooting
325
+
326
+ ### Common Issues
327
+
328
+ **Issue**: "No API key configured"
329
+ **Solution**: Ensure your API key is set in the environment variables or configuration file.
330
+
331
+ **Issue**: "Agent not found"
332
+ **Solution**: Make sure the agent is added to the crew before creating tasks that reference it.
333
+
334
+ **Issue**: "Task execution failed"
335
+ **Solution**: Check that all task dependencies are properly defined and agents have necessary tools.
336
+
337
+ ## Get Help
338
+
339
+ - [GitHub Issues](https://github.com/gkosmo/rcrewAI/issues)
340
+ - [API Documentation]({{ site.baseurl }}/api/)
341
+ - [Examples]({{ site.baseurl }}/examples/)
@@ -0,0 +1,294 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rcrewai'
4
+ require 'benchmark'
5
+
6
+ puts "⚔ Async Execution Example"
7
+ puts "=" * 50
8
+
9
+ # Configure RCrewAI
10
+ RCrewAI.configure do |config|
11
+ config.llm_provider = :openai # Change as needed
12
+ config.temperature = 0.1
13
+ end
14
+
15
+ puts "šŸ”§ Setting up crew for async vs sync performance comparison..."
16
+
17
+ # Create a crew with multiple tasks that can benefit from parallelization
18
+ crew = RCrewAI::Crew.new("data_processing_crew")
19
+
20
+ # Create specialized agents
21
+ data_collector = RCrewAI::Agent.new(
22
+ name: "data_collector",
23
+ role: "Data Collection Specialist",
24
+ goal: "Gather data from various sources efficiently",
25
+ backstory: "You specialize in collecting and organizing data from multiple sources.",
26
+ tools: [RCrewAI::Tools::WebSearch.new],
27
+ verbose: true,
28
+ max_iterations: 3
29
+ )
30
+
31
+ data_analyst = RCrewAI::Agent.new(
32
+ name: "data_analyst",
33
+ role: "Data Analyst",
34
+ goal: "Analyze collected data and extract insights",
35
+ backstory: "You excel at finding patterns and insights in datasets.",
36
+ tools: [RCrewAI::Tools::FileWriter.new],
37
+ verbose: true,
38
+ max_iterations: 4
39
+ )
40
+
41
+ report_writer = RCrewAI::Agent.new(
42
+ name: "report_writer",
43
+ role: "Technical Writer",
44
+ goal: "Create comprehensive reports from analysis",
45
+ backstory: "You transform complex analysis into clear, actionable reports.",
46
+ tools: [RCrewAI::Tools::FileWriter.new, RCrewAI::Tools::FileReader.new],
47
+ verbose: true,
48
+ max_iterations: 3
49
+ )
50
+
51
+ code_reviewer = RCrewAI::Agent.new(
52
+ name: "code_reviewer",
53
+ role: "Code Quality Specialist",
54
+ goal: "Review and analyze code quality",
55
+ backstory: "You ensure code meets quality standards and best practices.",
56
+ tools: [RCrewAI::Tools::CodeExecutor.new, RCrewAI::Tools::FileReader.new],
57
+ verbose: true,
58
+ max_iterations: 4
59
+ )
60
+
61
+ # Add agents to crew
62
+ crew.add_agent(data_collector)
63
+ crew.add_agent(data_analyst)
64
+ crew.add_agent(report_writer)
65
+ crew.add_agent(code_reviewer)
66
+
67
+ puts "šŸ‘„ Created crew with #{crew.agents.length} specialized agents"
68
+
69
+ # Create tasks that can run independently (parallel execution potential)
70
+ data_collection_task1 = RCrewAI::Task.new(
71
+ name: "collect_market_data",
72
+ description: "Research current market trends in AI and machine learning for 2024",
73
+ agent: data_collector,
74
+ expected_output: "Market research summary with key trends and statistics",
75
+ async: true
76
+ )
77
+
78
+ data_collection_task2 = RCrewAI::Task.new(
79
+ name: "collect_tech_data",
80
+ description: "Research emerging technologies in software development",
81
+ agent: data_collector,
82
+ expected_output: "Technology research summary with key developments",
83
+ async: true
84
+ )
85
+
86
+ # Analysis tasks that depend on data collection
87
+ analysis_task1 = RCrewAI::Task.new(
88
+ name: "analyze_market_trends",
89
+ description: "Analyze the collected market data to identify opportunities and threats",
90
+ agent: data_analyst,
91
+ expected_output: "Market analysis report with actionable insights saved to market_analysis.md",
92
+ context: [data_collection_task1],
93
+ async: true
94
+ )
95
+
96
+ analysis_task2 = RCrewAI::Task.new(
97
+ name: "analyze_tech_trends",
98
+ description: "Analyze emerging technology data to predict future developments",
99
+ agent: data_analyst,
100
+ expected_output: "Technology trend analysis saved to tech_analysis.md",
101
+ context: [data_collection_task2],
102
+ async: true
103
+ )
104
+
105
+ # Code review task (independent)
106
+ code_review_task = RCrewAI::Task.new(
107
+ name: "review_sample_code",
108
+ description: "Review this Python code for best practices: 'def calculate(x, y): return x + y if x > 0 else 0'",
109
+ agent: code_reviewer,
110
+ expected_output: "Code review with suggestions for improvement",
111
+ async: true
112
+ )
113
+
114
+ # Final report task (depends on all analysis)
115
+ final_report_task = RCrewAI::Task.new(
116
+ name: "create_comprehensive_report",
117
+ description: "Combine all analysis into a comprehensive business report with recommendations",
118
+ agent: report_writer,
119
+ expected_output: "Executive business report combining all insights saved to executive_report.md",
120
+ context: [analysis_task1, analysis_task2, code_review_task],
121
+ async: true
122
+ )
123
+
124
+ # Add all tasks to crew
125
+ crew.add_task(data_collection_task1)
126
+ crew.add_task(data_collection_task2)
127
+ crew.add_task(analysis_task1)
128
+ crew.add_task(analysis_task2)
129
+ crew.add_task(code_review_task)
130
+ crew.add_task(final_report_task)
131
+
132
+ puts "šŸ“‹ Created #{crew.tasks.length} tasks with dependency chains"
133
+
134
+ # Demonstrate both sync and async execution
135
+ puts "\nšŸ”„ Comparing Synchronous vs Asynchronous Execution"
136
+ puts "-" * 60
137
+
138
+ # First: Synchronous execution
139
+ puts "\n1ļøāƒ£ SYNCHRONOUS EXECUTION"
140
+ puts "Tasks will execute sequentially, one at a time..."
141
+
142
+ sync_time = Benchmark.measure do
143
+ sync_results = crew.execute
144
+
145
+ puts "\nšŸ“Š Synchronous Results:"
146
+ puts " Process: #{sync_results[:process]}"
147
+ puts " Success Rate: #{sync_results[:success_rate]}%"
148
+ puts " Completed: #{sync_results[:completed_tasks]}/#{sync_results[:total_tasks]}"
149
+ puts " Failed: #{sync_results[:failed_tasks]}"
150
+ end
151
+
152
+ puts "ā±ļø Synchronous execution time: #{sync_time.real.round(2)} seconds"
153
+
154
+ # Clear any previous results
155
+ crew.tasks.each do |task|
156
+ task.instance_variable_set(:@result, nil)
157
+ task.instance_variable_set(:@status, :pending)
158
+ end
159
+
160
+ puts "\n2ļøāƒ£ ASYNCHRONOUS EXECUTION"
161
+ puts "Tasks will execute in parallel where possible..."
162
+
163
+ async_time = Benchmark.measure do
164
+ async_results = crew.execute(
165
+ async: true,
166
+ max_concurrency: 4, # Allow up to 4 concurrent tasks
167
+ timeout: 300, # 5 minute timeout
168
+ verbose: true # Show detailed async logs
169
+ )
170
+
171
+ puts "\nšŸ“Š Asynchronous Results:"
172
+ puts " Process: #{async_results[:process]}"
173
+ puts " Execution Mode: #{async_results[:execution_mode]}"
174
+ puts " Max Concurrency: #{async_results[:max_concurrency]}"
175
+ puts " Success Rate: #{async_results[:success_rate]}%"
176
+ puts " Completed: #{async_results[:completed_tasks]}/#{async_results[:total_tasks]}"
177
+ puts " Failed: #{async_results[:failed_tasks]}"
178
+ puts " Timeouts: #{async_results[:timed_out_tasks]}"
179
+
180
+ if async_results[:thread_pool_stats]
181
+ puts " Thread Pool Stats:"
182
+ puts " Max Threads: #{async_results[:thread_pool_stats][:max_threads]}"
183
+ puts " Peak Usage: #{async_results[:thread_pool_stats][:largest_length]} threads"
184
+ end
185
+ end
186
+
187
+ puts "⚔ Asynchronous execution time: #{async_time.real.round(2)} seconds"
188
+
189
+ # Performance comparison
190
+ puts "\nšŸ† PERFORMANCE COMPARISON"
191
+ puts "=" * 40
192
+ speedup = sync_time.real / async_time.real
193
+ puts "Speedup: #{speedup.round(2)}x faster with async execution"
194
+ puts "Time saved: #{(sync_time.real - async_time.real).round(2)} seconds"
195
+
196
+ if speedup > 1.5
197
+ puts "šŸš€ Significant performance improvement with async execution!"
198
+ elsif speedup > 1.2
199
+ puts "āœ… Good performance improvement with async execution"
200
+ else
201
+ puts "ā„¹ļø Minimal performance difference (tasks may be I/O bound or have dependencies)"
202
+ end
203
+
204
+ # Show task execution patterns
205
+ puts "\nšŸ“ˆ TASK EXECUTION ANALYSIS"
206
+ puts "-" * 30
207
+
208
+ # Demonstrate hierarchical async execution
209
+ puts "\n3ļøāƒ£ HIERARCHICAL ASYNC EXECUTION"
210
+ puts "Manager will coordinate parallel task delegation..."
211
+
212
+ # Create a new crew with manager for hierarchical async
213
+ hierarchical_crew = RCrewAI::Crew.new("async_hierarchical_crew", process: :hierarchical)
214
+
215
+ # Add a manager
216
+ project_manager = RCrewAI::Agent.new(
217
+ name: "project_manager",
218
+ role: "Project Coordinator",
219
+ goal: "Coordinate team efforts efficiently",
220
+ backstory: "You excel at managing parallel workstreams and ensuring optimal resource utilization.",
221
+ manager: true,
222
+ allow_delegation: true,
223
+ verbose: true
224
+ )
225
+
226
+ hierarchical_crew.add_agent(project_manager)
227
+ hierarchical_crew.add_agent(data_collector)
228
+ hierarchical_crew.add_agent(data_analyst)
229
+ hierarchical_crew.add_agent(code_reviewer)
230
+
231
+ # Create simpler tasks for hierarchical demo
232
+ quick_tasks = [
233
+ RCrewAI::Task.new(
234
+ name: "quick_research",
235
+ description: "Quick research on Ruby vs Python performance",
236
+ expected_output: "Brief comparison summary"
237
+ ),
238
+ RCrewAI::Task.new(
239
+ name: "quick_analysis",
240
+ description: "Analyze a simple dataset: [1,2,3,4,5]",
241
+ expected_output: "Basic statistical analysis"
242
+ ),
243
+ RCrewAI::Task.new(
244
+ name: "quick_code_check",
245
+ description: "Review this Ruby code: 'arr.map(&:to_i).sum'",
246
+ expected_output: "Code quality assessment"
247
+ )
248
+ ]
249
+
250
+ quick_tasks.each { |task| hierarchical_crew.add_task(task) }
251
+
252
+ hierarchical_time = Benchmark.measure do
253
+ hierarchical_results = hierarchical_crew.execute(
254
+ async: true,
255
+ max_concurrency: 3,
256
+ verbose: true
257
+ )
258
+
259
+ puts "\nšŸ“Š Hierarchical Async Results:"
260
+ puts " Manager: #{hierarchical_results[:manager]}"
261
+ puts " Process: #{hierarchical_results[:process]}"
262
+ puts " Success Rate: #{hierarchical_results[:success_rate]}%"
263
+ puts " Tasks Completed: #{hierarchical_results[:completed_tasks]}/#{hierarchical_results[:total_tasks]}"
264
+ end
265
+
266
+ puts "šŸ—ļø Hierarchical async execution time: #{hierarchical_time.real.round(2)} seconds"
267
+
268
+ # Check generated files
269
+ puts "\nšŸ“„ GENERATED FILES"
270
+ output_files = [
271
+ 'market_analysis.md',
272
+ 'tech_analysis.md',
273
+ 'executive_report.md'
274
+ ]
275
+
276
+ output_files.each do |file|
277
+ if File.exist?(file)
278
+ puts " āœ… #{file} (#{File.size(file)} bytes)"
279
+ else
280
+ puts " āŒ #{file} (not generated)"
281
+ end
282
+ end
283
+
284
+ puts "\nšŸŽÆ ASYNC EXECUTION BENEFITS DEMONSTRATED:"
285
+ puts " • Parallel task processing where dependencies allow"
286
+ puts " • Efficient resource utilization with thread pooling"
287
+ puts " • Manager coordination in hierarchical async mode"
288
+ puts " • Automatic dependency resolution across phases"
289
+ puts " • Timeout and error handling for robust execution"
290
+ puts " • Detailed performance metrics and monitoring"
291
+
292
+ puts "\n" + "=" * 50
293
+ puts "⚔ Async Execution Demo Complete!"
294
+ puts "=" * 50