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
rcrewai 0.5.0 planning options.
- #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
79 80 81 |
# File 'app/models/rcrewai/rails/crew.rb', line 79 def batch_executions(batch_id) executions.where(batch_id: batch_id).order(:created_at, :id) end |
#crew_planning_options ⇒ Object
rcrewai 0.5.0 planning options. 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 |
# 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 end |
#execute_async(inputs = {}) ⇒ Object
55 56 57 |
# File 'app/models/rcrewai/rails/crew.rb', line 55 def execute_async(inputs = {}) CrewExecutionJob.perform_later(self, inputs) end |
#execute_batch_async(inputs_list) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/models/rcrewai/rails/crew.rb', line 63 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
71 72 73 74 75 76 77 |
# File 'app/models/rcrewai/rails/crew.rb', line 71 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
59 60 61 |
# File 'app/models/rcrewai/rails/crew.rb', line 59 def execute_sync(inputs = {}) CrewExecutionJob.perform_now(self, inputs) end |
#execution_stats ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'app/models/rcrewai/rails/crew.rb', line 87 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
83 84 85 |
# File 'app/models/rcrewai/rails/crew.rb', line 83 def last_execution executions.order(created_at: :desc).first end |
#rcrew_knowledge_sources ⇒ Object
51 52 53 |
# File 'app/models/rcrewai/rails/crew.rb', line 51 def rcrew_knowledge_sources knowledge_sources.active.map(&:to_rcrew_source) end |
#to_rcrew ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/rcrewai/rails/crew.rb', line 20 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 |