Class: RcrewAI::Rails::Agent

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

Instance Method Summary collapse

Instance Method Details

#add_tool(tool_class, params = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/models/rcrewai/rails/agent.rb', line 41

def add_tool(tool_class, params = {})
  self.tools ||= []
  self.tools << {
    "class" => tool_class.to_s,
    "params" => params
  }
  save
end

#instantiated_toolsObject



31
32
33
34
35
36
37
38
39
# File 'app/models/rcrewai/rails/agent.rb', line 31

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_tool(tool_class) ⇒ Object



50
51
52
53
# File 'app/models/rcrewai/rails/agent.rb', line 50

def remove_tool(tool_class)
  self.tools = tools.reject { |t| t["class"] == tool_class.to_s }
  save
end

#to_rcrew_agentObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/rcrewai/rails/agent.rb', line 18

def to_rcrew_agent
  RCrewAI::Agent.new(
    name: name,
    role: role,
    goal: goal,
    backstory: backstory,
    verbose: verbose,
    allow_delegation: allow_delegation,
    tools: instantiated_tools,
    max_iterations: max_iterations
  )
end