Class: SmartBrain::Consolidator::WorkingSummary
- Inherits:
-
Object
- Object
- SmartBrain::Consolidator::WorkingSummary
- Defined in:
- lib/smart_brain/consolidator/working_summary.rb
Overview
WorkingSummary is store-backed: summaries persist via the MemoryStore (in-memory hash for MemoryStore::InMemory, the summaries table for MemoryStore::Postgres), so they survive runtime restarts on the PG path. The last-summary turn is derived from the persisted summary's source range.
When a real LLM ModelProvider is wired, the summary text is generated by the model (qwen3 etc.); otherwise it falls back to the deterministic template (Stub default), so behavior is stable and offline-friendly.
Constant Summary collapse
- SUMMARY_SYSTEM =
'You are a memory consolidator. Produce a concise rolling ' \ 'summary in the exact section structure given. Skip empty ' \ 'sections. No preamble, no markdown fences.'
Instance Method Summary collapse
-
#initialize(config:, clock:, memory_store:, model_provider: SmartBrain::ModelProvider::Stub.new) ⇒ WorkingSummary
constructor
A new instance of WorkingSummary.
- #latest_summary(session_id) ⇒ Object
- #update(session_id:, turn_count:, recent_turns:, memory_items:, stage_event: false) ⇒ Object
Constructor Details
#initialize(config:, clock:, memory_store:, model_provider: SmartBrain::ModelProvider::Stub.new) ⇒ WorkingSummary
Returns a new instance of WorkingSummary.
20 21 22 23 24 25 |
# File 'lib/smart_brain/consolidator/working_summary.rb', line 20 def initialize(config:, clock:, memory_store:, model_provider: SmartBrain::ModelProvider::Stub.new) @config = config @clock = clock @memory_store = memory_store @model_provider = model_provider end |
Instance Method Details
#latest_summary(session_id) ⇒ Object
47 48 49 |
# File 'lib/smart_brain/consolidator/working_summary.rb', line 47 def latest_summary(session_id) memory_store.latest_summary(session_id: session_id) || default_summary end |
#update(session_id:, turn_count:, recent_turns:, memory_items:, stage_event: false) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/smart_brain/consolidator/working_summary.rb', line 27 def update(session_id:, turn_count:, recent_turns:, memory_items:, stage_event: false) reason = trigger_reason(session_id: session_id, turn_count: turn_count, recent_turns: recent_turns, stage_event: stage_event) unless reason return latest_summary(session_id).merge(triggered: false, trigger_reason: 'not_triggered') end text, method = build_summary_text(memory_items: memory_items, recent_turns: recent_turns) summary = { summary_version: next_version(session_id), summary_source_turn_range: source_turn_range(turn_count), summary_generated_at: clock.call.iso8601, text: text, summary_method: method, triggered: true, trigger_reason: reason } memory_store.save_summary(session_id: session_id, summary: summary) summary end |