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,193 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rcrewai'
4
+
5
+ puts "šŸ—ļø Hierarchical Crew Process Example"
6
+ puts "=" * 50
7
+
8
+ # Configure RCrewAI
9
+ RCrewAI.configure do |config|
10
+ config.llm_provider = :openai # Change as needed
11
+ config.temperature = 0.1
12
+ end
13
+
14
+ # Create a hierarchical crew
15
+ crew = RCrewAI::Crew.new("product_development_crew", process: :hierarchical, verbose: true)
16
+
17
+ puts "šŸ“‹ Creating hierarchical crew with manager and specialists..."
18
+
19
+ # Create a manager agent
20
+ project_manager = RCrewAI::Agent.new(
21
+ name: "project_manager",
22
+ role: "Senior Project Manager",
23
+ goal: "Coordinate team efforts and ensure project success",
24
+ backstory: "You are an experienced project manager with 10+ years leading cross-functional teams. You excel at delegation, coordination, and ensuring deliverables meet requirements.",
25
+ manager: true, # This makes the agent a manager
26
+ allow_delegation: true,
27
+ tools: [RCrewAI::Tools::FileWriter.new],
28
+ verbose: true,
29
+ max_iterations: 6
30
+ )
31
+
32
+ # Create specialist agents
33
+ market_researcher = RCrewAI::Agent.new(
34
+ name: "market_researcher",
35
+ role: "Market Research Specialist",
36
+ goal: "Conduct thorough market analysis and competitive research",
37
+ backstory: "You are a market research expert who excels at finding market opportunities, analyzing competitors, and identifying customer needs.",
38
+ tools: [RCrewAI::Tools::WebSearch.new(max_results: 10)],
39
+ verbose: true
40
+ )
41
+
42
+ product_designer = RCrewAI::Agent.new(
43
+ name: "product_designer",
44
+ role: "Senior Product Designer",
45
+ goal: "Design user-centered products and experiences",
46
+ 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
+ tools: [RCrewAI::Tools::FileWriter.new],
48
+ verbose: true
49
+ )
50
+
51
+ technical_lead = RCrewAI::Agent.new(
52
+ name: "technical_lead",
53
+ role: "Technical Lead",
54
+ goal: "Define technical architecture and implementation strategy",
55
+ backstory: "You are a senior software architect who designs scalable, maintainable systems. You excel at technical planning and risk assessment.",
56
+ tools: [
57
+ RCrewAI::Tools::FileWriter.new,
58
+ RCrewAI::Tools::FileReader.new
59
+ ],
60
+ verbose: true
61
+ )
62
+
63
+ # Add agents to crew
64
+ crew.add_agent(project_manager) # Manager added first
65
+ crew.add_agent(market_researcher)
66
+ crew.add_agent(product_designer)
67
+ crew.add_agent(technical_lead)
68
+
69
+ puts "šŸ‘„ Crew created with:"
70
+ puts " šŸ“Š Manager: #{project_manager.name}"
71
+ puts " šŸ” Specialists: #{crew.agents.length - 1} agents"
72
+
73
+ # Set up manager relationships
74
+ project_manager.add_subordinate(market_researcher)
75
+ project_manager.add_subordinate(product_designer)
76
+ project_manager.add_subordinate(technical_lead)
77
+
78
+ # Create tasks that will be delegated by the manager
79
+ market_research_task = RCrewAI::Task.new(
80
+ name: "market_analysis",
81
+ description: "Conduct comprehensive market research for a new AI-powered productivity app. Focus on market size, target demographics, competitors, pricing strategies, and key opportunities.",
82
+ expected_output: "Detailed market analysis report with actionable insights and recommendations",
83
+ max_retries: 2
84
+ )
85
+
86
+ product_design_task = RCrewAI::Task.new(
87
+ name: "product_design",
88
+ 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.",
89
+ expected_output: "Product design document with UX strategy, feature specifications, and user flow diagrams",
90
+ context: [market_research_task] # Depends on market research
91
+ )
92
+
93
+ technical_architecture_task = RCrewAI::Task.new(
94
+ name: "technical_architecture",
95
+ description: "Define the technical architecture for an AI productivity app. Include technology stack, system design, scalability considerations, AI integration approach, and implementation roadmap.",
96
+ expected_output: "Technical architecture document with system design, technology recommendations, and implementation plan",
97
+ context: [market_research_task, product_design_task] # Depends on both previous tasks
98
+ )
99
+
100
+ project_plan_task = RCrewAI::Task.new(
101
+ name: "project_planning",
102
+ description: "Create comprehensive project plan integrating market research, product design, and technical architecture. Include timeline, milestones, resource requirements, and risk assessment.",
103
+ expected_output: "Complete project plan with timelines, deliverables, and coordination strategy saved to project_plan.md",
104
+ agent: project_manager, # Manager handles this directly
105
+ context: [market_research_task, product_design_task, technical_architecture_task]
106
+ )
107
+
108
+ # Add tasks to crew
109
+ crew.add_task(market_research_task)
110
+ crew.add_task(product_design_task)
111
+ crew.add_task(technical_architecture_task)
112
+ crew.add_task(project_plan_task)
113
+
114
+ puts "šŸ“‹ Tasks created with dependencies:"
115
+ crew.tasks.each_with_index do |task, i|
116
+ deps = task.context&.length || 0
117
+ puts " #{i + 1}. #{task.name} (#{deps} dependencies)"
118
+ end
119
+
120
+ # Execute the hierarchical crew
121
+ puts "\nšŸš€ Starting hierarchical execution..."
122
+ puts "The project manager will coordinate and delegate tasks to specialists"
123
+
124
+ begin
125
+ start_time = Time.now
126
+
127
+ # Execute with hierarchical process
128
+ results = crew.execute
129
+
130
+ execution_time = Time.now - start_time
131
+
132
+ # Display results
133
+ puts "\n" + "=" * 60
134
+ puts "šŸŽ‰ HIERARCHICAL EXECUTION COMPLETED"
135
+ puts "=" * 60
136
+ puts "Total execution time: #{execution_time.round(2)} seconds"
137
+ puts "Process type: #{results[:process]}"
138
+ puts "Success rate: #{results[:success_rate]}%"
139
+ puts "Completed tasks: #{results[:completed_tasks]}/#{results[:total_tasks]}"
140
+
141
+ # Show task results
142
+ puts "\nšŸ“Š Task Results:"
143
+ results[:results].each do |result|
144
+ status_icon = result[:status] == :completed ? "āœ…" : "āŒ"
145
+ agent_name = result[:assigned_agent]&.name || result[:task].agent&.name
146
+
147
+ puts "#{status_icon} #{result[:task].name}"
148
+ puts " Assigned to: #{agent_name}"
149
+ puts " Status: #{result[:status]}"
150
+
151
+ if result[:phase]
152
+ puts " Phase: #{result[:phase]}"
153
+ end
154
+
155
+ if result[:status] == :completed
156
+ preview = result[:result][0..150]
157
+ preview += "..." if result[:result].length > 150
158
+ puts " Result: #{preview}"
159
+ else
160
+ puts " Error: #{result[:result]}"
161
+ end
162
+
163
+ puts
164
+ end
165
+
166
+ # Show delegation insights
167
+ puts "šŸŽÆ Hierarchical Process Insights:"
168
+ puts " • Manager coordinated #{crew.agents.length - 1} specialists"
169
+ puts " • Tasks were delegated based on agent expertise"
170
+ puts " • Dependencies were handled automatically"
171
+ puts " • Cross-phase coordination was managed"
172
+
173
+ # Check for output files
174
+ if File.exist?('project_plan.md')
175
+ puts "\nšŸ“„ Generated Files:"
176
+ puts " āœ… project_plan.md (#{File.size('project_plan.md')} bytes)"
177
+ end
178
+
179
+ rescue RCrewAI::ProcessError => e
180
+ puts "\nāŒ Process Error: #{e.message}"
181
+ puts "This might indicate issues with agent setup or task dependencies"
182
+
183
+ rescue RCrewAI::AgentError => e
184
+ puts "\nāŒ Agent Error: #{e.message}"
185
+
186
+ rescue => e
187
+ puts "\nšŸ’„ Unexpected error: #{e.message}"
188
+ puts e.backtrace.first(3).join("\n") if ENV['DEBUG']
189
+ end
190
+
191
+ puts "\n" + "=" * 50
192
+ puts "šŸ—ļø Hierarchical Crew Example Complete!"
193
+ puts "=" * 50
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rcrewai'
4
+
5
+ puts "šŸ¤ Human-in-the-Loop Example"
6
+ puts "=" * 50
7
+
8
+ # Configure RCrewAI
9
+ RCrewAI.configure do |config|
10
+ config.llm_provider = :openai # Change as needed
11
+ config.temperature = 0.1
12
+ end
13
+
14
+ puts "šŸ”§ Setting up crew with human interaction capabilities..."
15
+
16
+ # Create crew
17
+ crew = RCrewAI::Crew.new("human_assisted_crew")
18
+
19
+ # Create agents with human input capabilities
20
+ research_agent = RCrewAI::Agent.new(
21
+ name: "research_assistant",
22
+ role: "Research Specialist",
23
+ goal: "Conduct thorough research with human oversight",
24
+ backstory: "You work closely with humans to ensure research quality and accuracy.",
25
+ tools: [RCrewAI::Tools::WebSearch.new, RCrewAI::Tools::FileWriter.new],
26
+ verbose: true,
27
+ human_input: true, # Enable human input
28
+ require_approval_for_tools: true, # Require approval for tool usage
29
+ require_approval_for_final_answer: true # Require approval for final answers
30
+ )
31
+
32
+ content_creator = RCrewAI::Agent.new(
33
+ name: "content_creator",
34
+ role: "Content Writer",
35
+ goal: "Create engaging content with human guidance",
36
+ backstory: "You collaborate with humans to create compelling, accurate content.",
37
+ tools: [RCrewAI::Tools::FileWriter.new, RCrewAI::Tools::FileReader.new],
38
+ verbose: true,
39
+ human_input: true,
40
+ require_approval_for_final_answer: true
41
+ )
42
+
43
+ quality_checker = RCrewAI::Agent.new(
44
+ name: "quality_checker",
45
+ role: "Quality Assurance Specialist",
46
+ goal: "Ensure content meets quality standards",
47
+ backstory: "You work with humans to maintain high quality standards.",
48
+ tools: [RCrewAI::Tools::FileReader.new],
49
+ verbose: true,
50
+ human_input: true
51
+ )
52
+
53
+ # Add agents to crew
54
+ crew.add_agent(research_agent)
55
+ crew.add_agent(content_creator)
56
+ crew.add_agent(quality_checker)
57
+
58
+ puts "šŸ‘„ Created crew with #{crew.agents.length} agents (all human-enabled)"
59
+
60
+ # Create tasks with various levels of human interaction
61
+
62
+ # Task 1: Research with human confirmation and guidance
63
+ research_task = RCrewAI::Task.new(
64
+ name: "research_ai_trends",
65
+ description: "Research the latest AI trends for 2024, focusing on practical business applications",
66
+ agent: research_agent,
67
+ expected_output: "Comprehensive research document saved as ai_trends_2024.md",
68
+ human_input: true,
69
+ require_confirmation: true, # Human must confirm before starting
70
+ allow_guidance: true, # Allow human to provide guidance during execution
71
+ human_review_points: [:completion] # Review when completed
72
+ )
73
+
74
+ # Task 2: Content creation with human oversight
75
+ content_task = RCrewAI::Task.new(
76
+ name: "create_ai_article",
77
+ description: "Write an engaging article based on the research findings about AI trends",
78
+ agent: content_creator,
79
+ expected_output: "Well-structured article saved as ai_trends_article.md",
80
+ context: [research_task],
81
+ human_input: true,
82
+ allow_guidance: true,
83
+ human_review_points: [:completion]
84
+ )
85
+
86
+ # Task 3: Quality check with human review
87
+ quality_task = RCrewAI::Task.new(
88
+ name: "quality_review",
89
+ description: "Review the article for accuracy, clarity, and engagement",
90
+ agent: quality_checker,
91
+ expected_output: "Quality assessment report with recommendations",
92
+ context: [content_task],
93
+ human_input: true,
94
+ human_review_points: [:completion]
95
+ )
96
+
97
+ crew.add_task(research_task)
98
+ crew.add_task(content_task)
99
+ crew.add_task(quality_task)
100
+
101
+ puts "šŸ“‹ Created #{crew.tasks.length} tasks with human interaction points"
102
+
103
+ # Demonstrate different human interaction modes
104
+ puts "\nšŸŽÆ HUMAN-IN-THE-LOOP EXECUTION MODES"
105
+ puts "-" * 40
106
+
107
+ puts "\n1ļøāƒ£ BASIC HUMAN APPROVAL MODE"
108
+ puts "Tasks will request human approval at key decision points..."
109
+
110
+ begin
111
+ results = crew.execute
112
+
113
+ puts "\nšŸ“Š Execution Results:"
114
+ puts " Completed: #{results[:completed_tasks]}/#{results[:total_tasks]}"
115
+ puts " Success Rate: #{results[:success_rate]}%"
116
+
117
+ # Show any generated files
118
+ output_files = ['ai_trends_2024.md', 'ai_trends_article.md']
119
+ puts "\nšŸ“„ Generated Files:"
120
+ output_files.each do |file|
121
+ if File.exist?(file)
122
+ puts " āœ… #{file} (#{File.size(file)} bytes)"
123
+ else
124
+ puts " āŒ #{file} (not created)"
125
+ end
126
+ end
127
+
128
+ rescue => e
129
+ puts "āŒ Execution failed or was cancelled: #{e.message}"
130
+ end
131
+
132
+ puts "\n2ļøāƒ£ AGENT-LEVEL HUMAN INTERACTION DEMONSTRATION"
133
+ puts "Creating a standalone task to show detailed human interactions..."
134
+
135
+ # Create a simple demonstration task
136
+ demo_agent = RCrewAI::Agent.new(
137
+ name: "demo_agent",
138
+ role: "Demonstration Agent",
139
+ goal: "Show human interaction capabilities",
140
+ backstory: "I demonstrate various human interaction patterns.",
141
+ tools: [RCrewAI::Tools::FileWriter.new],
142
+ verbose: true
143
+ )
144
+
145
+ # Enable different types of human interaction
146
+ demo_agent.enable_human_input(
147
+ require_approval_for_tools: true,
148
+ require_approval_for_final_answer: true
149
+ )
150
+
151
+ demo_task = RCrewAI::Task.new(
152
+ name: "human_interaction_demo",
153
+ description: "Write a short summary of Ruby programming benefits and save it to ruby_benefits.txt",
154
+ agent: demo_agent,
155
+ expected_output: "A text file containing Ruby programming benefits",
156
+ human_input: true,
157
+ require_confirmation: true,
158
+ allow_guidance: true
159
+ )
160
+
161
+ puts "\nšŸš€ Starting human interaction demonstration..."
162
+
163
+ begin
164
+ demo_result = demo_task.execute
165
+ puts "\nDemo result: #{demo_result}"
166
+
167
+ if File.exist?('ruby_benefits.txt')
168
+ puts "\nšŸ“„ Generated demo file:"
169
+ puts File.read('ruby_benefits.txt')[0..200] + "..."
170
+ end
171
+
172
+ rescue => e
173
+ puts "Demo task result: #{e.message}"
174
+ end
175
+
176
+ puts "\n3ļøāƒ£ HUMAN INPUT UTILITY DEMONSTRATION"
177
+ puts "Testing different types of human input requests..."
178
+
179
+ # Demonstrate the HumanInput utility directly
180
+ human_input = RCrewAI::HumanInput.new(verbose: true)
181
+
182
+ puts "\nTesting approval request..."
183
+ approval_result = human_input.request_approval(
184
+ "Test approval request - this is just a demonstration",
185
+ context: "This is a test of the human input system",
186
+ consequences: "Nothing will actually happen",
187
+ timeout: 30
188
+ )
189
+ puts "Approval result: #{approval_result[:approved] ? 'APPROVED' : 'REJECTED'}"
190
+
191
+ puts "\nTesting choice request..."
192
+ choice_result = human_input.request_choice(
193
+ "What's your preferred programming language?",
194
+ ["Ruby", "Python", "JavaScript", "Other"],
195
+ timeout: 30
196
+ )
197
+ puts "Choice result: #{choice_result[:choice]}" if choice_result[:valid]
198
+
199
+ puts "\nTesting input request..."
200
+ input_result = human_input.request_input(
201
+ "Enter a short message (or press Enter to skip):",
202
+ help_text: "This is just for testing the input system",
203
+ timeout: 20
204
+ )
205
+ puts "Input result: '#{input_result[:input]}'" if input_result[:valid]
206
+
207
+ # Show session summary
208
+ puts "\nšŸ“ˆ Human Input Session Summary:"
209
+ summary = human_input.session_summary
210
+ summary.each { |key, value| puts " #{key}: #{value}" }
211
+
212
+ puts "\nšŸŽÆ HUMAN-IN-THE-LOOP FEATURES DEMONSTRATED:"
213
+ puts " • Task-level human confirmation before execution"
214
+ puts " • Agent-level tool approval workflows"
215
+ puts " • Final answer review and revision capabilities"
216
+ puts " • Human guidance integration into agent reasoning"
217
+ puts " • Task completion review and feedback handling"
218
+ puts " • Error handling with human intervention options"
219
+ puts " • Flexible human input types (approval, choice, input, review)"
220
+ puts " • Session tracking and interaction history"
221
+ puts " • Configurable timeouts and auto-approval modes"
222
+ puts " • Integration with both sync and async execution"
223
+
224
+ puts "\nšŸ’” USAGE PATTERNS:"
225
+ puts " 1. Development & Testing: Use human approval for tool usage"
226
+ puts " 2. Content Creation: Human review of final outputs"
227
+ puts " 3. Critical Tasks: Human confirmation before execution"
228
+ puts " 4. Learning & Training: Human guidance during reasoning"
229
+ puts " 5. Quality Assurance: Human review at completion points"
230
+
231
+ puts "\n" + "=" * 50
232
+ puts "šŸ¤ Human-in-the-Loop Demo Complete!"
233
+ puts "=" * 50