Class: ActiveAgent::Memory::ActiveRecord
- Inherits:
-
Base
- Object
- Base
- ActiveAgent::Memory::ActiveRecord
show all
- Defined in:
- lib/active_agent/memory/active_record.rb
Instance Attribute Summary
Attributes inherited from Base
#conversation_id
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#add_message(role:, content:, **options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/active_agent/memory/active_record.rb', line 41
def add_message(role:, content:, **options)
ensure_table_exists!
MessageRecord.create!(
conversation_id: conversation_id.to_s,
role: role.to_s,
content: content,
tool_calls: options[:tool_calls],
tool_call_id: options[:tool_call_id],
name: options[:name]
)
end
|
#clear ⇒ Object
54
55
56
57
|
# File 'lib/active_agent/memory/active_record.rb', line 54
def clear
ensure_table_exists!
MessageRecord.where(conversation_id: conversation_id.to_s).delete_all
end
|
#messages ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/active_agent/memory/active_record.rb', line 22
def messages
ensure_table_exists!
MessageRecord.where(conversation_id: conversation_id.to_s)
.order(:created_at, :id)
.map do |record|
msg = {
role: record.role,
content: record.content
}
if record.tool_calls.present?
msg[:tool_calls] = record.tool_calls.map { |tc| tc.is_a?(Hash) ? tc.deep_symbolize_keys : tc }
end
msg[:tool_call_id] = record.tool_call_id if record.tool_call_id.present?
msg[:name] = record.name if record.name.present?
msg
end
end
|