FGAgent Class
FGAgent Class
Details
Represents an agent (participant or moderator) in a focus group simulation. Each agent has a unique ID, a persona, an LLM configuration, and methods to generate utterances and express a desire to speak.
Customizing Agents
`FGAgent` is designed to be flexible:
**Per-Agent LLM Configuration**: Each agent is initialized with its own `model_config`. This allows different agents to use different LLMs, temperatures, or even providers.
**Persona Definition**: The `agent_details` (containing `demographics`, `survey_responses`, `direct_persona_description`, and/or `communication_style`) are used to construct the `persona_description` and `communication_style_instruction`.
**Subclassing**: For advanced customization, inherit from `FGAgent` to override methods or add new fields.
Public fields
idCharacter. Unique identifier for the agent.
persona_descriptionCharacter. Textual description of the agent's persona, derived from demographics, survey responses, or direct input.
communication_style_instructionCharacter. A specific instruction about the agent's communication style, to be included in prompts.
model_configAn `llm_config` object (from the `LLMR` package) specifying the LLM provider, model, API key, and other parameters for this agent.
is_moderatorLogical. `TRUE` if the agent is the moderator, `FALSE` otherwise.
historyList. A log of utterances made by this agent during the simulation.
tokens_sent_agentNumeric. Total tokens sent by this agent.
tokens_received_agentNumeric. Total tokens received by this agent.
roleCharacter. "moderator" or "participant" for convenience in reports.
demographicsNamed list. Raw demographics used to build persona.
survey_responsesNamed list. Raw survey responses used to build persona.
Methods
Method new()
Initialize a new FGAgent.
Usage
FGAgent$new(id, agent_details, model_config, is_moderator = FALSE)Arguments
idCharacter. A unique identifier for the agent.
agent_detailsList. Contains information to build the agent's persona. Can include:
`demographics`: A named list of demographic attributes (e.g., `list(age = 30, occupation = "teacher")`).
`survey_responses`: A named list of survey questions and answers.
`direct_persona_description`: A character string to be used directly as the persona. Overrides demographics/survey if provided.
`communication_style`: A character string describing the agent's communication style (e.g., "analytical and direct", "empathetic and story-driven").
If `is_moderator` is `TRUE` and no specific details are provided, a default moderator persona is used.
model_configAn `llm_config` object from `LLMR::llm_config()`.
is_moderatorLogical. `TRUE` if this agent is the moderator, `FALSE` otherwise.
Method generate_utterance()
Generate an utterance for the agent.
Usage
FGAgent$generate_utterance(
topic,
conversation_history_string,
utterance_prompt_template,
max_tokens_utterance = 150,
current_moderator_question = "N/A",
conversation_summary_so_far = "N/A",
current_phase = "discussion",
conversation_log = NULL,
standing_rules = NULL,
self_state = TRUE
)Arguments
topicCharacter. The current discussion topic.
conversation_history_stringCharacter. Formatted string of recent conversation history.
utterance_prompt_templateCharacter. The prompt template to use.
max_tokens_utteranceInteger. Maximum tokens for the generated utterance.
current_moderator_questionCharacter. The current question posed by the moderator.
conversation_summary_so_farCharacter. A summary of earlier parts of the conversation.
current_phaseCharacter. The current phase of the focus group (e.g., "icebreaker", "exploration").
Method get_need_to_talk()
Get the agent's "desire to talk" score. This method queries the LLM to rate how strongly the agent feels the need to contribute to the discussion at the current moment.
Usage
FGAgent$get_need_to_talk(
topic,
conversation_history_string,
desire_prompt_template,
max_tokens_desire = 20,
current_moderator_question = "N/A",
last_speaker_id = "N/A",
last_utterance_text = "N/A",
conversation_log = NULL
)Arguments
topicCharacter. The current discussion topic.
conversation_history_stringCharacter. Formatted string of recent conversation history.
desire_prompt_templateCharacter. The prompt template to use for this query.
max_tokens_desireInteger. Maximum tokens for the LLM's response to the desire query.
current_moderator_questionCharacter. The current question posed by the moderator.
last_speaker_idCharacter. The ID of the agent who spoke last.
last_utterance_textCharacter. The text of the last utterance.
