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) layer: :identity | :volatile | nil. Stamped by the Builder at production from the provider's declaration; nil (a fragment built outside the Builder) reads as :volatile everywhere it is consumed — parity, never a crash. 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.
-
#layer ⇒ Object
readonly
Returns the value of attribute layer.
-
#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: [], layer: nil) ⇒ 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
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def content @content end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def labels @labels end |
#layer ⇒ Object (readonly)
Returns the value of attribute layer
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def layer @layer end |
#pinned ⇒ Object (readonly)
Returns the value of attribute pinned
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def pinned @pinned end |
#placement ⇒ Object (readonly)
Returns the value of attribute placement
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def placement @placement end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def priority @priority end |
#source ⇒ Object (readonly)
Returns the value of attribute source
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def source @source end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens
28 29 30 |
# File 'lib/insika/context/fragment.rb', line 28 def tokens @tokens end |
Class Method Details
.build(content:, placement:, source:, priority: 50, tokens: nil, pinned: false, labels: [], layer: nil) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/insika/context/fragment.rb', line 30 def self.build(content:, placement:, source:, priority: 50, tokens: nil, pinned: false, labels: [], layer: nil) new(content: content, placement: placement, priority: priority, tokens: tokens, source: source, pinned: pinned, labels: Array(labels).map { |l| label(l) }, layer: layer) 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.
39 40 41 42 43 44 45 |
# File 'lib/insika/context/fragment.rb', line 39 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 |