Module: SolidAgent::HasMemory
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/solid_agent/has_memory.rb
Constant Summary collapse
- DEFAULT_SCOPE =
"default"
Class Method Summary collapse
-
.tool_definitions ⇒ Object
Function-calling schemas (common format) for the two memory tools.
Instance Method Summary collapse
-
#memory ⇒ Object
The memory record for the current subject (or nil without a subject).
-
#memory_subject ⇒ Object
The record memory is attached to.
- #memory_tool_definitions ⇒ Object
- #recall_memory(category: nil, limit: 20) ⇒ Object
-
#save_memory(content:, category: nil) ⇒ Object
Tool implementations — routed here by the provider's tool calls.
Class Method Details
.tool_definitions ⇒ Object
Function-calling schemas (common format) for the two memory tools. Exposed as a module method so non-agent callers (platform executors, MCP servers) can reuse the exact same contract.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/solid_agent/has_memory.rb', line 43 def self.tool_definitions [ { name: "save_memory", description: "Persist a short summary note to long-term memory. Use for facts, decisions, task outcomes, or anything a future agent or session should know. Keep each note self-contained.", parameters: { type: "object", properties: { content: { type: "string", description: "The summary note to remember" }, category: { type: "string", description: "Optional label, e.g. fact, task, handoff" } }, required: [ "content" ] } }, { name: "recall_memory", description: "Read back previously saved memory notes for the current subject, most recent first. Use before starting work to pick up prior context or another agent's handoff.", parameters: { type: "object", properties: { category: { type: "string", description: "Only return notes with this label" }, limit: { type: "integer", description: "Maximum notes to return (default 20)" } }, required: [] } } ] end |
Instance Method Details
#memory ⇒ Object
The memory record for the current subject (or nil without a subject).
87 88 89 90 91 92 93 |
# File 'lib/solid_agent/has_memory.rb', line 87 def memory config = self.class._memory_config || { scope: DEFAULT_SCOPE, class_name: "AgentMemory" } subject = memory_subject return nil unless subject @memory ||= config[:class_name].constantize.for(subject, scope: config[:scope]) end |
#memory_subject ⇒ Object
The record memory is attached to. Defaults to params, falling back to the HasContext contextable when present. Override for custom subjects.
98 99 100 101 102 103 104 |
# File 'lib/solid_agent/has_memory.rb', line 98 def memory_subject return params[:memorable] if respond_to?(:params) && params.is_a?(Hash) && params[:memorable] context.contextable if respond_to?(:context) && context.respond_to?(:contextable) rescue StandardError nil end |
#memory_tool_definitions ⇒ Object
106 107 108 |
# File 'lib/solid_agent/has_memory.rb', line 106 def memory_tool_definitions SolidAgent::HasMemory.tool_definitions end |
#recall_memory(category: nil, limit: 20) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/solid_agent/has_memory.rb', line 119 def recall_memory(category: nil, limit: 20) return { error: "No memory subject available" } unless memory entries = memory.recall(limit: limit, category: category) { count: entries.size, entries: entries.map do |entry| { content: entry.content, category: (entry.category if entry.respond_to?(:category)), source_agent: (entry.source_agent if entry.respond_to?(:source_agent)), created_at: (entry.created_at.iso8601 if entry.respond_to?(:created_at) && entry.created_at) }.compact end } end |
#save_memory(content:, category: nil) ⇒ Object
Tool implementations — routed here by the provider's tool calls.
112 113 114 115 116 117 |
# File 'lib/solid_agent/has_memory.rb', line 112 def save_memory(content:, category: nil) return { error: "No memory subject available" } unless memory entry = memory.remember(content, source_agent: self.class.name, category: category) { saved: true, id: entry.respond_to?(:id) ? entry.id : nil, content: content } end |