rcrewai 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +99 -0
- data/CHANGELOG.md +24 -0
- data/README.md +2 -2
- data/Rakefile +53 -53
- data/bin/rcrewai +3 -3
- data/docs/mcp.md +109 -0
- data/docs/superpowers/plans/2026-05-11-llm-modernization.md +2753 -0
- data/docs/superpowers/specs/2026-05-11-llm-modernization-design.md +479 -0
- data/docs/upgrading-to-0.3.md +163 -0
- data/examples/async_execution_example.rb +82 -81
- data/examples/hierarchical_crew_example.rb +68 -72
- data/examples/human_in_the_loop_example.rb +73 -74
- data/examples/mcp_example.rb +48 -0
- data/examples/native_tools_example.rb +64 -0
- data/examples/streaming_example.rb +56 -0
- data/lib/rcrewai/agent.rb +148 -287
- data/lib/rcrewai/async_executor.rb +43 -43
- data/lib/rcrewai/cli.rb +11 -11
- data/lib/rcrewai/configuration.rb +14 -9
- data/lib/rcrewai/crew.rb +56 -39
- data/lib/rcrewai/events.rb +30 -0
- data/lib/rcrewai/human_input.rb +104 -114
- data/lib/rcrewai/legacy_react_runner.rb +172 -0
- data/lib/rcrewai/llm_client.rb +1 -1
- data/lib/rcrewai/llm_clients/anthropic.rb +174 -54
- data/lib/rcrewai/llm_clients/azure.rb +23 -128
- data/lib/rcrewai/llm_clients/base.rb +11 -7
- data/lib/rcrewai/llm_clients/google.rb +159 -95
- data/lib/rcrewai/llm_clients/ollama.rb +150 -106
- data/lib/rcrewai/llm_clients/openai.rb +140 -63
- data/lib/rcrewai/mcp/client.rb +101 -0
- data/lib/rcrewai/mcp/tool_adapter.rb +59 -0
- data/lib/rcrewai/mcp/transport/http.rb +53 -0
- data/lib/rcrewai/mcp/transport/stdio.rb +55 -0
- data/lib/rcrewai/mcp.rb +8 -0
- data/lib/rcrewai/memory.rb +45 -37
- data/lib/rcrewai/pricing.rb +34 -0
- data/lib/rcrewai/process.rb +86 -95
- data/lib/rcrewai/provider_schema.rb +38 -0
- data/lib/rcrewai/sse_parser.rb +55 -0
- data/lib/rcrewai/task.rb +56 -64
- data/lib/rcrewai/tool_runner.rb +132 -0
- data/lib/rcrewai/tool_schema.rb +97 -0
- data/lib/rcrewai/tools/base.rb +98 -37
- data/lib/rcrewai/tools/code_executor.rb +71 -74
- data/lib/rcrewai/tools/email_sender.rb +70 -78
- data/lib/rcrewai/tools/file_reader.rb +38 -30
- data/lib/rcrewai/tools/file_writer.rb +40 -38
- data/lib/rcrewai/tools/pdf_processor.rb +115 -130
- data/lib/rcrewai/tools/sql_database.rb +58 -55
- data/lib/rcrewai/tools/web_search.rb +26 -25
- data/lib/rcrewai/version.rb +2 -2
- data/lib/rcrewai.rb +18 -10
- data/rcrewai.gemspec +39 -39
- metadata +65 -47
|
@@ -1,58 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require_relative '../lib/rcrewai'
|
|
4
5
|
require 'benchmark'
|
|
5
6
|
|
|
6
|
-
puts
|
|
7
|
-
puts
|
|
7
|
+
puts '⚡ Async Execution Example'
|
|
8
|
+
puts '=' * 50
|
|
8
9
|
|
|
9
10
|
# Configure RCrewAI
|
|
10
11
|
RCrewAI.configure do |config|
|
|
11
|
-
config.llm_provider = :openai
|
|
12
|
+
config.llm_provider = :openai # Change as needed
|
|
12
13
|
config.temperature = 0.1
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
puts
|
|
16
|
+
puts '🔧 Setting up crew for async vs sync performance comparison...'
|
|
16
17
|
|
|
17
18
|
# Create a crew with multiple tasks that can benefit from parallelization
|
|
18
|
-
crew = RCrewAI::Crew.new(
|
|
19
|
+
crew = RCrewAI::Crew.new('data_processing_crew')
|
|
19
20
|
|
|
20
21
|
# Create specialized agents
|
|
21
22
|
data_collector = RCrewAI::Agent.new(
|
|
22
|
-
name:
|
|
23
|
-
role:
|
|
24
|
-
goal:
|
|
25
|
-
backstory:
|
|
23
|
+
name: 'data_collector',
|
|
24
|
+
role: 'Data Collection Specialist',
|
|
25
|
+
goal: 'Gather data from various sources efficiently',
|
|
26
|
+
backstory: 'You specialize in collecting and organizing data from multiple sources.',
|
|
26
27
|
tools: [RCrewAI::Tools::WebSearch.new],
|
|
27
28
|
verbose: true,
|
|
28
29
|
max_iterations: 3
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
data_analyst = RCrewAI::Agent.new(
|
|
32
|
-
name:
|
|
33
|
-
role:
|
|
34
|
-
goal:
|
|
35
|
-
backstory:
|
|
33
|
+
name: 'data_analyst',
|
|
34
|
+
role: 'Data Analyst',
|
|
35
|
+
goal: 'Analyze collected data and extract insights',
|
|
36
|
+
backstory: 'You excel at finding patterns and insights in datasets.',
|
|
36
37
|
tools: [RCrewAI::Tools::FileWriter.new],
|
|
37
38
|
verbose: true,
|
|
38
39
|
max_iterations: 4
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
report_writer = RCrewAI::Agent.new(
|
|
42
|
-
name:
|
|
43
|
-
role:
|
|
44
|
-
goal:
|
|
45
|
-
backstory:
|
|
43
|
+
name: 'report_writer',
|
|
44
|
+
role: 'Technical Writer',
|
|
45
|
+
goal: 'Create comprehensive reports from analysis',
|
|
46
|
+
backstory: 'You transform complex analysis into clear, actionable reports.',
|
|
46
47
|
tools: [RCrewAI::Tools::FileWriter.new, RCrewAI::Tools::FileReader.new],
|
|
47
48
|
verbose: true,
|
|
48
49
|
max_iterations: 3
|
|
49
50
|
)
|
|
50
51
|
|
|
51
52
|
code_reviewer = RCrewAI::Agent.new(
|
|
52
|
-
name:
|
|
53
|
-
role:
|
|
54
|
-
goal:
|
|
55
|
-
backstory:
|
|
53
|
+
name: 'code_reviewer',
|
|
54
|
+
role: 'Code Quality Specialist',
|
|
55
|
+
goal: 'Review and analyze code quality',
|
|
56
|
+
backstory: 'You ensure code meets quality standards and best practices.',
|
|
56
57
|
tools: [RCrewAI::Tools::CodeExecutor.new, RCrewAI::Tools::FileReader.new],
|
|
57
58
|
verbose: true,
|
|
58
59
|
max_iterations: 4
|
|
@@ -60,7 +61,7 @@ code_reviewer = RCrewAI::Agent.new(
|
|
|
60
61
|
|
|
61
62
|
# Add agents to crew
|
|
62
63
|
crew.add_agent(data_collector)
|
|
63
|
-
crew.add_agent(data_analyst)
|
|
64
|
+
crew.add_agent(data_analyst)
|
|
64
65
|
crew.add_agent(report_writer)
|
|
65
66
|
crew.add_agent(code_reviewer)
|
|
66
67
|
|
|
@@ -68,62 +69,62 @@ puts "👥 Created crew with #{crew.agents.length} specialized agents"
|
|
|
68
69
|
|
|
69
70
|
# Create tasks that can run independently (parallel execution potential)
|
|
70
71
|
data_collection_task1 = RCrewAI::Task.new(
|
|
71
|
-
name:
|
|
72
|
-
description:
|
|
72
|
+
name: 'collect_market_data',
|
|
73
|
+
description: 'Research current market trends in AI and machine learning for 2024',
|
|
73
74
|
agent: data_collector,
|
|
74
|
-
expected_output:
|
|
75
|
+
expected_output: 'Market research summary with key trends and statistics',
|
|
75
76
|
async: true
|
|
76
77
|
)
|
|
77
78
|
|
|
78
79
|
data_collection_task2 = RCrewAI::Task.new(
|
|
79
|
-
name:
|
|
80
|
-
description:
|
|
80
|
+
name: 'collect_tech_data',
|
|
81
|
+
description: 'Research emerging technologies in software development',
|
|
81
82
|
agent: data_collector,
|
|
82
|
-
expected_output:
|
|
83
|
+
expected_output: 'Technology research summary with key developments',
|
|
83
84
|
async: true
|
|
84
85
|
)
|
|
85
86
|
|
|
86
87
|
# Analysis tasks that depend on data collection
|
|
87
88
|
analysis_task1 = RCrewAI::Task.new(
|
|
88
|
-
name:
|
|
89
|
-
description:
|
|
89
|
+
name: 'analyze_market_trends',
|
|
90
|
+
description: 'Analyze the collected market data to identify opportunities and threats',
|
|
90
91
|
agent: data_analyst,
|
|
91
|
-
expected_output:
|
|
92
|
+
expected_output: 'Market analysis report with actionable insights saved to market_analysis.md',
|
|
92
93
|
context: [data_collection_task1],
|
|
93
94
|
async: true
|
|
94
95
|
)
|
|
95
96
|
|
|
96
97
|
analysis_task2 = RCrewAI::Task.new(
|
|
97
|
-
name:
|
|
98
|
-
description:
|
|
99
|
-
agent: data_analyst,
|
|
100
|
-
expected_output:
|
|
98
|
+
name: 'analyze_tech_trends',
|
|
99
|
+
description: 'Analyze emerging technology data to predict future developments',
|
|
100
|
+
agent: data_analyst,
|
|
101
|
+
expected_output: 'Technology trend analysis saved to tech_analysis.md',
|
|
101
102
|
context: [data_collection_task2],
|
|
102
103
|
async: true
|
|
103
104
|
)
|
|
104
105
|
|
|
105
106
|
# Code review task (independent)
|
|
106
107
|
code_review_task = RCrewAI::Task.new(
|
|
107
|
-
name:
|
|
108
|
+
name: 'review_sample_code',
|
|
108
109
|
description: "Review this Python code for best practices: 'def calculate(x, y): return x + y if x > 0 else 0'",
|
|
109
110
|
agent: code_reviewer,
|
|
110
|
-
expected_output:
|
|
111
|
+
expected_output: 'Code review with suggestions for improvement',
|
|
111
112
|
async: true
|
|
112
113
|
)
|
|
113
114
|
|
|
114
115
|
# Final report task (depends on all analysis)
|
|
115
116
|
final_report_task = RCrewAI::Task.new(
|
|
116
|
-
name:
|
|
117
|
-
description:
|
|
117
|
+
name: 'create_comprehensive_report',
|
|
118
|
+
description: 'Combine all analysis into a comprehensive business report with recommendations',
|
|
118
119
|
agent: report_writer,
|
|
119
|
-
expected_output:
|
|
120
|
+
expected_output: 'Executive business report combining all insights saved to executive_report.md',
|
|
120
121
|
context: [analysis_task1, analysis_task2, code_review_task],
|
|
121
122
|
async: true
|
|
122
123
|
)
|
|
123
124
|
|
|
124
125
|
# Add all tasks to crew
|
|
125
126
|
crew.add_task(data_collection_task1)
|
|
126
|
-
crew.add_task(data_collection_task2)
|
|
127
|
+
crew.add_task(data_collection_task2)
|
|
127
128
|
crew.add_task(analysis_task1)
|
|
128
129
|
crew.add_task(analysis_task2)
|
|
129
130
|
crew.add_task(code_review_task)
|
|
@@ -133,15 +134,15 @@ puts "📋 Created #{crew.tasks.length} tasks with dependency chains"
|
|
|
133
134
|
|
|
134
135
|
# Demonstrate both sync and async execution
|
|
135
136
|
puts "\n🔄 Comparing Synchronous vs Asynchronous Execution"
|
|
136
|
-
puts
|
|
137
|
+
puts '-' * 60
|
|
137
138
|
|
|
138
139
|
# First: Synchronous execution
|
|
139
140
|
puts "\n1️⃣ SYNCHRONOUS EXECUTION"
|
|
140
|
-
puts
|
|
141
|
+
puts 'Tasks will execute sequentially, one at a time...'
|
|
141
142
|
|
|
142
143
|
sync_time = Benchmark.measure do
|
|
143
144
|
sync_results = crew.execute
|
|
144
|
-
|
|
145
|
+
|
|
145
146
|
puts "\n📊 Synchronous Results:"
|
|
146
147
|
puts " Process: #{sync_results[:process]}"
|
|
147
148
|
puts " Success Rate: #{sync_results[:success_rate]}%"
|
|
@@ -157,8 +158,8 @@ crew.tasks.each do |task|
|
|
|
157
158
|
task.instance_variable_set(:@status, :pending)
|
|
158
159
|
end
|
|
159
160
|
|
|
160
|
-
puts "\n2️⃣ ASYNCHRONOUS EXECUTION"
|
|
161
|
-
puts
|
|
161
|
+
puts "\n2️⃣ ASYNCHRONOUS EXECUTION"
|
|
162
|
+
puts 'Tasks will execute in parallel where possible...'
|
|
162
163
|
|
|
163
164
|
async_time = Benchmark.measure do
|
|
164
165
|
async_results = crew.execute(
|
|
@@ -167,7 +168,7 @@ async_time = Benchmark.measure do
|
|
|
167
168
|
timeout: 300, # 5 minute timeout
|
|
168
169
|
verbose: true # Show detailed async logs
|
|
169
170
|
)
|
|
170
|
-
|
|
171
|
+
|
|
171
172
|
puts "\n📊 Asynchronous Results:"
|
|
172
173
|
puts " Process: #{async_results[:process]}"
|
|
173
174
|
puts " Execution Mode: #{async_results[:execution_mode]}"
|
|
@@ -176,9 +177,9 @@ async_time = Benchmark.measure do
|
|
|
176
177
|
puts " Completed: #{async_results[:completed_tasks]}/#{async_results[:total_tasks]}"
|
|
177
178
|
puts " Failed: #{async_results[:failed_tasks]}"
|
|
178
179
|
puts " Timeouts: #{async_results[:timed_out_tasks]}"
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
if async_results[:thread_pool_stats]
|
|
181
|
-
puts
|
|
182
|
+
puts ' Thread Pool Stats:'
|
|
182
183
|
puts " Max Threads: #{async_results[:thread_pool_stats][:max_threads]}"
|
|
183
184
|
puts " Peak Usage: #{async_results[:thread_pool_stats][:largest_length]} threads"
|
|
184
185
|
end
|
|
@@ -188,36 +189,36 @@ puts "⚡ Asynchronous execution time: #{async_time.real.round(2)} seconds"
|
|
|
188
189
|
|
|
189
190
|
# Performance comparison
|
|
190
191
|
puts "\n🏆 PERFORMANCE COMPARISON"
|
|
191
|
-
puts
|
|
192
|
+
puts '=' * 40
|
|
192
193
|
speedup = sync_time.real / async_time.real
|
|
193
194
|
puts "Speedup: #{speedup.round(2)}x faster with async execution"
|
|
194
195
|
puts "Time saved: #{(sync_time.real - async_time.real).round(2)} seconds"
|
|
195
196
|
|
|
196
197
|
if speedup > 1.5
|
|
197
|
-
puts
|
|
198
|
+
puts '🚀 Significant performance improvement with async execution!'
|
|
198
199
|
elsif speedup > 1.2
|
|
199
|
-
puts
|
|
200
|
+
puts '✅ Good performance improvement with async execution'
|
|
200
201
|
else
|
|
201
|
-
puts
|
|
202
|
+
puts 'ℹ️ Minimal performance difference (tasks may be I/O bound or have dependencies)'
|
|
202
203
|
end
|
|
203
204
|
|
|
204
205
|
# Show task execution patterns
|
|
205
206
|
puts "\n📈 TASK EXECUTION ANALYSIS"
|
|
206
|
-
puts
|
|
207
|
+
puts '-' * 30
|
|
207
208
|
|
|
208
209
|
# Demonstrate hierarchical async execution
|
|
209
210
|
puts "\n3️⃣ HIERARCHICAL ASYNC EXECUTION"
|
|
210
|
-
puts
|
|
211
|
+
puts 'Manager will coordinate parallel task delegation...'
|
|
211
212
|
|
|
212
213
|
# Create a new crew with manager for hierarchical async
|
|
213
|
-
hierarchical_crew = RCrewAI::Crew.new(
|
|
214
|
+
hierarchical_crew = RCrewAI::Crew.new('async_hierarchical_crew', process: :hierarchical)
|
|
214
215
|
|
|
215
216
|
# Add a manager
|
|
216
217
|
project_manager = RCrewAI::Agent.new(
|
|
217
|
-
name:
|
|
218
|
-
role:
|
|
219
|
-
goal:
|
|
220
|
-
backstory:
|
|
218
|
+
name: 'project_manager',
|
|
219
|
+
role: 'Project Coordinator',
|
|
220
|
+
goal: 'Coordinate team efforts efficiently',
|
|
221
|
+
backstory: 'You excel at managing parallel workstreams and ensuring optimal resource utilization.',
|
|
221
222
|
manager: true,
|
|
222
223
|
allow_delegation: true,
|
|
223
224
|
verbose: true
|
|
@@ -231,19 +232,19 @@ hierarchical_crew.add_agent(code_reviewer)
|
|
|
231
232
|
# Create simpler tasks for hierarchical demo
|
|
232
233
|
quick_tasks = [
|
|
233
234
|
RCrewAI::Task.new(
|
|
234
|
-
name:
|
|
235
|
-
description:
|
|
236
|
-
expected_output:
|
|
235
|
+
name: 'quick_research',
|
|
236
|
+
description: 'Quick research on Ruby vs Python performance',
|
|
237
|
+
expected_output: 'Brief comparison summary'
|
|
237
238
|
),
|
|
238
239
|
RCrewAI::Task.new(
|
|
239
|
-
name:
|
|
240
|
-
description:
|
|
241
|
-
expected_output:
|
|
240
|
+
name: 'quick_analysis',
|
|
241
|
+
description: 'Analyze a simple dataset: [1,2,3,4,5]',
|
|
242
|
+
expected_output: 'Basic statistical analysis'
|
|
242
243
|
),
|
|
243
244
|
RCrewAI::Task.new(
|
|
244
|
-
name:
|
|
245
|
+
name: 'quick_code_check',
|
|
245
246
|
description: "Review this Ruby code: 'arr.map(&:to_i).sum'",
|
|
246
|
-
expected_output:
|
|
247
|
+
expected_output: 'Code quality assessment'
|
|
247
248
|
)
|
|
248
249
|
]
|
|
249
250
|
|
|
@@ -255,10 +256,10 @@ hierarchical_time = Benchmark.measure do
|
|
|
255
256
|
max_concurrency: 3,
|
|
256
257
|
verbose: true
|
|
257
258
|
)
|
|
258
|
-
|
|
259
|
+
|
|
259
260
|
puts "\n📊 Hierarchical Async Results:"
|
|
260
261
|
puts " Manager: #{hierarchical_results[:manager]}"
|
|
261
|
-
puts " Process: #{hierarchical_results[:process]}"
|
|
262
|
+
puts " Process: #{hierarchical_results[:process]}"
|
|
262
263
|
puts " Success Rate: #{hierarchical_results[:success_rate]}%"
|
|
263
264
|
puts " Tasks Completed: #{hierarchical_results[:completed_tasks]}/#{hierarchical_results[:total_tasks]}"
|
|
264
265
|
end
|
|
@@ -269,7 +270,7 @@ puts "🏗️ Hierarchical async execution time: #{hierarchical_time.real.round
|
|
|
269
270
|
puts "\n📄 GENERATED FILES"
|
|
270
271
|
output_files = [
|
|
271
272
|
'market_analysis.md',
|
|
272
|
-
'tech_analysis.md',
|
|
273
|
+
'tech_analysis.md',
|
|
273
274
|
'executive_report.md'
|
|
274
275
|
]
|
|
275
276
|
|
|
@@ -282,13 +283,13 @@ output_files.each do |file|
|
|
|
282
283
|
end
|
|
283
284
|
|
|
284
285
|
puts "\n🎯 ASYNC EXECUTION BENEFITS DEMONSTRATED:"
|
|
285
|
-
puts
|
|
286
|
-
puts
|
|
287
|
-
puts
|
|
288
|
-
puts
|
|
289
|
-
puts
|
|
290
|
-
puts
|
|
291
|
-
|
|
292
|
-
puts "\n
|
|
293
|
-
puts
|
|
294
|
-
puts
|
|
286
|
+
puts ' • Parallel task processing where dependencies allow'
|
|
287
|
+
puts ' • Efficient resource utilization with thread pooling'
|
|
288
|
+
puts ' • Manager coordination in hierarchical async mode'
|
|
289
|
+
puts ' • Automatic dependency resolution across phases'
|
|
290
|
+
puts ' • Timeout and error handling for robust execution'
|
|
291
|
+
puts ' • Detailed performance metrics and monitoring'
|
|
292
|
+
|
|
293
|
+
puts "\n#{'=' * 50}"
|
|
294
|
+
puts '⚡ Async Execution Demo Complete!'
|
|
295
|
+
puts '=' * 50
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require_relative '../lib/rcrewai'
|
|
4
5
|
|
|
5
|
-
puts
|
|
6
|
-
puts
|
|
6
|
+
puts '🏗️ Hierarchical Crew Process Example'
|
|
7
|
+
puts '=' * 50
|
|
7
8
|
|
|
8
9
|
# Configure RCrewAI
|
|
9
10
|
RCrewAI.configure do |config|
|
|
10
|
-
config.llm_provider = :openai
|
|
11
|
+
config.llm_provider = :openai # Change as needed
|
|
11
12
|
config.temperature = 0.1
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
# Create a hierarchical crew
|
|
15
|
-
crew = RCrewAI::Crew.new(
|
|
16
|
+
crew = RCrewAI::Crew.new('product_development_crew', process: :hierarchical, verbose: true)
|
|
16
17
|
|
|
17
|
-
puts
|
|
18
|
+
puts '📋 Creating hierarchical crew with manager and specialists...'
|
|
18
19
|
|
|
19
20
|
# Create a manager agent
|
|
20
21
|
project_manager = RCrewAI::Agent.new(
|
|
21
|
-
name:
|
|
22
|
-
role:
|
|
23
|
-
goal:
|
|
24
|
-
backstory:
|
|
25
|
-
manager: true,
|
|
22
|
+
name: 'project_manager',
|
|
23
|
+
role: 'Senior Project Manager',
|
|
24
|
+
goal: 'Coordinate team efforts and ensure project success',
|
|
25
|
+
backstory: 'You are an experienced project manager with 10+ years leading cross-functional teams. You excel at delegation, coordination, and ensuring deliverables meet requirements.',
|
|
26
|
+
manager: true, # This makes the agent a manager
|
|
26
27
|
allow_delegation: true,
|
|
27
28
|
tools: [RCrewAI::Tools::FileWriter.new],
|
|
28
29
|
verbose: true,
|
|
@@ -31,28 +32,28 @@ project_manager = RCrewAI::Agent.new(
|
|
|
31
32
|
|
|
32
33
|
# Create specialist agents
|
|
33
34
|
market_researcher = RCrewAI::Agent.new(
|
|
34
|
-
name:
|
|
35
|
-
role:
|
|
36
|
-
goal:
|
|
37
|
-
backstory:
|
|
35
|
+
name: 'market_researcher',
|
|
36
|
+
role: 'Market Research Specialist',
|
|
37
|
+
goal: 'Conduct thorough market analysis and competitive research',
|
|
38
|
+
backstory: 'You are a market research expert who excels at finding market opportunities, analyzing competitors, and identifying customer needs.',
|
|
38
39
|
tools: [RCrewAI::Tools::WebSearch.new(max_results: 10)],
|
|
39
40
|
verbose: true
|
|
40
41
|
)
|
|
41
42
|
|
|
42
43
|
product_designer = RCrewAI::Agent.new(
|
|
43
|
-
name:
|
|
44
|
-
role:
|
|
45
|
-
goal:
|
|
46
|
-
backstory:
|
|
44
|
+
name: 'product_designer',
|
|
45
|
+
role: 'Senior Product Designer',
|
|
46
|
+
goal: 'Design user-centered products and experiences',
|
|
47
|
+
backstory: 'You are a product designer with expertise in UX/UI design, user research, and product strategy. You create designs that solve real user problems.',
|
|
47
48
|
tools: [RCrewAI::Tools::FileWriter.new],
|
|
48
49
|
verbose: true
|
|
49
50
|
)
|
|
50
51
|
|
|
51
52
|
technical_lead = RCrewAI::Agent.new(
|
|
52
|
-
name:
|
|
53
|
-
role:
|
|
54
|
-
goal:
|
|
55
|
-
backstory:
|
|
53
|
+
name: 'technical_lead',
|
|
54
|
+
role: 'Technical Lead',
|
|
55
|
+
goal: 'Define technical architecture and implementation strategy',
|
|
56
|
+
backstory: 'You are a senior software architect who designs scalable, maintainable systems. You excel at technical planning and risk assessment.',
|
|
56
57
|
tools: [
|
|
57
58
|
RCrewAI::Tools::FileWriter.new,
|
|
58
59
|
RCrewAI::Tools::FileReader.new
|
|
@@ -61,12 +62,12 @@ technical_lead = RCrewAI::Agent.new(
|
|
|
61
62
|
)
|
|
62
63
|
|
|
63
64
|
# Add agents to crew
|
|
64
|
-
crew.add_agent(project_manager)
|
|
65
|
+
crew.add_agent(project_manager) # Manager added first
|
|
65
66
|
crew.add_agent(market_researcher)
|
|
66
|
-
crew.add_agent(product_designer)
|
|
67
|
+
crew.add_agent(product_designer)
|
|
67
68
|
crew.add_agent(technical_lead)
|
|
68
69
|
|
|
69
|
-
puts
|
|
70
|
+
puts '👥 Crew created with:'
|
|
70
71
|
puts " 📊 Manager: #{project_manager.name}"
|
|
71
72
|
puts " 🔍 Specialists: #{crew.agents.length - 1} agents"
|
|
72
73
|
|
|
@@ -77,31 +78,31 @@ project_manager.add_subordinate(technical_lead)
|
|
|
77
78
|
|
|
78
79
|
# Create tasks that will be delegated by the manager
|
|
79
80
|
market_research_task = RCrewAI::Task.new(
|
|
80
|
-
name:
|
|
81
|
-
description:
|
|
82
|
-
expected_output:
|
|
81
|
+
name: 'market_analysis',
|
|
82
|
+
description: 'Conduct comprehensive market research for a new AI-powered productivity app. Focus on market size, target demographics, competitors, pricing strategies, and key opportunities.',
|
|
83
|
+
expected_output: 'Detailed market analysis report with actionable insights and recommendations',
|
|
83
84
|
max_retries: 2
|
|
84
85
|
)
|
|
85
86
|
|
|
86
87
|
product_design_task = RCrewAI::Task.new(
|
|
87
|
-
name:
|
|
88
|
-
description:
|
|
89
|
-
expected_output:
|
|
90
|
-
context: [market_research_task]
|
|
88
|
+
name: 'product_design',
|
|
89
|
+
description: 'Design the core user experience and feature set for an AI productivity app based on market research. Include user personas, key features, user journey, and design principles.',
|
|
90
|
+
expected_output: 'Product design document with UX strategy, feature specifications, and user flow diagrams',
|
|
91
|
+
context: [market_research_task] # Depends on market research
|
|
91
92
|
)
|
|
92
93
|
|
|
93
94
|
technical_architecture_task = RCrewAI::Task.new(
|
|
94
|
-
name:
|
|
95
|
-
description:
|
|
96
|
-
expected_output:
|
|
97
|
-
context: [market_research_task, product_design_task]
|
|
95
|
+
name: 'technical_architecture',
|
|
96
|
+
description: 'Define the technical architecture for an AI productivity app. Include technology stack, system design, scalability considerations, AI integration approach, and implementation roadmap.',
|
|
97
|
+
expected_output: 'Technical architecture document with system design, technology recommendations, and implementation plan',
|
|
98
|
+
context: [market_research_task, product_design_task] # Depends on both previous tasks
|
|
98
99
|
)
|
|
99
100
|
|
|
100
101
|
project_plan_task = RCrewAI::Task.new(
|
|
101
|
-
name:
|
|
102
|
-
description:
|
|
103
|
-
expected_output:
|
|
104
|
-
agent: project_manager,
|
|
102
|
+
name: 'project_planning',
|
|
103
|
+
description: 'Create comprehensive project plan integrating market research, product design, and technical architecture. Include timeline, milestones, resource requirements, and risk assessment.',
|
|
104
|
+
expected_output: 'Complete project plan with timelines, deliverables, and coordination strategy saved to project_plan.md',
|
|
105
|
+
agent: project_manager, # Manager handles this directly
|
|
105
106
|
context: [market_research_task, product_design_task, technical_architecture_task]
|
|
106
107
|
)
|
|
107
108
|
|
|
@@ -111,7 +112,7 @@ crew.add_task(product_design_task)
|
|
|
111
112
|
crew.add_task(technical_architecture_task)
|
|
112
113
|
crew.add_task(project_plan_task)
|
|
113
114
|
|
|
114
|
-
puts
|
|
115
|
+
puts '📋 Tasks created with dependencies:'
|
|
115
116
|
crew.tasks.each_with_index do |task, i|
|
|
116
117
|
deps = task.context&.length || 0
|
|
117
118
|
puts " #{i + 1}. #{task.name} (#{deps} dependencies)"
|
|
@@ -119,75 +120,70 @@ end
|
|
|
119
120
|
|
|
120
121
|
# Execute the hierarchical crew
|
|
121
122
|
puts "\n🚀 Starting hierarchical execution..."
|
|
122
|
-
puts
|
|
123
|
+
puts 'The project manager will coordinate and delegate tasks to specialists'
|
|
123
124
|
|
|
124
125
|
begin
|
|
125
126
|
start_time = Time.now
|
|
126
|
-
|
|
127
|
+
|
|
127
128
|
# Execute with hierarchical process
|
|
128
129
|
results = crew.execute
|
|
129
|
-
|
|
130
|
+
|
|
130
131
|
execution_time = Time.now - start_time
|
|
131
|
-
|
|
132
|
+
|
|
132
133
|
# Display results
|
|
133
|
-
puts "\n
|
|
134
|
-
puts
|
|
135
|
-
puts
|
|
134
|
+
puts "\n#{'=' * 60}"
|
|
135
|
+
puts '🎉 HIERARCHICAL EXECUTION COMPLETED'
|
|
136
|
+
puts '=' * 60
|
|
136
137
|
puts "Total execution time: #{execution_time.round(2)} seconds"
|
|
137
138
|
puts "Process type: #{results[:process]}"
|
|
138
139
|
puts "Success rate: #{results[:success_rate]}%"
|
|
139
140
|
puts "Completed tasks: #{results[:completed_tasks]}/#{results[:total_tasks]}"
|
|
140
|
-
|
|
141
|
+
|
|
141
142
|
# Show task results
|
|
142
143
|
puts "\n📊 Task Results:"
|
|
143
144
|
results[:results].each do |result|
|
|
144
|
-
status_icon = result[:status] == :completed ?
|
|
145
|
+
status_icon = result[:status] == :completed ? '✅' : '❌'
|
|
145
146
|
agent_name = result[:assigned_agent]&.name || result[:task].agent&.name
|
|
146
|
-
|
|
147
|
+
|
|
147
148
|
puts "#{status_icon} #{result[:task].name}"
|
|
148
149
|
puts " Assigned to: #{agent_name}"
|
|
149
150
|
puts " Status: #{result[:status]}"
|
|
150
|
-
|
|
151
|
-
if result[:phase]
|
|
152
|
-
|
|
153
|
-
end
|
|
154
|
-
|
|
151
|
+
|
|
152
|
+
puts " Phase: #{result[:phase]}" if result[:phase]
|
|
153
|
+
|
|
155
154
|
if result[:status] == :completed
|
|
156
155
|
preview = result[:result][0..150]
|
|
157
|
-
preview +=
|
|
156
|
+
preview += '...' if result[:result].length > 150
|
|
158
157
|
puts " Result: #{preview}"
|
|
159
158
|
else
|
|
160
159
|
puts " Error: #{result[:result]}"
|
|
161
160
|
end
|
|
162
|
-
|
|
161
|
+
|
|
163
162
|
puts
|
|
164
163
|
end
|
|
165
|
-
|
|
164
|
+
|
|
166
165
|
# Show delegation insights
|
|
167
|
-
puts
|
|
166
|
+
puts '🎯 Hierarchical Process Insights:'
|
|
168
167
|
puts " • Manager coordinated #{crew.agents.length - 1} specialists"
|
|
169
|
-
puts
|
|
170
|
-
puts
|
|
171
|
-
puts
|
|
172
|
-
|
|
168
|
+
puts ' • Tasks were delegated based on agent expertise'
|
|
169
|
+
puts ' • Dependencies were handled automatically'
|
|
170
|
+
puts ' • Cross-phase coordination was managed'
|
|
171
|
+
|
|
173
172
|
# Check for output files
|
|
174
173
|
if File.exist?('project_plan.md')
|
|
175
174
|
puts "\n📄 Generated Files:"
|
|
176
175
|
puts " ✅ project_plan.md (#{File.size('project_plan.md')} bytes)"
|
|
177
176
|
end
|
|
178
|
-
|
|
179
177
|
rescue RCrewAI::ProcessError => e
|
|
180
178
|
puts "\n❌ Process Error: #{e.message}"
|
|
181
|
-
puts
|
|
182
|
-
|
|
179
|
+
puts 'This might indicate issues with agent setup or task dependencies'
|
|
183
180
|
rescue RCrewAI::AgentError => e
|
|
184
181
|
puts "\n❌ Agent Error: #{e.message}"
|
|
185
|
-
|
|
186
|
-
rescue => e
|
|
182
|
+
rescue StandardError => e
|
|
187
183
|
puts "\n💥 Unexpected error: #{e.message}"
|
|
188
184
|
puts e.backtrace.first(3).join("\n") if ENV['DEBUG']
|
|
189
185
|
end
|
|
190
186
|
|
|
191
|
-
puts "\n
|
|
192
|
-
puts
|
|
193
|
-
puts
|
|
187
|
+
puts "\n#{'=' * 50}"
|
|
188
|
+
puts '🏗️ Hierarchical Crew Example Complete!'
|
|
189
|
+
puts '=' * 50
|