Class: SwarmMemory::DSL::MemoryConfig
- Inherits:
-
Object
- Object
- SwarmMemory::DSL::MemoryConfig
- Defined in:
- lib/swarm_memory/dsl/memory_config.rb
Overview
Memory configuration for agents
This class is injected into SwarmSDK when swarm_memory is required, allowing agents to configure memory via the DSL.
Supports custom adapters through options hash that gets passed through to the adapter constructor.
Instance Attribute Summary collapse
-
#adapter_options ⇒ Object
readonly
Returns the value of attribute adapter_options.
-
#adapter_type ⇒ Object
readonly
Returns the value of attribute adapter_type.
Instance Method Summary collapse
-
#adapter(value = nil) ⇒ Symbol
DSL method to set/get adapter type.
-
#directory(value = nil) ⇒ String
DSL method to set/get directory (convenience for filesystem adapter).
-
#enabled? ⇒ Boolean
Check if memory is enabled.
-
#initialize ⇒ MemoryConfig
constructor
A new instance of MemoryConfig.
-
#keyword_weight(value = nil) ⇒ Float?
DSL method to set/get keyword weight for hybrid search.
-
#mode(value = nil) ⇒ Symbol
DSL method to set/get mode.
-
#option(key, value) ⇒ Object
DSL method to set adapter option (generic).
-
#semantic_weight(value = nil) ⇒ Float?
DSL method to set/get semantic weight for hybrid search.
-
#to_h ⇒ Hash
Convert config to hash (for SDK plugin).
Constructor Details
#initialize ⇒ MemoryConfig
Returns a new instance of MemoryConfig.
28 29 30 31 32 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 28 def initialize @adapter_type = :filesystem # Default adapter @adapter_options = {} # Options passed to adapter constructor @mode = :read_write # Default mode end |
Instance Attribute Details
#adapter_options ⇒ Object (readonly)
Returns the value of attribute adapter_options.
26 27 28 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 26 def @adapter_options end |
#adapter_type ⇒ Object (readonly)
Returns the value of attribute adapter_type.
26 27 28 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 26 def adapter_type @adapter_type end |
Instance Method Details
#adapter(value = nil) ⇒ Symbol
DSL method to set/get adapter type
38 39 40 41 42 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 38 def adapter(value = nil) return @adapter_type if value.nil? @adapter_type = value.to_sym end |
#directory(value = nil) ⇒ String
DSL method to set/get directory (convenience for filesystem adapter)
Equivalent to: option :directory, value
64 65 66 67 68 69 70 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 64 def directory(value = nil) if value.nil? @adapter_options[:directory] else @adapter_options[:directory] = value end end |
#enabled? ⇒ Boolean
Check if memory is enabled
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 127 def enabled? case @adapter_type when :filesystem !@adapter_options[:directory].nil? else # For custom adapters, assume enabled if adapter is set # Custom adapter will validate its own requirements true end end |
#keyword_weight(value = nil) ⇒ Float?
DSL method to set/get keyword weight for hybrid search
Controls how much keyword (tag) matching affects search results. Default is 0.5 (50%). Set to 0.0 to disable keyword matching.
116 117 118 119 120 121 122 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 116 def keyword_weight(value = nil) if value.nil? @adapter_options[:keyword_weight] else @adapter_options[:keyword_weight] = value.to_f end end |
#mode(value = nil) ⇒ Symbol
DSL method to set/get mode
Modes:
- :read_write (default) - Read + Write + Edit, balanced for learning and retrieval
- :read_only - Read-only, optimized for Q&A
- :full_access - All tools including Delete and Defrag, optimized for knowledge management
81 82 83 84 85 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 81 def mode(value = nil) return @mode if value.nil? @mode = value.to_sym end |
#option(key, value) ⇒ Object
DSL method to set adapter option (generic)
This allows passing any option to the adapter constructor.
54 55 56 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 54 def option(key, value) @adapter_options[key.to_sym] = value end |
#semantic_weight(value = nil) ⇒ Float?
DSL method to set/get semantic weight for hybrid search
Controls how much semantic (embedding) similarity affects search results. Default is 0.5 (50%). Set to 1.0 for pure semantic search.
98 99 100 101 102 103 104 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 98 def semantic_weight(value = nil) if value.nil? @adapter_options[:semantic_weight] else @adapter_options[:semantic_weight] = value.to_f end end |
#to_h ⇒ Hash
Convert config to hash (for SDK plugin)
141 142 143 144 145 146 147 148 |
# File 'lib/swarm_memory/dsl/memory_config.rb', line 141 def to_h { adapter: @adapter_type, mode: @mode, loadskill_preserve_delegation: @loadskill_preserve_delegation, **@adapter_options, } end |