Class: Phronomy::Agent::SharedState::KnowledgeStore
- Inherits:
-
Object
- Object
- Phronomy::Agent::SharedState::KnowledgeStore
- Defined in:
- lib/phronomy/agent/shared_state.rb
Overview
Thread-safe (serialised by sequential execution) knowledge store shared across all researcher agents within a single #invoke call.
Each finding is stored as a Hash with the keys: :agent — Symbol derived from the researcher class name :content — String written by the researcher :cycle — Integer cycle number in which the finding was recorded
Instance Method Summary collapse
-
#initialize ⇒ KnowledgeStore
constructor
A new instance of KnowledgeStore.
-
#read_all ⇒ Array<Hash>
Returns a shallow copy of all findings in insertion order.
-
#size ⇒ Integer
Returns the number of findings recorded so far.
-
#write(agent:, content:, cycle:) ⇒ nil
Appends a new finding to the store.
Constructor Details
#initialize ⇒ KnowledgeStore
Returns a new instance of KnowledgeStore.
54 55 56 |
# File 'lib/phronomy/agent/shared_state.rb', line 54 def initialize @findings = [] end |
Instance Method Details
#read_all ⇒ Array<Hash>
Returns a shallow copy of all findings in insertion order.
60 61 62 |
# File 'lib/phronomy/agent/shared_state.rb', line 60 def read_all @findings.dup end |
#size ⇒ Integer
Returns the number of findings recorded so far.
76 77 78 |
# File 'lib/phronomy/agent/shared_state.rb', line 76 def size @findings.size end |
#write(agent:, content:, cycle:) ⇒ nil
Appends a new finding to the store.
69 70 71 72 |
# File 'lib/phronomy/agent/shared_state.rb', line 69 def write(agent:, content:, cycle:) @findings << {agent: agent, content: content, cycle: cycle} nil end |