Class: ActiveAgent::ActionPrompt::Message
- Inherits:
-
Object
- Object
- ActiveAgent::ActionPrompt::Message
- Defined in:
- lib/active_agent/action_prompt/message.rb
Constant Summary collapse
- VALID_ROLES =
%w[system assistant user tool function].freeze
Instance Attribute Summary collapse
-
#action_requested ⇒ Object
Returns the value of attribute action_requested.
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
-
#requested_actions ⇒ Object
Returns the value of attribute requested_actions.
-
#role ⇒ Object
Returns the value of attribute role.
Instance Method Summary collapse
- #action_requested? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #perform_actions ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 15 |
# File 'lib/active_agent/action_prompt/message.rb', line 8 def initialize(attributes = {}) @content = attributes[:content] || "" @role = attributes[:role] || "user" @name = attributes[:name] @action_requested = attributes[:function_call] @requested_actions = attributes[:tool_calls] || [] validate_role end |
Instance Attribute Details
#action_requested ⇒ Object
Returns the value of attribute action_requested.
6 7 8 |
# File 'lib/active_agent/action_prompt/message.rb', line 6 def action_requested @action_requested end |
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/active_agent/action_prompt/message.rb', line 6 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_agent/action_prompt/message.rb', line 6 def name @name end |
#requested_actions ⇒ Object
Returns the value of attribute requested_actions.
6 7 8 |
# File 'lib/active_agent/action_prompt/message.rb', line 6 def requested_actions @requested_actions end |
#role ⇒ Object
Returns the value of attribute role.
6 7 8 |
# File 'lib/active_agent/action_prompt/message.rb', line 6 def role @role end |
Instance Method Details
#action_requested? ⇒ Boolean
31 32 33 |
# File 'lib/active_agent/action_prompt/message.rb', line 31 def action_requested? action_requested.present? || requested_actions.any? end |
#perform_actions ⇒ Object
25 26 27 28 29 |
# File 'lib/active_agent/action_prompt/message.rb', line 25 def perform_actions requested_actions.each do |action| action.call(self) if action.respond_to?(:call) end end |
#to_h ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 17 def to_h hash = {role: role, content: content} hash[:name] = name if name hash[:action_requested] = action_requested if action_requested hash[:requested_actions] = requested_actions if requested_actions.any? hash end |