CrucibleTrace.Event (CrucibleTrace v0.3.1)

View Source

Represents a single causal reasoning event in the decision chain.

Events capture the decision-making process of LLMs during code generation, including what was chosen, what alternatives were considered, and why.

Summary

Functions

Creates an event from a map (e.g., from JSON parsing).

Creates a new event with the given attributes.

Converts an event to a map suitable for JSON encoding.

Validates an event struct.

Types

event_type()

@type event_type() ::
  :hypothesis_formed
  | :alternative_rejected
  | :constraint_evaluated
  | :pattern_applied
  | :ambiguity_flagged
  | :confidence_updated
  | :training_started
  | :training_completed
  | :epoch_started
  | :epoch_completed
  | :batch_processed
  | :loss_computed
  | :metric_recorded
  | :gradient_computed
  | :checkpoint_saved
  | :checkpoint_loaded
  | :early_stopped
  | :deployment_started
  | :model_loaded
  | :inference_completed
  | :deployment_completed
  | :reward_received
  | :policy_updated
  | :experience_sampled
  | :stage_started
  | :stage_completed

t()

@type t() :: %CrucibleTrace.Event{
  alternatives: [String.t()],
  code_section: String.t() | nil,
  confidence: float(),
  decision: String.t(),
  depends_on: [String.t()],
  experiment_id: String.t() | nil,
  id: String.t(),
  metadata: map(),
  parent_id: String.t() | nil,
  reasoning: String.t(),
  spec_reference: String.t() | nil,
  stage_id: String.t() | nil,
  timestamp: DateTime.t(),
  type: event_type()
}

Functions

from_map(map)

Creates an event from a map (e.g., from JSON parsing).

new(type, decision, reasoning, opts \\ [])

Creates a new event with the given attributes.

Examples

iex> CrucibleTrace.Event.new(:hypothesis_formed, "Use GenServer for state", "Need concurrent state management")
%CrucibleTrace.Event{
  type: :hypothesis_formed,
  decision: "Use GenServer for state",
  reasoning: "Need concurrent state management"
}

to_map(event)

Converts an event to a map suitable for JSON encoding.

validate(event)

Validates an event struct.

Returns {:ok, event} if valid, {:error, reason} otherwise.