Class: Insika::ContextFragment
- Inherits:
-
Data
- Object
- Data
- Insika::ContextFragment
- Defined in:
- lib/insika/context/fragment.rb
Overview
Unit of context produced by a provider. SHARED type (Insika::, not Insika::Context::). placement: :system | :history | :tool_context priority: Integer; higher = more important (survives cuts) tokens: Integer | nil; estimated by the Builder when nil source: String — provider id (audit) pinned: true -> uncuttable in the budget (e.g. identity) labels: [{ "name" =>, "reason" => }] — WHAT this fragment carries and WHY, as ids. Content-FREE by contract, so the context trace can report which skills a turn injected without storing a byte of the bodies. [] = nothing to name (the default for every provider that has no natural id, e.g. the identity prompt).
The REASON is the point. A name alone answers "was something
injected"; the operator's actual question is "which skill did I
trigger, and why is it here" — `eager` (the agent always wants it),
`trigger:<matched phrase>` (this message asked for it), or absent
for a body a plugin supplied. String keys because these labels are
written to the context trace and to events as JSON: the round-trip
is then the identity, and no reader has to defend against both.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#pinned ⇒ Object
readonly
Returns the value of attribute pinned.
-
#placement ⇒ Object
readonly
Returns the value of attribute placement.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
- .build(content:, placement:, source:, priority: 50, tokens: nil, pinned: false, labels: []) ⇒ Object
-
.label(raw) ⇒ Object
A bare String is still a valid label (a provider that has an id but no reason to give) — it normalizes to a reason-less entry rather than being rejected.
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def content @content end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def labels @labels end |
#pinned ⇒ Object (readonly)
Returns the value of attribute pinned
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def pinned @pinned end |
#placement ⇒ Object (readonly)
Returns the value of attribute placement
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def placement @placement end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def priority @priority end |
#source ⇒ Object (readonly)
Returns the value of attribute source
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def source @source end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens
24 25 26 |
# File 'lib/insika/context/fragment.rb', line 24 def tokens @tokens end |
Class Method Details
.build(content:, placement:, source:, priority: 50, tokens: nil, pinned: false, labels: []) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/insika/context/fragment.rb', line 26 def self.build(content:, placement:, source:, priority: 50, tokens: nil, pinned: false, labels: []) new(content: content, placement: placement, priority: priority, tokens: tokens, source: source, pinned: pinned, labels: Array(labels).map { |l| label(l) }) end |
.label(raw) ⇒ Object
A bare String is still a valid label (a provider that has an id but no reason to give) — it normalizes to a reason-less entry rather than being rejected.
35 36 37 38 39 40 41 |
# File 'lib/insika/context/fragment.rb', line 35 def self.label(raw) return { "name" => raw.to_s }.freeze unless raw.is_a?(Hash) name = (raw[:name] || raw["name"]).to_s reason = raw[:reason] || raw["reason"] { "name" => name, "reason" => reason&.to_s }.compact.freeze end |