Jido.Thread (Jido v2.0.0-rc.4)

View Source

An append-only log of interaction entries.

Thread is the canonical record of "what happened" in a conversation or workflow. It is provider-agnostic and never modified destructively.

LLM context is derived from Thread via projection functions, not stored directly in Thread.

Example

thread = Thread.new(metadata: %{user_id: "u1"})

thread = Thread.append(thread, %{
  kind: :message,
  payload: %{role: "user", content: "Hello"}
})

Thread.entry_count(thread)  # => 1
Thread.last(thread).kind    # => :message

Summary

Functions

Append entries to thread (returns new thread)

Get entry count

Filter entries by kind

Get entry by seq

Get last entry

Create a new empty thread

Get entries in seq range (inclusive)

Get all entries as list

Types

t()

@type t() :: %Jido.Thread{
  created_at: integer(),
  entries: [any()],
  id: binary(),
  metadata: map(),
  rev: integer(),
  stats: map(),
  updated_at: integer()
}

Functions

append(thread, entries)

@spec append(t(), Jido.Thread.Entry.t() | map() | [Jido.Thread.Entry.t() | map()]) ::
  t()

Append entries to thread (returns new thread)

entry_count(thread)

@spec entry_count(t()) :: non_neg_integer()

Get entry count

filter_by_kind(thread, kinds)

@spec filter_by_kind(t(), atom() | [atom()]) :: [Jido.Thread.Entry.t()]

Filter entries by kind

get_entry(thread, seq)

@spec get_entry(t(), non_neg_integer()) :: Jido.Thread.Entry.t() | nil

Get entry by seq

last(thread)

@spec last(t()) :: Jido.Thread.Entry.t() | nil

Get last entry

new(opts \\ [])

@spec new(keyword()) :: t()

Create a new empty thread

slice(thread, from_seq, to_seq)

Get entries in seq range (inclusive)

to_list(thread)

@spec to_list(t()) :: [Jido.Thread.Entry.t()]

Get all entries as list