diff --git a/enterprise/app/services/captain/assistant/session_capture_service.rb b/enterprise/app/services/captain/assistant/session_capture_service.rb index 36af50308..ceeb28210 100644 --- a/enterprise/app/services/captain/assistant/session_capture_service.rb +++ b/enterprise/app/services/captain/assistant/session_capture_service.rb @@ -59,6 +59,11 @@ class Captain::Assistant::SessionCaptureService def current_turn_history history = Array(context[:conversation_history]) last_user_index = history.rindex { |message| message[:role].to_s == 'user' } - last_user_index ? history[last_user_index..] : history + current_turn = last_user_index ? history[last_user_index..] : history + + current_turn.map do |message| + content = message[:content] + content.is_a?(RubyLLM::Content) ? message.merge(content: content.to_h) : message + end end end diff --git a/spec/enterprise/services/captain/assistant/session_capture_service_spec.rb b/spec/enterprise/services/captain/assistant/session_capture_service_spec.rb index ef25b1e2b..daf38c8d6 100644 --- a/spec/enterprise/services/captain/assistant/session_capture_service_spec.rb +++ b/spec/enterprise/services/captain/assistant/session_capture_service_spec.rb @@ -111,6 +111,25 @@ RSpec.describe Captain::Assistant::SessionCaptureService do expect(history.first).to include('role' => 'user', 'content' => 'CUST001') end + it 'stores multimodal content without cached attachment bytes' do + content = RubyLLM::Content.new('See image', ['https://example.com/image.jpg']) + content.attachments.first.instance_variable_set(:@content, "\xFF\xD8\xFF\xE0JFIF".b) + run_context[:conversation_history] = [ + { role: :user, content: content }, + { role: :assistant, content: 'I can see the image', agent_name: 'Assistant' } + ] + + history = service.capture!.run_context + + expect(history.first).to include( + 'role' => 'user', + 'content' => { + 'text' => 'See image', + 'attachments' => [{ 'type' => 'image', 'source' => 'https://example.com/image.jpg' }] + } + ) + end + it 'stores the full history when it contains no user message' do run_context[:conversation_history] = conversation_history.reject { |message| message[:role] == :user }