Module: SwarmSDK::Agent::ChatHelpers::Serialization
- Included in:
- SwarmSDK::Agent::Chat
- Defined in:
- lib/swarm_sdk/agent/chat_helpers/serialization.rb
Overview
Message serialization and deserialization for snapshots
Extracted from Chat to reduce class size and centralize persistence logic.
Instance Method Summary collapse
-
#conversation_snapshot ⇒ Hash
Create snapshot of current conversation state.
-
#restore_conversation(snapshot) ⇒ self
Restore conversation from snapshot.
Instance Method Details
#conversation_snapshot ⇒ Hash
Create snapshot of current conversation state
13 14 15 16 17 18 19 20 |
# File 'lib/swarm_sdk/agent/chat_helpers/serialization.rb', line 13 def conversation_snapshot { messages: @llm_chat..map { |msg| (msg) }, model_id: model_id, provider: model_provider, timestamp: Time.now.utc.iso8601, } end |
#restore_conversation(snapshot) ⇒ self
Restore conversation from snapshot
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/swarm_sdk/agent/chat_helpers/serialization.rb', line 26 def restore_conversation(snapshot) raise ArgumentError, "Invalid snapshot: missing messages" unless snapshot[:messages] @llm_chat..clear snapshot[:messages].each do |msg_data| @llm_chat. << (msg_data) end self end |