Class: ActionAgent::AgentMemory

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

Overview

Agent-curated long-term memory for a subject record (solid_agent HasMemory contract). On this platform the memorable is usually the dashboard Agent record; agents write/read it through the save_memory / recall_memory tools during generation runs.

Memory is scoped to (memorable, scope) — not to an agent class — so any agent operating on the same subject shares it, making it a handoff channel between agents. Entry source_agent records who wrote each note.

Constant Summary collapse

DEFAULT_SCOPE =
"default"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

for_owner, owner_association

Class Method Details

.for(memorable, scope: DEFAULT_SCOPE) ⇒ Object



20
21
22
# File 'app/models/action_agent/agent_memory.rb', line 20

def self.for(memorable, scope: DEFAULT_SCOPE)
  find_or_create_by!(memorable: memorable, scope: scope.to_s)
end

Instance Method Details

#recall(limit: 20, category: nil) ⇒ Object



28
29
30
31
32
# File 'app/models/action_agent/agent_memory.rb', line 28

def recall(limit: 20, category: nil)
  scope = entries.order(created_at: :desc)
  scope = scope.where(category: category) if category.present?
  scope.limit(limit || 20).to_a
end

#remember(content, source_agent: nil, category: nil) ⇒ Object



24
25
26
# File 'app/models/action_agent/agent_memory.rb', line 24

def remember(content, source_agent: nil, category: nil)
  entries.create!(content: content, source_agent: source_agent, category: category)
end

#summary_listObject



34
35
36
# File 'app/models/action_agent/agent_memory.rb', line 34

def summary_list
  entries.order(:created_at).pluck(:content)
end

#to_promptObject

Formatted block suitable for injecting into another agent's instructions when handing a subject off.



40
41
42
43
44
45
46
47
48
# File 'app/models/action_agent/agent_memory.rb', line 40

def to_prompt
  notes = entries.order(:created_at).map do |entry|
    source = entry.source_agent.present? ? " (#{entry.source_agent})" : ""
    "- #{entry.content}#{source}"
  end
  return "" if notes.empty?

  "Memory notes for this subject:\n#{notes.join("\n")}"
end