Class: RcrewAI::Rails::Crew

Inherits:
ApplicationRecord show all
Defined in:
app/models/rcrewai/rails/crew.rb

Instance Method Summary collapse

Instance Method Details

#execute_async(inputs = {}) ⇒ Object



37
38
39
# File 'app/models/rcrewai/rails/crew.rb', line 37

def execute_async(inputs = {})
  CrewExecutionJob.perform_later(self, inputs)
end

#execute_sync(inputs = {}) ⇒ Object



41
42
43
# File 'app/models/rcrewai/rails/crew.rb', line 41

def execute_sync(inputs = {})
  CrewExecutionJob.perform_now(self, inputs)
end

#execution_statsObject



49
50
51
52
53
54
55
56
57
# File 'app/models/rcrewai/rails/crew.rb', line 49

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_executionObject



45
46
47
# File 'app/models/rcrewai/rails/crew.rb', line 45

def last_execution
  executions.order(created_at: :desc).first
end

#to_rcrewObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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

  crew
end