Class: Phronomy::Agent::SharedState::KnowledgeStore

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeKnowledgeStore

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_allArray<Hash>

Returns a shallow copy of all findings in insertion order.

Returns:

  • (Array<Hash>)


60
61
62
# File 'lib/phronomy/agent/shared_state.rb', line 60

def read_all
  @findings.dup
end

#sizeInteger

Returns the number of findings recorded so far.

Returns:

  • (Integer)


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.

Parameters:

  • agent (Symbol)

    researcher identifier

  • content (String)

    the finding text

  • cycle (Integer)

    the current cycle number

Returns:

  • (nil)


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