Class: RobotLab::Durable::Hook
- Inherits:
-
Hook
- Object
- Hook
- RobotLab::Durable::Hook
- Defined in:
- lib/robot_lab/durable/hook.rb
Class Method Summary collapse
-
.around_run(ctx, &block) ⇒ Object
Initialize an HTM-backed adapter for the robot and make it available thread-locally for the duration of the run, then tear it down.
-
.current_adapter ⇒ Object
Returns the active durable adapter for the current thread, or nil.
-
.on_learn(ctx) ⇒ Object
Persist new session learnings to HTM long-term memory.
Class Method Details
.around_run(ctx, &block) ⇒ Object
Initialize an HTM-backed adapter for the robot and make it available thread-locally for the duration of the run, then tear it down.
11 12 13 14 15 16 17 |
# File 'lib/robot_lab/durable/hook.rb', line 11 def around_run(ctx, &block) robot_name = ctx.robot.name || 'default' set_adapter(Adapter.new(robot_name: robot_name)) block.call ensure clear_adapter end |
.current_adapter ⇒ Object
Returns the active durable adapter for the current thread, or nil.
32 33 34 |
# File 'lib/robot_lab/durable/hook.rb', line 32 def current_adapter Thread.current[:robot_lab_durable_adapter] end |
.on_learn(ctx) ⇒ Object
Persist new session learnings to HTM long-term memory. HTM deduplicates by content hash, so double-writes from RecordKnowledge are harmless — the second call simply increments remember_count.
22 23 24 25 26 27 28 29 |
# File 'lib/robot_lab/durable/hook.rb', line 22 def on_learn(ctx) return unless ctx.stored adapter = current_adapter return unless adapter adapter.record(content: ctx.text, category: :observation) end |