Class: RcrewAI::Rails::Agent
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RcrewAI::Rails::Agent
- Defined in:
- app/models/rcrewai/rails/agent.rb
Instance Method Summary collapse
- #add_tool(tool_class, params = {}) ⇒ Object
-
#agent_options ⇒ Object
rcrewai 0.5.0 agent options.
- #instantiated_tools ⇒ Object
- #rcrew_knowledge_sources ⇒ Object
- #remove_tool(tool_class) ⇒ Object
- #to_rcrew_agent ⇒ Object
Instance Method Details
#add_tool(tool_class, params = {}) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/models/rcrewai/rails/agent.rb', line 61 def add_tool(tool_class, params = {}) self.tools ||= [] self.tools << { "class" => tool_class.to_s, "params" => params } save end |
#agent_options ⇒ Object
rcrewai 0.5.0 agent options. Only emit a key when it is meaningfully set, so an all-default record constructs exactly as it did pre-0.5.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/rcrewai/rails/agent.rb', line 35 def opts = {} opts[:max_rpm] = max_rpm if max_rpm.present? && max_rpm.positive? opts[:reasoning] = reasoning if reasoning opts[:max_reasoning_attempts] = max_reasoning_attempts if reasoning && max_reasoning_attempts opts[:respect_context_window] = respect_context_window if respect_context_window opts[:llm] = llm_config.symbolize_keys if llm_config.present? sources = rcrew_knowledge_sources opts[:knowledge_sources] = sources if sources.any? opts end |
#instantiated_tools ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/rcrewai/rails/agent.rb', line 51 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 |
#rcrew_knowledge_sources ⇒ Object
47 48 49 |
# File 'app/models/rcrewai/rails/agent.rb', line 47 def rcrew_knowledge_sources knowledge_sources.active.map(&:to_rcrew_source) end |
#remove_tool(tool_class) ⇒ Object
70 71 72 73 |
# File 'app/models/rcrewai/rails/agent.rb', line 70 def remove_tool(tool_class) self.tools = tools.reject { |t| t["class"] == tool_class.to_s } save end |
#to_rcrew_agent ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/rcrewai/rails/agent.rb', line 19 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 |