Class: ActionAgent::AgentMessage

Inherits:
ApplicationRecord show all
Defined in:
app/models/action_agent/agent_message.rb

Overview

A single message in an agent conversation context (user, assistant, system, or tool). From the solid_agent install generator; the provenance and content_checksum columns are populated automatically by SolidAgent::HasContext.

Instance Method Summary collapse

Methods inherited from ApplicationRecord

for_owner, owner_association

Instance Method Details

#to_message_hashObject

Converts the message to a hash format for ActiveAgent prompts



19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/action_agent/agent_message.rb', line 19

def to_message_hash
  hash = { role: role, content: content }
  hash[:tool_calls] = tool_calls_data if role == "assistant" && tool_calls_data.present?

  if role == "tool"
    hash[:tool_call_id] = tool_call_id
    hash[:name] = tool_name
  end

  hash
end

#tool_call?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/action_agent/agent_message.rb', line 35

def tool_call?
  role == "assistant" && tool_calls_data.present?
end

#tool_calls_dataObject



31
32
33
# File 'app/models/action_agent/agent_message.rb', line 31

def tool_calls_data
  &.dig("tool_calls") || []
end

#tool_result?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/action_agent/agent_message.rb', line 39

def tool_result?
  role == "tool"
end