Module: Agents::Helpers::MessageExtractor
- Defined in:
- lib/agents/helpers/message_extractor.rb
Constant Summary collapse
- AUTHORING_AGENT_IVAR =
RubyLLM::Message has no metadata/extension API, so agent ownership is stored as an SDK-namespaced ivar on the message object until it is extracted.
Caveat: RubyLLM::Message#instance_variables is overridden to hide :@raw but does not hide this ivar, so it will appear in instance_variables listings. This is harmless for our own code path (we read it via instance_variable_get and serialize through extract_messages, not Marshal), but external introspection of a message’s ivars will see :@agents_authoring_agent.
:@agents_authoring_agent
Class Method Summary collapse
- .assign_agent_name(message, agent_name) ⇒ Object
- .attributed_agent_name_for(message) ⇒ Object
-
.content_empty?(content) ⇒ Boolean
Check if content is considered empty (handles both String and Hash content).
-
.extract_messages(chat, current_agent) ⇒ Array<Hash>
Extract messages from a chat object for conversation history persistence.
Class Method Details
.assign_agent_name(message, agent_name) ⇒ Object
33 34 35 36 37 |
# File 'lib/agents/helpers/message_extractor.rb', line 33 def assign_agent_name(, agent_name) return unless && agent_name .instance_variable_set(AUTHORING_AGENT_IVAR, agent_name) end |
.attributed_agent_name_for(message) ⇒ Object
39 40 41 42 43 |
# File 'lib/agents/helpers/message_extractor.rb', line 39 def attributed_agent_name_for() return unless &.instance_variable_defined?(AUTHORING_AGENT_IVAR) .instance_variable_get(AUTHORING_AGENT_IVAR) end |
.content_empty?(content) ⇒ Boolean
Check if content is considered empty (handles both String and Hash content)
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/agents/helpers/message_extractor.rb', line 49 def content_empty?(content) case content when String content.strip.empty? when Hash content.empty? else content.nil? end end |
.extract_messages(chat, current_agent) ⇒ Array<Hash>
Extract messages from a chat object for conversation history persistence
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/agents/helpers/message_extractor.rb', line 65 def (chat, current_agent) return [] unless chat.respond_to?(:messages) chat..filter_map do |msg| case msg.role when :user, :assistant (msg, current_agent) when :tool (msg) end end end |