Class: RcrewAI::Rails::Crew
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RcrewAI::Rails::Crew
- Defined in:
- app/models/rcrewai/rails/crew.rb
Instance Method Summary collapse
- #batch_executions(batch_id) ⇒ Object
-
#crew_planning_options ⇒ Object
Crew construction options (planning, consensus_agents, knowledge).
- #execute_async(inputs = {}) ⇒ Object
- #execute_batch_async(inputs_list) ⇒ Object
- #execute_batch_sync(inputs_list) ⇒ Object
- #execute_sync(inputs = {}) ⇒ Object
- #execution_stats ⇒ Object
- #last_execution ⇒ Object
- #rcrew_knowledge_sources ⇒ Object
- #to_rcrew ⇒ Object
Instance Method Details
#batch_executions(batch_id) ⇒ Object
80 81 82 |
# File 'app/models/rcrewai/rails/crew.rb', line 80 def batch_executions(batch_id) executions.where(batch_id: batch_id).order(:created_at, :id) end |
#crew_planning_options ⇒ Object
Crew construction options (planning, consensus_agents, knowledge). Emit a key only when meaningfully set, so an all-default crew constructs exactly as it did before.
42 43 44 45 46 47 48 49 50 |
# File 'app/models/rcrewai/rails/crew.rb', line 42 def opts = {} opts[:planning] = planning if planning opts[:planning_llm] = planning_llm.to_sym if planning_llm.present? sources = rcrew_knowledge_sources opts[:knowledge_sources] = sources if sources.any? opts[:consensus_agents] = consensus_agents if consensus_agents.present? opts end |
#execute_async(inputs = {}) ⇒ Object
56 57 58 |
# File 'app/models/rcrewai/rails/crew.rb', line 56 def execute_async(inputs = {}) CrewExecutionJob.perform_later(self, inputs) end |
#execute_batch_async(inputs_list) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/models/rcrewai/rails/crew.rb', line 64 def execute_batch_async(inputs_list) batch_id = SecureRandom.uuid normalize_batch_inputs(inputs_list).each do |inputs| CrewExecutionJob.perform_later(self, inputs, batch_id: batch_id) end batch_id end |
#execute_batch_sync(inputs_list) ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/models/rcrewai/rails/crew.rb', line 72 def execute_batch_sync(inputs_list) batch_id = SecureRandom.uuid normalize_batch_inputs(inputs_list).each do |inputs| CrewExecutionJob.perform_now(self, inputs, batch_id: batch_id) end { batch_id: batch_id, executions: batch_executions(batch_id).to_a } end |
#execute_sync(inputs = {}) ⇒ Object
60 61 62 |
# File 'app/models/rcrewai/rails/crew.rb', line 60 def execute_sync(inputs = {}) CrewExecutionJob.perform_now(self, inputs) end |
#execution_stats ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'app/models/rcrewai/rails/crew.rb', line 88 def execution_stats { total: executions.count, successful: executions.successful.count, failed: executions.failed.count, pending: executions.pending.count, average_duration: executions.successful.average(:duration_seconds) } end |
#last_execution ⇒ Object
84 85 86 |
# File 'app/models/rcrewai/rails/crew.rb', line 84 def last_execution executions.order(created_at: :desc).first end |
#rcrew_knowledge_sources ⇒ Object
52 53 54 |
# File 'app/models/rcrewai/rails/crew.rb', line 52 def rcrew_knowledge_sources knowledge_sources.active.map(&:to_rcrew_source) end |
#to_rcrew ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/rcrewai/rails/crew.rb', line 19 def to_rcrew crew = RCrewAI::Crew.new( name, process: process_type.to_sym, verbose: verbose, ** ) agents.each do |agent| crew.add_agent(agent.to_rcrew_agent) end tasks.each do |task| crew.add_task(task.to_rcrew_task) end register_kickoff_hooks(crew) crew end |