Class: Agent::SessionContext::Transcript

Inherits:
Data
  • Object
show all
Defined in:
lib/agent/session_context/transcript.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session:, captured_at:, entries:, warnings:) ⇒ Transcript

Returns a new instance of Transcript.



186
187
188
189
190
191
192
193
# File 'lib/agent/session_context/transcript.rb', line 186

def initialize(session:, captured_at:, entries:, warnings:)
  super(
    session: session,
    captured_at: captured_at,
    entries: normalize_entries(entries),
    warnings: normalize_warnings(warnings)
  )
end

Instance Attribute Details

#captured_at ⇒ Object (readonly)

Returns the value of attribute captured_at

Returns:

  • (Object) —

    the current value of captured_at



111
112
113
# File 'lib/agent/session_context/transcript.rb', line 111

def captured_at
  @captured_at
end

#entries ⇒ Object (readonly)

Returns the value of attribute entries

Returns:

  • (Object) —

    the current value of entries



111
112
113
# File 'lib/agent/session_context/transcript.rb', line 111

def entries
  @entries
end

#session ⇒ Object (readonly)

Returns the value of attribute session

Returns:

  • (Object) —

    the current value of session



111
112
113
# File 'lib/agent/session_context/transcript.rb', line 111

def session
  @session
end

#warnings ⇒ Object (readonly)

Returns the value of attribute warnings

Returns:

  • (Object) —

    the current value of warnings



111
112
113
# File 'lib/agent/session_context/transcript.rb', line 111

def warnings
  @warnings
end

Class Method Details

.capture(session, reader: Agent::Sessions.read(session), now: Time.now) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/agent/session_context/transcript.rb', line 113

def capture(session, reader: Agent::Sessions.read(session), now: Time.now)
  entries = []

  reader.each_message.with_index(1) do |message, message_index|
    entries << TranscriptEntry.new(
      index: message_index,
      role: message.role,
      at: message.at,
      parts: capture_parts(session, message, message_index)
    )
  end

  new(
    session: session,
    captured_at: now,
    entries: entries.freeze,
    warnings: capture_warnings(reader)
  )
end

.injection_kind(agent, text) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/agent/session_context/transcript.rb', line 133

def injection_kind(agent, text)
  return unless text.is_a?(String)

  stripped_text = text.b.lstrip
  marker_kinds = Transcript::INJECTION_MARKERS.fetch(agent&.to_sym, {})
  match = marker_kinds.find { |marker, _kind| stripped_text.start_with?(marker.b) }
  match&.last
end