Class: ActiveAgent::ActionPrompt::Message

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_requestedObject

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

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/active_agent/action_prompt/message.rb', line 6

def content
  @content
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/active_agent/action_prompt/message.rb', line 6

def name
  @name
end

#requested_actionsObject

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

#roleObject

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

Returns:

  • (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_actionsObject



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_hObject



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