Class: OllamaAgent::Memory::Manager
- Inherits:
-
Object
- Object
- OllamaAgent::Memory::Manager
- Defined in:
- lib/ollama_agent/memory/manager.rb
Overview
Unified memory interface exposing all three tiers.
Tier semantics:
:short_term — sliding window of the current run; cleared at run end
:session — key-value store for this session; persisted to YAML in project dir
:long_term — global persistent store in ~/.config/ollama_agent/memory/
Instance Attribute Summary collapse
-
#long_term ⇒ Object
readonly
Returns the value of attribute long_term.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#short_term ⇒ Object
readonly
Returns the value of attribute short_term.
Instance Method Summary collapse
- #active_goals ⇒ Object
- #complete_goal(description) ⇒ Object
-
#flush_short_term! ⇒ Object
Call at the end of each run to clear short-term memory.
-
#forget(key, tier: :long_term, namespace: "default") ⇒ Object
Forget a fact from the specified tier.
-
#initialize(root:, session_id: nil, long_term_path: nil) ⇒ Manager
constructor
A new instance of Manager.
-
#list(tier: :long_term, namespace: "default") ⇒ Object
List all keys in a tier/namespace.
-
#recall(key, tier: :long_term, namespace: "default") ⇒ Object
Retrieve a fact from the specified tier.
- #recent_context(n = 10) ⇒ Object
- #record_observation(text) ⇒ Object
-
#record_tool_call(tool_name, args, result = nil) ⇒ Object
── Short-term recording ─────────────────────────────────────────────.
-
#remember(key, value, tier: :long_term, namespace: "default") ⇒ Object
Store a fact at the specified tier.
-
#search(pattern, namespace: "default") ⇒ Object
Search long-term memory for entries matching a pattern.
-
#set_goal(description) ⇒ Object
── Goal tracking ─────────────────────────────────────────────────────.
- #summary ⇒ Object
Constructor Details
#initialize(root:, session_id: nil, long_term_path: nil) ⇒ Manager
Returns a new instance of Manager.
24 25 26 27 28 |
# File 'lib/ollama_agent/memory/manager.rb', line 24 def initialize(root:, session_id: nil, long_term_path: nil) @short_term = ShortTerm.new @session = SessionMemory.new(root: root, session_id: session_id) @long_term = LongTerm.new(base_path: long_term_path || LongTerm::DEFAULT_BASE) end |
Instance Attribute Details
#long_term ⇒ Object (readonly)
Returns the value of attribute long_term.
22 23 24 |
# File 'lib/ollama_agent/memory/manager.rb', line 22 def long_term @long_term end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
22 23 24 |
# File 'lib/ollama_agent/memory/manager.rb', line 22 def session @session end |
#short_term ⇒ Object (readonly)
Returns the value of attribute short_term.
22 23 24 |
# File 'lib/ollama_agent/memory/manager.rb', line 22 def short_term @short_term end |
Instance Method Details
#active_goals ⇒ Object
100 101 102 |
# File 'lib/ollama_agent/memory/manager.rb', line 100 def active_goals @session.active_goals end |
#complete_goal(description) ⇒ Object
96 97 98 |
# File 'lib/ollama_agent/memory/manager.rb', line 96 def complete_goal(description) @session.complete_goal(description) end |
#flush_short_term! ⇒ Object
Call at the end of each run to clear short-term memory.
107 108 109 |
# File 'lib/ollama_agent/memory/manager.rb', line 107 def flush_short_term! @short_term.clear! end |
#forget(key, tier: :long_term, namespace: "default") ⇒ Object
Forget a fact from the specified tier.
69 70 71 72 73 74 |
# File 'lib/ollama_agent/memory/manager.rb', line 69 def forget(key, tier: :long_term, namespace: "default") case tier.to_sym when :long_term then @long_term.delete(key.to_s, namespace: namespace) when :session then @session.delete(key.to_s) end end |
#list(tier: :long_term, namespace: "default") ⇒ Object
List all keys in a tier/namespace.
77 78 79 80 81 82 83 |
# File 'lib/ollama_agent/memory/manager.rb', line 77 def list(tier: :long_term, namespace: "default") case tier.to_sym when :long_term then @long_term.all(namespace: namespace) when :session then @session.all else {} end end |
#recall(key, tier: :long_term, namespace: "default") ⇒ Object
Retrieve a fact from the specified tier.
61 62 63 64 65 66 |
# File 'lib/ollama_agent/memory/manager.rb', line 61 def recall(key, tier: :long_term, namespace: "default") case tier.to_sym when :long_term then @long_term.fetch(key.to_s, namespace: namespace) when :session then @session.get(key.to_s) end end |
#recent_context(n = 10) ⇒ Object
41 42 43 |
# File 'lib/ollama_agent/memory/manager.rb', line 41 def recent_context(n = 10) @short_term.recent(n) end |
#record_observation(text) ⇒ Object
37 38 39 |
# File 'lib/ollama_agent/memory/manager.rb', line 37 def record_observation(text) @short_term.record(:observation, text) end |
#record_tool_call(tool_name, args, result = nil) ⇒ Object
── Short-term recording ─────────────────────────────────────────────
32 33 34 35 |
# File 'lib/ollama_agent/memory/manager.rb', line 32 def record_tool_call(tool_name, args, result = nil) @short_term.record(:tool_call, { tool: tool_name.to_s, args: args }) @short_term.record(:tool_result, { tool: tool_name.to_s, result: result.to_s[0, 500] }) if result end |
#remember(key, value, tier: :long_term, namespace: "default") ⇒ Object
Store a fact at the specified tier.
52 53 54 55 56 57 58 |
# File 'lib/ollama_agent/memory/manager.rb', line 52 def remember(key, value, tier: :long_term, namespace: "default") case tier.to_sym when :long_term then @long_term.store(key.to_s, value, namespace: namespace) when :session then @session.set(key.to_s, value) else raise ArgumentError, "Unknown memory tier: #{tier}" end end |
#search(pattern, namespace: "default") ⇒ Object
Search long-term memory for entries matching a pattern.
86 87 88 |
# File 'lib/ollama_agent/memory/manager.rb', line 86 def search(pattern, namespace: "default") @long_term.search(pattern, namespace: namespace) end |
#set_goal(description) ⇒ Object
── Goal tracking ─────────────────────────────────────────────────────
92 93 94 |
# File 'lib/ollama_agent/memory/manager.rb', line 92 def set_goal(description) @session.set_goal(description) end |
#summary ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/ollama_agent/memory/manager.rb', line 111 def summary { short_term_entries: @short_term.size, session_keys: @session.keys.size, long_term_namespaces: @long_term.namespaces.size } end |