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

## ----setup--------------------------------------------------------------------
# library(LLMRagent)
# cfg <- LLMR::llm_config("groq", "openai/gpt-oss-20b", temperature = 0.7)

## ----robustness---------------------------------------------------------------
# rate_risk <- function(cond, rep) {
#   cfg_i <- LLMR::llm_config("groq", "openai/gpt-oss-20b",
#                             temperature = as.numeric(cond$temperature))
#   a <- agent("Rater", cfg_i)
#   r <- a$reply("On a scale of 1 to 10, how risky is skydiving? Reply with only the integer.")
#   as.numeric(gsub("[^0-9].*$", "", trimws(r)))
# }
# 
# battery <- agent_robustness(
#   rate_risk,
#   vary    = list(temperature = c("0", "1")),
#   reps    = 3,
#   measure = function(r) r,
#   .config = cfg
# )
# 
# battery$by_axis   # instability, dispersion, agreement along each axis
# battery$overall   # a single 'fragile' verdict

## ----calibrate----------------------------------------------------------------
# # model coded all 12 statements; a human labeled the first 6
# preds <- c(1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0)   # the model's codings (all units)
# gold  <- tibble::tibble(id = 1:6, value = c(1, 0, 1, 0, 1, 0))  # human labels (subset)
# 
# cal <- agent_calibrate(
#   predictions = preds,
#   gold        = gold,        # (id, value): the labeled subset
#   id          = 1:12,        # the id vector for ALL units (length == length(preds))
#   method      = "ppi",
#   estimand    = "proportion"
# )
# 
# cal$naive$estimate     # the biased plug-in: just mean(preds)
# cal$estimate           # the calibrated estimate, with a confidence interval

## ----claims-------------------------------------------------------------------
# run <- as_agent_run(
#   agent("Coder", cfg)$reply("Is this abstract about climate? Answer yes or no.\n...")
# )
# 
# # a coding run is a coding run; calling it a population estimate is refused
# tryCatch(
#   mark_claim_type(run, "calibrated_inference"),
#   llmragent_claim_error = function(e) "refused: no calibration is attached"
# )
# 
# mark_claim_type(run, "coding")   # this is honest

