Skip to contents

ConversationFlow is an R6 base class defining the interface for turn-taking mechanisms in a focus group simulation. Subclasses implement specific strategies for selecting the next speaker.

Value

An R6 generator meant for subclassing; instances are built by create_conversation_flow(), which returns a ConversationFlow subclass object ready for FocusGroup.

Methods for Subclassing

initialize(agents, moderator_id)

Sets up the flow. Call super$initialize(agents, moderator_id).

select_next_speaker(focus_group)

Required. Logic to choose the next FGAgent to speak. Should return the agent object or NULL.

update_state_post_selection(speaker_id, focus_group)

Optional. Updates internal state after a speaker has spoken. Base implementation updates self$last_speaker_id.

note_moderator_turn()

Optional. Called after every moderator line: a guide item, a call-on line, or an injected moderator message. Base implementation clears self$last_speaker_id, so that a flow that passes over the previous speaker bars only back-to-back participant turns.

Public fields

agents

A named list of FGAgent objects participating in the conversation.

participant_ids

A character vector of agent identifiers, excluding the moderator.

moderator_id

Character. The ID of the moderator agent.

last_speaker_id

The ID of the agent who last spoke. Can be NULL.

selection_metadata

Details recorded for the latest selection when it departs from the flow's usual rule, such as a lowered desire threshold or, under on_desire_failure = "random", a desire-scoring failure.

routing_record

The record of the latest selection, whatever rule made it: a list with flow, rule, candidates, excluded (a named character vector giving the reason each excluded participant was passed over), scores, threshold, tied, tie_break, and selected_id. A running session copies it into its routing record after every pick. A subclass that does not set it is recorded with rule "custom".

Methods


Method new()

Initializes the ConversationFlow object.

Usage

ConversationFlow$new(agents, moderator_id)

Arguments

agents

A named list of FGAgent objects.

moderator_id

Character. The ID of the moderator agent.


Method select_next_speaker()

Selects the next speaker. Must be implemented by subclasses.

Usage

ConversationFlow$select_next_speaker(focus_group)

Arguments

focus_group

The FocusGroup object managing the simulation, providing context.

Returns

The FGAgent object of the selected speaker, or NULL.


Method update_state_post_selection()

Updates internal state after a speaker is selected.

Usage

ConversationFlow$update_state_post_selection(speaker_id, focus_group)

Arguments

speaker_id

The ID of the agent who was selected and just spoke.

focus_group

The FocusGroup object.


Method note_moderator_turn()

Notes that the moderator has just spoken. The participant who spoke before the moderator's line is then no longer the previous speaker: whoever closed one question may open the next.

Usage

ConversationFlow$note_moderator_turn()

Returns

The flow, invisibly.


Method clone()

The objects of this class are cloneable with this method.

Usage

ConversationFlow$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

RandomFlow <- R6::R6Class("RandomFlow", inherit = ConversationFlow,
  public = list(
    select_next_speaker = function(focus_group) {
      ids <- self$participant_ids
      self$agents[[sample(ids, 1)]]
    }))