## ----include=FALSE------------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE, comment = "#>",
  eval = identical(tolower(Sys.getenv("LLMRAGENT_RUN_VIGNETTES", "false")), "true")
)

## ----design-------------------------------------------------------------------
# library(LLMRagent)
# 
# cfg <- LLMR::llm_config("groq", "openai/gpt-oss-20b", temperature = 0.9)
# 
# base_personas <- c(
#   "An operations manager who values predictability. Plain speech.",
#   "A young engineer enthusiastic about flexible work. Optimistic."
# )
# skeptic  <- "A finance director fixated on costs and risks. Blunt."
# neutral  <- "An HR generalist who weighs evidence carefully. Even-keeled."
# 
# design <- expand.grid(
#   composition = c("with_skeptic", "no_skeptic"),
#   stringsAsFactors = FALSE
# )
# 
# run_cell <- function(cond, rep) {
#   third <- if (cond$composition == "with_skeptic") skeptic else neutral
#   panel <- list(
#     agent("Morgan", cfg, persona = base_personas[1], quiet = TRUE),
#     agent("Sam",    cfg, persona = base_personas[2], quiet = TRUE),
#     agent("Ren",    cfg, persona = third, quiet = TRUE)
#   )
#   deliberate(
#     panel,
#     proposal = "Adopt a four-day work week for a one-year pilot, full pay.",
#     rounds = 2, quiet = TRUE
#   )
# }

## ----run----------------------------------------------------------------------
# LLMR::llm_log_enable("deliberation_runs.jsonl")
# res <- agent_experiment(design, run_cell, reps = 5, quiet = TRUE)
# LLMR::llm_log_disable()
# res[, c("composition", "rep", "error", "duration")]

## ----analyze------------------------------------------------------------------
# votes <- do.call(rbind, lapply(seq_len(nrow(res)), function(i) {
#   d <- res$result[[i]]
#   if (is.null(d)) return(NULL)
#   cbind(composition = res$composition[i], rep = res$rep[i], d$votes)
# }))
# 
# # share of 'yes' votes by composition
# aggregate(I(vote == "yes") ~ composition, data = votes, FUN = mean)
# 
# # and the decisions
# decisions <- vapply(res$result, function(d)
#   if (is.null(d)) NA_character_ else d$decision, character(1))
# table(res$composition, decisions, useNA = "ifany")

