Class: RcrewAI::Rails::Task

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

Instance Method Summary collapse

Instance Method Details

#add_dependency(other_task) ⇒ Object



65
66
67
# File 'app/models/rcrewai/rails/task.rb', line 65

def add_dependency(other_task)
  task_dependencies.create!(dependency: other_task)
end

#instantiated_toolsObject



55
56
57
58
59
60
61
62
63
# File 'app/models/rcrewai/rails/task.rb', line 55

def instantiated_tools
  return [] if tools.blank?

  tools.map do |tool_config|
    tool_class = tool_config["class"].constantize
    tool_params = tool_config["params"] || {}
    tool_class.new(**tool_params.symbolize_keys)
  end
end

#remove_dependency(other_task) ⇒ Object



69
70
71
# File 'app/models/rcrewai/rails/task.rb', line 69

def remove_dependency(other_task)
  task_dependencies.where(dependency: other_task).destroy_all
end

#task_output_optionsObject

rcrewai 0.4/0.5 task output-processing options. Only emit a key when it is meaningfully set, so an all-default record constructs exactly as it did before these options existed.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/rcrewai/rails/task.rb', line 40

def task_output_options
  opts = {}
  opts[:output_schema] = output_schema.deep_symbolize_keys if output_schema.present?
  opts[:guardrail] = guardrail_callable if guardrail_callable
  opts[:guardrail_max_retries] = guardrail_max_retries if guardrail_callable && guardrail_max_retries
  opts[:output_file] = output_file if output_file.present?
  # Core defaults create_directory to true; only forward when explicitly
  # disabled, so an all-default record still emits nothing.
  opts[:create_directory] = false if create_directory == false
  opts[:markdown] = markdown if markdown
  opts[:attachments] = normalized_attachments if attachments.present?
  opts
end

#to_rcrew_taskObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/rcrewai/rails/task.rb', line 23

def to_rcrew_task
  RCrewAI::Task.new(
    name: rcrew_task_name,
    description: description,
    expected_output: expected_output,
    agent: agent&.to_rcrew_agent,
    context: context,
    async: async_execution,
    tools: instantiated_tools,
    callback: callback_method,
    **task_output_options
  )
end