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
-
#memory_options ⇒ Object
Agent memory config (rcrewai 0.6+).
- #rcrew_knowledge_sources ⇒ Object
- #remove_tool(tool_class) ⇒ Object
- #to_rcrew_agent ⇒ Object
Instance Method Details
#add_tool(tool_class, params = {}) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'app/models/rcrewai/rails/agent.rb', line 76 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 46 |
# 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[:memory] = if memory_enabled opts end |
#instantiated_tools ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/models/rcrewai/rails/agent.rb', line 66 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 |
#memory_options ⇒ Object
Agent memory config (rcrewai 0.6+). Scalars come from columns; embedder and store come from the engine configuration (set in a host initializer). May return {} — an empty hash still enables memory with core defaults.
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/rcrewai/rails/agent.rb', line 51 def m = {} m[:scope] = memory_scope if memory_scope.present? m[:short_term_limit] = memory_short_term_limit if memory_short_term_limit.present? = RcrewAI::Rails.config. store = RcrewAI::Rails.config.default_memory_store m[:embedder] = if m[:store] = store if store m end |
#rcrew_knowledge_sources ⇒ Object
62 63 64 |
# File 'app/models/rcrewai/rails/agent.rb', line 62 def rcrew_knowledge_sources knowledge_sources.active.map(&:to_rcrew_source) end |
#remove_tool(tool_class) ⇒ Object
85 86 87 88 |
# File 'app/models/rcrewai/rails/agent.rb', line 85 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 |