Class: Protege::Trace
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Protege::Trace
- Defined in:
- app/models/protege/trace.rb
Overview
A durable, self-contained snapshot of one inference turn (one provider API call), captured for later
fine-tuning when tracing is enabled. Each row is a training example in the making: the exact
request as sent (the wire conversation — resolved system prompt, history, user turn, tool catalog,
attachment bytes inline) paired with the response it produced and the inference settings
(+model+ + settings) that shaped it, frozen at that instant — unlike ToolUse, which stores only
enough to replay against the current prompts.
Deliberately isolated and minimal: no associations, no foreign keys, and no identity columns
(persona/provider) — a trace records only what affects training, plus a human review verdict. The
table can be truncated or dropped without touching anything else. correlation_id + turn_index
group the turns of one run for retry-safe dedup. Written only by the tracing subscriber
(+Protege::Subscribers::Tracing+); reviewed and labeled in the dashboard.
Class Method Summary collapse
-
.record(correlation_id:, turn_index:, **attributes) ⇒ Protege::Trace
Record one turn's snapshot.
Instance Method Summary collapse
-
#apply_label(label:, annotation: nil) ⇒ void
Apply a human review verdict — the label plus an optional free-text note — stamping the review time so the turn leaves the unlabeled queue.
Class Method Details
.record(correlation_id:, turn_index:, **attributes) ⇒ Protege::Trace
Record one turn's snapshot. Idempotent on [correlation_id, turn_index] so a retried job (which
replays the same run from turn 0) re-snapshots each turn in place rather than duplicating training
rows — the same retry-safety ToolUse.record_round provides. When no correlation id is present
(a run kind that carries none), rows can't be keyed for dedup, so each call simply inserts.
62 63 64 65 66 67 68 |
# File 'app/models/protege/trace.rb', line 62 def record(correlation_id:, turn_index:, **attributes) return create!(correlation_id:, turn_index:, **attributes) if correlation_id.blank? find_or_create_by!(correlation_id:, turn_index:) do |trace| trace.assign_attributes(attributes) end end |
Instance Method Details
#apply_label(label:, annotation: nil) ⇒ void
This method returns an undefined value.
Apply a human review verdict — the label plus an optional free-text note — stamping the review time so the turn leaves the unlabeled queue.
48 49 50 |
# File 'app/models/protege/trace.rb', line 48 def apply_label(label:, annotation: nil) update!(label:, annotation:, reviewed_at: Time.current) end |