Class: Agent::Sessions::Message
- Inherits:
-
Data
- Object
- Data
- Agent::Sessions::Message
- Defined in:
- lib/agent/sessions/message.rb
Overview
One turn. role is normalized to :user, :assistant, :system or :tool, with
:unknown for a role the adapter did not recognize — the four the spec names
were written before any real corpus was read, and Codex promptly said
"developer".
raw is never dropped (Layer 3 rule 1): when this normalization is wrong or incomplete, a caller escapes the abstraction instead of forking the gem.
usage and model are nil wherever the format does not put them on the
message itself — Codex records tokens in separate event records and the
model in its session header, so its messages carry neither; the reader's
session-level usage is where those formats answer. A nil here means
"not recorded on this message", never "zero tokens".
Constant Summary collapse
- ROLES =
%i[user assistant system tool unknown].freeze
Instance Attribute Summary collapse
-
#at ⇒ Object
readonly
Returns the value of attribute at.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
-
#initialize(role:, at:, parts:, raw:, usage: nil, model: nil) ⇒ Message
constructor
A new instance of Message.
-
#text ⇒ Object
Concatenated :text parts, as the design doc specifies — no separator inserted, because a separator is a formatting decision this layer has no business making.
Constructor Details
#initialize(role:, at:, parts:, raw:, usage: nil, model: nil) ⇒ Message
Returns a new instance of Message.
19 20 21 22 23 24 |
# File 'lib/agent/sessions/message.rb', line 19 def initialize(role:, at:, parts:, raw:, usage: nil, model: nil) roles = self.class::ROLES raise ArgumentError, "role #{role.inspect} must be one of #{roles.join(", ")}" unless roles.include?(role) super end |
Instance Attribute Details
#at ⇒ Object (readonly)
Returns the value of attribute at
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def at @at end |
#model ⇒ Object (readonly)
Returns the value of attribute model
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def model @model end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def parts @parts end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def raw @raw end |
#role ⇒ Object (readonly)
Returns the value of attribute role
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def role @role end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage
18 19 20 |
# File 'lib/agent/sessions/message.rb', line 18 def usage @usage end |
Instance Method Details
#text ⇒ Object
Concatenated :text parts, as the design doc specifies — no separator
inserted, because a separator is a formatting decision this layer has no
business making. A caller that needs the boundaries has parts.
29 30 31 |
# File 'lib/agent/sessions/message.rb', line 29 def text parts.select { |part| part.type == :text }.map(&:text).join end |