Module: Legion::LLM::Hooks::Reciprocity
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/hooks/reciprocity.rb
Overview
Records a :given exchange event on the social graph whenever the LLM responds to a caller that carries an identity. Runs as an after_chat hook.
The hook is intentionally lightweight — it does not block the response path and silently swallows all errors so a social-layer problem never surfaces to the caller.
Class Method Summary collapse
Class Method Details
.install ⇒ Object
18 19 20 21 22 23 |
# File 'lib/legion/llm/hooks/reciprocity.rb', line 18 def install Legion::LLM::Hooks.after_chat do |caller: nil, **| record_reciprocity(caller: caller) nil end end |
.record_reciprocity(caller:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/legion/llm/hooks/reciprocity.rb', line 25 def record_reciprocity(caller:) identity = caller&.dig(:requested_by, :identity) return unless identity runner = return unless runner runner.record_exchange(agent_id: identity, action: :communication, direction: :given) rescue StandardError => e handle_exception(e, level: :debug) end |
.social_runner ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/legion/llm/hooks/reciprocity.rb', line 37 def return nil unless defined?(Legion::Extensions::Agentic::Social::Social::Client) Legion::Extensions::Agentic::Social::Social::Client.new rescue StandardError => e handle_exception(e, level: :debug) nil end |