Skip to contents

Creates a string representation of the recent conversation history, optionally including a summary of earlier parts of the discussion.

Usage

format_conversation_history(
  conversation_log,
  n_recent = NULL,
  include_summary = NULL,
  max_tokens_history = 64000L
)

Arguments

conversation_log

A list of message objects from the simulation. Each message should be a list with at least `speaker_id` and `text`.

n_recent

Integer. Optional. The number of most recent messages to include in detail.

include_summary

Character string. An optional summary of earlier parts of the conversation to prepend to the recent history.

max_tokens_history

Integer. Approximate token ceiling for dynamically selected history when `n_recent` is `NULL`.

Value

A character string representing the formatted conversation history.

Examples

log <- list(
  list(speaker_id = "Alice", text = "Hello!"),
  list(speaker_id = "Bob", text = "Hi Alice!"),
  list(speaker_id = "Alice", text = "How are you?")
)
format_conversation_history(log, n_recent = 2)
#> [1] "Bob: Hi Alice!\nAlice: How are you?"
format_conversation_history(log, include_summary = "They greeted each other.")
#> [1] "Summary of earlier discussion: They greeted each other. \n---\nRecent turns:\nAlice: Hello!\nBob: Hi Alice!\nAlice: How are you?"