rcrewai 0.1.0 → 0.2.1
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/README.md +32 -0
- data/docs/api/agent.md +429 -0
- data/docs/api/task.md +494 -0
- data/docs/examples/api-integration.md +829 -0
- data/docs/examples/async-execution.md +893 -0
- data/docs/examples/code-review-crew.md +660 -0
- data/docs/examples/content-marketing-pipeline.md +681 -0
- data/docs/examples/custom-tools.md +1224 -0
- data/docs/examples/customer-support.md +717 -0
- data/docs/examples/data-analysis-team.md +677 -0
- data/docs/examples/database-operations.md +1298 -0
- data/docs/examples/ecommerce-operations.md +990 -0
- data/docs/examples/financial-analysis.md +857 -0
- data/docs/examples/hierarchical-crew.md +479 -0
- data/docs/examples/product-development.md +688 -0
- data/docs/examples/production-ready-crew.md +384 -408
- data/docs/examples/research-development.md +1225 -0
- data/docs/examples/social-media.md +1073 -0
- data/docs/examples/task-automation.md +527 -0
- data/docs/examples/tool-composition.md +1075 -0
- data/docs/examples/web-scraping.md +1201 -0
- data/docs/tutorials/advanced-agents.md +1014 -0
- data/docs/tutorials/custom-tools.md +1242 -0
- data/docs/tutorials/deployment.md +1836 -0
- data/docs/tutorials/index.md +184 -0
- data/docs/tutorials/multiple-crews.md +1692 -0
- data/lib/rcrewai/llm_clients/anthropic.rb +1 -1
- data/lib/rcrewai/version.rb +1 -1
- data/rcrewai.gemspec +21 -2
- metadata +47 -5
@@ -1,485 +1,461 @@
|
|
1
1
|
---
|
2
2
|
layout: example
|
3
|
-
title: Production-Ready
|
4
|
-
description:
|
3
|
+
title: Production-Ready Crew
|
4
|
+
description: Enterprise-grade AI crew with comprehensive error handling, monitoring, and production features
|
5
5
|
---
|
6
6
|
|
7
|
-
# Production-Ready
|
7
|
+
# Production-Ready Crew
|
8
8
|
|
9
|
-
This example demonstrates a
|
9
|
+
This example demonstrates how to build a production-ready RCrewAI crew with enterprise-grade features including comprehensive error handling, monitoring, logging, security controls, and deployment considerations.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Overview
|
12
12
|
|
13
|
-
We'll
|
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
|
13
|
+
We'll create a customer support automation crew with:
|
19
14
|
|
20
|
-
|
15
|
+
- **Robust Error Handling**: Comprehensive exception handling and recovery
|
16
|
+
- **Monitoring & Observability**: Detailed metrics, logging, and health checks
|
17
|
+
- **Security Controls**: Input validation, access controls, and audit logging
|
18
|
+
- **Performance Optimization**: Caching, connection pooling, and resource management
|
19
|
+
- **Scalability Features**: Load balancing, concurrency controls, and auto-scaling
|
20
|
+
- **Production Deployment**: Docker containers, configuration management, and CI/CD
|
21
21
|
|
22
|
-
|
23
|
-
#!/usr/bin/env ruby
|
22
|
+
## Complete Production Implementation
|
24
23
|
|
24
|
+
```ruby
|
25
25
|
require 'rcrewai'
|
26
26
|
require 'logger'
|
27
|
-
require '
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
require 'json'
|
28
|
+
require 'redis'
|
29
|
+
|
30
|
+
# ===== PRODUCTION CONFIGURATION =====
|
31
|
+
|
32
|
+
class ProductionConfig
|
33
|
+
def self.setup
|
34
|
+
# Environment-based configuration
|
35
|
+
@env = ENV.fetch('RAILS_ENV', 'development')
|
36
|
+
@redis_url = ENV.fetch('REDIS_URL', 'redis://localhost:6379')
|
37
|
+
|
38
|
+
# Configure RCrewAI for production
|
39
|
+
RCrewAI.configure do |config|
|
40
|
+
config.llm_provider = ENV.fetch('LLM_PROVIDER', 'openai').to_sym
|
41
|
+
config.temperature = ENV.fetch('LLM_TEMPERATURE', '0.1').to_f
|
42
|
+
config.max_tokens = ENV.fetch('LLM_MAX_TOKENS', '4000').to_i
|
43
|
+
|
44
|
+
# Provider-specific configuration
|
45
|
+
case config.llm_provider
|
46
|
+
when :openai
|
47
|
+
config.openai_api_key = ENV.fetch('OPENAI_API_KEY')
|
48
|
+
when :anthropic
|
49
|
+
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY')
|
50
|
+
when :azure
|
51
|
+
config.azure_api_key = ENV.fetch('AZURE_OPENAI_API_KEY')
|
52
|
+
config.base_url = ENV.fetch('AZURE_OPENAI_ENDPOINT')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Setup Redis for caching and coordination
|
57
|
+
@redis = Redis.new(url: @redis_url)
|
58
|
+
|
59
|
+
# Setup structured logging
|
60
|
+
@logger = setup_logger
|
61
|
+
|
62
|
+
[@redis, @logger]
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def self.setup_logger
|
68
|
+
logger = Logger.new($stdout)
|
69
|
+
logger.level = ENV.fetch('LOG_LEVEL', 'INFO').upcase.constantize rescue Logger::INFO
|
70
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
71
|
+
{
|
72
|
+
timestamp: datetime.iso8601,
|
73
|
+
level: severity,
|
74
|
+
component: progname || 'rcrewai',
|
75
|
+
message: msg,
|
76
|
+
environment: @env,
|
77
|
+
process_id: Process.pid
|
78
|
+
}.to_json + "\n"
|
79
|
+
end
|
80
|
+
logger
|
43
81
|
end
|
44
82
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
puts "Please check your API key environment variables"
|
49
|
-
exit 1
|
83
|
+
class << self
|
84
|
+
attr_reader :redis, :logger, :env
|
85
|
+
end
|
50
86
|
end
|
51
87
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
88
|
+
# Initialize production configuration
|
89
|
+
ProductionConfig.setup
|
90
|
+
redis = ProductionConfig.redis
|
91
|
+
logger = ProductionConfig.logger
|
55
92
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
93
|
+
# ===== PRODUCTION-GRADE BASE CLASSES =====
|
94
|
+
|
95
|
+
class ProductionAgent < RCrewAI::Agent
|
96
|
+
def initialize(**options)
|
97
|
+
super
|
98
|
+
@logger = ProductionConfig.logger
|
99
|
+
@start_time = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def execute_task(task)
|
103
|
+
@start_time = Time.now
|
104
|
+
task_labels = { agent_name: name, task_name: task.name }
|
105
|
+
|
106
|
+
begin
|
107
|
+
@logger.info("Task execution started", task_labels)
|
108
|
+
|
109
|
+
result = super(task)
|
110
|
+
|
111
|
+
duration = Time.now - @start_time
|
112
|
+
@logger.info("Task execution completed", task_labels.merge(
|
113
|
+
duration: duration,
|
114
|
+
result_length: result.length
|
115
|
+
))
|
116
|
+
|
117
|
+
result
|
118
|
+
|
119
|
+
rescue => e
|
120
|
+
duration = Time.now - @start_time
|
121
|
+
|
122
|
+
@logger.error("Task execution failed", task_labels.merge(
|
123
|
+
error: e.message,
|
124
|
+
error_class: e.class.name,
|
125
|
+
duration: duration
|
126
|
+
))
|
127
|
+
|
128
|
+
raise
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# ===== CUSTOMER SUPPORT CREW =====
|
74
134
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
135
|
+
logger.info("Initializing production customer support crew")
|
136
|
+
|
137
|
+
# Create production crew
|
138
|
+
support_crew = RCrewAI::Crew.new("customer_support_crew", process: :hierarchical)
|
139
|
+
|
140
|
+
# Support Manager
|
141
|
+
support_manager = ProductionAgent.new(
|
142
|
+
name: "support_manager",
|
143
|
+
role: "Customer Support Manager",
|
144
|
+
goal: "Efficiently coordinate customer support operations and ensure customer satisfaction",
|
145
|
+
backstory: "You are an experienced customer support manager with expertise in escalation handling, team coordination, and customer relationship management.",
|
146
|
+
manager: true,
|
147
|
+
allow_delegation: true,
|
80
148
|
tools: [
|
81
|
-
RCrewAI::Tools::
|
82
|
-
|
83
|
-
|
84
|
-
RCrewAI::Tools::FileWriter.new(
|
85
|
-
allowed_extensions: %w[.json .csv .md .txt],
|
86
|
-
create_directories: true
|
87
|
-
)
|
149
|
+
RCrewAI::Tools::WebSearch.new(max_results: 5),
|
150
|
+
RCrewAI::Tools::FileReader.new,
|
151
|
+
RCrewAI::Tools::FileWriter.new
|
88
152
|
],
|
89
|
-
verbose:
|
90
|
-
|
91
|
-
allow_delegation: false
|
153
|
+
verbose: ProductionConfig.env == 'development',
|
154
|
+
max_execution_time: 600
|
92
155
|
)
|
93
156
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
157
|
+
# Technical Support Specialist
|
158
|
+
tech_support = ProductionAgent.new(
|
159
|
+
name: "tech_support_specialist",
|
160
|
+
role: "Technical Support Specialist",
|
161
|
+
goal: "Resolve technical issues and provide expert technical guidance",
|
162
|
+
backstory: "You are a senior technical support specialist with deep knowledge of software systems, APIs, and troubleshooting.",
|
99
163
|
tools: [
|
164
|
+
RCrewAI::Tools::WebSearch.new(max_results: 10),
|
100
165
|
RCrewAI::Tools::FileReader.new,
|
101
|
-
RCrewAI::Tools::FileWriter.new
|
102
|
-
max_file_size: 20_000_000,
|
103
|
-
create_directories: true
|
104
|
-
)
|
166
|
+
RCrewAI::Tools::FileWriter.new
|
105
167
|
],
|
106
|
-
verbose:
|
107
|
-
|
108
|
-
allow_delegation: true
|
168
|
+
verbose: ProductionConfig.env == 'development',
|
169
|
+
max_execution_time: 900
|
109
170
|
)
|
110
171
|
|
111
|
-
#
|
112
|
-
|
113
|
-
|
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
|
-
)
|
172
|
+
# Add agents to crew
|
173
|
+
support_crew.add_agent(support_manager)
|
174
|
+
support_crew.add_agent(tech_support)
|
143
175
|
|
144
|
-
#
|
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
|
-
)
|
176
|
+
# ===== PRODUCTION TASK DEFINITIONS =====
|
167
177
|
|
168
|
-
#
|
169
|
-
|
170
|
-
name: "
|
171
|
-
description:
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
}
|
178
|
+
# Customer Issue Analysis
|
179
|
+
issue_analysis = RCrewAI::Task.new(
|
180
|
+
name: "customer_issue_analysis",
|
181
|
+
description: "Analyze incoming customer support tickets to categorize issues, assess severity, and determine initial response strategy.",
|
182
|
+
expected_output: "Structured analysis with issue categorization, severity assessment, and recommended response strategy",
|
183
|
+
async: true,
|
184
|
+
max_retries: 3,
|
185
|
+
retry_delay: 10
|
190
186
|
)
|
191
187
|
|
192
|
-
#
|
193
|
-
|
194
|
-
name: "
|
195
|
-
description:
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
}
|
188
|
+
# Technical Issue Resolution
|
189
|
+
technical_resolution = RCrewAI::Task.new(
|
190
|
+
name: "technical_issue_resolution",
|
191
|
+
description: "Investigate and resolve technical issues reported by customers. Provide step-by-step solutions and code examples.",
|
192
|
+
expected_output: "Comprehensive technical solution with troubleshooting steps and configuration guidance",
|
193
|
+
context: [issue_analysis],
|
194
|
+
async: true,
|
195
|
+
max_retries: 2
|
216
196
|
)
|
217
197
|
|
218
|
-
# Add
|
219
|
-
|
220
|
-
|
221
|
-
crew.add_task(executive_report_task)
|
222
|
-
crew.add_task(presentation_task)
|
223
|
-
|
224
|
-
puts "📋 #{crew.tasks.length} tasks defined with dependencies"
|
198
|
+
# Add tasks to crew
|
199
|
+
support_crew.add_task(issue_analysis)
|
200
|
+
support_crew.add_task(technical_resolution)
|
225
201
|
|
226
|
-
#
|
227
|
-
start_time = Time.now
|
202
|
+
# ===== PRODUCTION EXECUTION WITH MONITORING =====
|
228
203
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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"
|
204
|
+
class ProductionExecutor
|
205
|
+
def initialize(crew, logger)
|
206
|
+
@crew = crew
|
207
|
+
@logger = logger
|
208
|
+
@execution_id = SecureRandom.uuid
|
209
|
+
end
|
243
210
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
211
|
+
def execute
|
212
|
+
@logger.info("Starting production crew execution", {
|
213
|
+
execution_id: @execution_id,
|
214
|
+
crew_name: @crew.name,
|
215
|
+
agent_count: @crew.agents.length,
|
216
|
+
task_count: @crew.tasks.length
|
217
|
+
})
|
218
|
+
|
219
|
+
start_time = Time.now
|
250
220
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
221
|
+
begin
|
222
|
+
results = @crew.execute(
|
223
|
+
async: true,
|
224
|
+
max_concurrency: ENV.fetch('MAX_CONCURRENCY', '3').to_i
|
225
|
+
)
|
226
|
+
|
227
|
+
duration = Time.now - start_time
|
228
|
+
|
229
|
+
@logger.info("Crew execution completed", {
|
230
|
+
execution_id: @execution_id,
|
231
|
+
duration: duration,
|
232
|
+
success_rate: results[:success_rate]
|
233
|
+
})
|
234
|
+
|
235
|
+
generate_execution_report(results, duration)
|
236
|
+
|
237
|
+
results
|
238
|
+
|
239
|
+
rescue => e
|
240
|
+
duration = Time.now - start_time
|
241
|
+
|
242
|
+
@logger.error("Crew execution failed", {
|
243
|
+
execution_id: @execution_id,
|
244
|
+
error: e.message,
|
245
|
+
duration: duration
|
246
|
+
})
|
247
|
+
|
248
|
+
raise
|
256
249
|
end
|
257
250
|
end
|
258
251
|
|
259
|
-
|
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
|
-
]
|
252
|
+
private
|
277
253
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
254
|
+
def generate_execution_report(results, duration)
|
255
|
+
report = {
|
256
|
+
execution_id: @execution_id,
|
257
|
+
timestamp: Time.now.iso8601,
|
258
|
+
crew_name: @crew.name,
|
259
|
+
duration: duration,
|
260
|
+
metrics: {
|
261
|
+
total_tasks: results[:total_tasks],
|
262
|
+
completed_tasks: results[:completed_tasks],
|
263
|
+
success_rate: results[:success_rate]
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
File.write("execution_report_#{@execution_id}.json", report.to_json)
|
268
|
+
@logger.info("Execution report generated")
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# ===== HEALTH CHECKS =====
|
273
|
+
|
274
|
+
class HealthChecker
|
275
|
+
def self.check_system_health
|
276
|
+
health_status = {
|
277
|
+
timestamp: Time.now.iso8601,
|
278
|
+
status: 'healthy',
|
279
|
+
checks: {}
|
280
|
+
}
|
281
|
+
|
282
|
+
# Check Redis connectivity
|
283
|
+
begin
|
284
|
+
ProductionConfig.redis.ping
|
285
|
+
health_status[:checks][:redis] = { status: 'healthy' }
|
286
|
+
rescue => e
|
287
|
+
health_status[:checks][:redis] = { status: 'unhealthy', message: e.message }
|
288
|
+
health_status[:status] = 'unhealthy'
|
284
289
|
end
|
290
|
+
|
291
|
+
health_status
|
285
292
|
end
|
293
|
+
end
|
294
|
+
|
295
|
+
# ===== PRODUCTION EXECUTION =====
|
296
|
+
|
297
|
+
if __FILE__ == $0
|
298
|
+
logger.info("Starting production customer support crew")
|
286
299
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
rescue RCrewAI::AgentError => e
|
295
|
-
puts "\n❌ Agent error: #{e.message}"
|
296
|
-
logger.error "Agent error: #{e.message}"
|
300
|
+
# Pre-execution health check
|
301
|
+
health_status = HealthChecker.check_system_health
|
302
|
+
if health_status[:status] == 'unhealthy'
|
303
|
+
logger.error("System health check failed", health_status)
|
304
|
+
exit 1
|
305
|
+
end
|
297
306
|
|
298
|
-
|
299
|
-
|
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")
|
307
|
+
# Execute crew with production monitoring
|
308
|
+
executor = ProductionExecutor.new(support_crew, logger)
|
303
309
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
310
|
+
begin
|
311
|
+
results = executor.execute
|
312
|
+
|
313
|
+
puts "\n🎉 PRODUCTION EXECUTION COMPLETED"
|
314
|
+
puts "Success Rate: #{results[:success_rate]}%"
|
315
|
+
puts "Completed Tasks: #{results[:completed_tasks]}/#{results[:total_tasks]}"
|
316
|
+
|
317
|
+
rescue => e
|
318
|
+
logger.error("Production execution failed", { error: e.message })
|
319
|
+
puts "\n❌ PRODUCTION EXECUTION FAILED"
|
320
|
+
exit 1
|
321
|
+
end
|
309
322
|
end
|
323
|
+
```
|
310
324
|
|
311
|
-
|
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"
|
325
|
+
## Docker Configuration
|
316
326
|
|
317
|
-
|
318
|
-
```
|
327
|
+
**Dockerfile:**
|
328
|
+
```dockerfile
|
329
|
+
FROM ruby:3.1-alpine
|
319
330
|
|
320
|
-
|
331
|
+
WORKDIR /app
|
321
332
|
|
322
|
-
|
333
|
+
COPY Gemfile Gemfile.lock ./
|
334
|
+
RUN bundle install --without development test
|
323
335
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
336
|
+
COPY . .
|
337
|
+
|
338
|
+
ENV RAILS_ENV=production
|
339
|
+
ENV LOG_LEVEL=INFO
|
340
|
+
|
341
|
+
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
|
342
|
+
CMD ruby -e "puts HealthChecker.check_system_health[:status]" || exit 1
|
343
|
+
|
344
|
+
CMD ["ruby", "production_crew.rb"]
|
331
345
|
```
|
332
346
|
|
333
|
-
|
334
|
-
```
|
335
|
-
|
347
|
+
**docker-compose.yml:**
|
348
|
+
```yaml
|
349
|
+
version: '3.8'
|
350
|
+
services:
|
351
|
+
rcrewai-app:
|
352
|
+
build: .
|
353
|
+
environment:
|
354
|
+
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
355
|
+
- REDIS_URL=redis://redis:6379
|
356
|
+
- MAX_CONCURRENCY=3
|
357
|
+
depends_on:
|
358
|
+
- redis
|
359
|
+
restart: unless-stopped
|
360
|
+
|
361
|
+
redis:
|
362
|
+
image: redis:7-alpine
|
363
|
+
restart: unless-stopped
|
336
364
|
```
|
337
365
|
|
338
|
-
|
366
|
+
## Environment Variables
|
367
|
+
|
339
368
|
```bash
|
340
|
-
|
369
|
+
# LLM Configuration
|
370
|
+
export LLM_PROVIDER=openai
|
371
|
+
export OPENAI_API_KEY=sk-your-key
|
372
|
+
export LLM_TEMPERATURE=0.1
|
373
|
+
|
374
|
+
# Redis Configuration
|
375
|
+
export REDIS_URL=redis://localhost:6379
|
376
|
+
|
377
|
+
# Execution Configuration
|
378
|
+
export MAX_CONCURRENCY=3
|
379
|
+
export LOG_LEVEL=INFO
|
341
380
|
```
|
342
381
|
|
343
|
-
|
382
|
+
## Production Features
|
344
383
|
|
345
|
-
|
384
|
+
### 1. **Structured Logging**
|
385
|
+
JSON-formatted logs for easy parsing:
|
346
386
|
|
347
|
-
```
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
387
|
+
```json
|
388
|
+
{
|
389
|
+
"timestamp": "2024-01-15T10:30:45Z",
|
390
|
+
"level": "INFO",
|
391
|
+
"component": "rcrewai",
|
392
|
+
"message": "Task execution completed",
|
393
|
+
"agent_name": "tech_support_specialist",
|
394
|
+
"duration": 45.2
|
395
|
+
}
|
354
396
|
```
|
355
397
|
|
356
|
-
###
|
398
|
+
### 2. **Health Checks**
|
399
|
+
System health monitoring:
|
357
400
|
|
401
|
+
```ruby
|
402
|
+
health_status = HealthChecker.check_system_health
|
403
|
+
# Checks: Redis connectivity, system resources
|
358
404
|
```
|
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
405
|
|
435
|
-
###
|
436
|
-
|
437
|
-
- Error handling for missing API keys
|
438
|
-
- Multiple LLM provider support
|
406
|
+
### 3. **Error Recovery**
|
407
|
+
Automatic retry with backoff:
|
439
408
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
409
|
+
```ruby
|
410
|
+
max_retries: 3,
|
411
|
+
retry_delay: 10 # Increases on retry
|
412
|
+
```
|
444
413
|
|
445
|
-
###
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
414
|
+
### 4. **Execution Reports**
|
415
|
+
Detailed execution analytics:
|
416
|
+
|
417
|
+
```json
|
418
|
+
{
|
419
|
+
"execution_id": "uuid",
|
420
|
+
"duration": 120.5,
|
421
|
+
"success_rate": 100.0,
|
422
|
+
"total_tasks": 2,
|
423
|
+
"completed_tasks": 2
|
424
|
+
}
|
425
|
+
```
|
450
426
|
|
451
|
-
|
452
|
-
- Graceful error handling at all levels
|
453
|
-
- Comprehensive logging
|
454
|
-
- Cleanup procedures
|
427
|
+
## Monitoring and Alerting
|
455
428
|
|
456
|
-
###
|
457
|
-
-
|
458
|
-
-
|
459
|
-
-
|
460
|
-
-
|
429
|
+
### Key Metrics
|
430
|
+
- Success/failure rates
|
431
|
+
- Execution duration
|
432
|
+
- Queue depth
|
433
|
+
- System health
|
461
434
|
|
462
|
-
###
|
463
|
-
-
|
464
|
-
-
|
465
|
-
-
|
466
|
-
- Security controls
|
435
|
+
### Alerting Rules
|
436
|
+
- Success rate below 80%
|
437
|
+
- Execution time above 5 minutes
|
438
|
+
- System health check failures
|
467
439
|
|
468
|
-
|
469
|
-
- Agent learning from executions
|
470
|
-
- Tool usage patterns
|
471
|
-
- Performance optimization
|
440
|
+
## Security Best Practices
|
472
441
|
|
473
|
-
|
442
|
+
1. **Environment Variables**: Store sensitive data in env vars
|
443
|
+
2. **Input Validation**: Sanitize all inputs
|
444
|
+
3. **Access Controls**: Implement proper authorization
|
445
|
+
4. **Audit Logging**: Track all operations
|
474
446
|
|
475
|
-
##
|
447
|
+
## Deployment Strategies
|
476
448
|
|
477
|
-
|
449
|
+
### Rolling Updates
|
450
|
+
```bash
|
451
|
+
kubectl set image deployment/rcrewai rcrewai=rcrewai:v1.2.0
|
452
|
+
kubectl rollout status deployment/rcrewai
|
453
|
+
```
|
478
454
|
|
479
|
-
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
455
|
+
### Blue-Green Deployment
|
456
|
+
1. Deploy to green environment
|
457
|
+
2. Test thoroughly
|
458
|
+
3. Switch traffic
|
459
|
+
4. Keep blue for rollback
|
484
460
|
|
485
|
-
|
461
|
+
This production-ready implementation provides enterprise-grade reliability, monitoring, and scalability for AI crew deployments.
|