Skip to contents

ai_config() sets them for the session (a function's own settings still win); with_ai_config() and local_ai_config() for a block of code, as withr does.

Usage

ai_config(...)

with_ai_config(code, ...)

local_ai_config(..., .local_envir = parent.frame())

Arguments

...

Settings: lm (the model: "gpt-4.1-mini", "claude-haiku-4-5", "gemini:gemini-2.5-flash", ...), temperature, max_tokens, adapter ("xml", "chat", "json"), module ("cot": reasoning first), retries, api_retries, concurrency (calls in flight at once, default 8), on_error ("warn", the default: a failed row is NA; or "stop"), log_calls (a folder, or TRUE), log_content (TRUE, FALSE, c(transcript = FALSE), or the names of the fields to keep), caller, router (an lm15::new_router()); cache_replies (TRUE: in memory; "disk", a folder or a .sqlite file: kept across runs, shared by every language) and replicate (the n-th independent answer to the same request); progress (a progress line over a column); observers (functions given every event), journal (ai_journal()) and program_observers; plugins (ai_plugin()) and program_plugins; approve (a function, "changes", "all", or tool names: see ai_conversation()); escalate_to (a model or an AI function that answers when the first model is less sure than escalate_below, default 0.9).

code

Code to run with these settings.

.local_envir

The environment whose end ends these settings.

Value

The settings in force, invisibly (ai_config()), or the value of code (with_ai_config()).

Details

What the call log keeps (log_content) is not overridden by a closer setting: every layer (a function's own, each block, ai_config(), and the environment variable FUNCTAI_LOG_CONTENT) can only remove. A value is written only when no layer drops it, so a host holds every function it runs to "never write the transcript": with_ai_config(code, log_content = c(transcript = FALSE)), or, surest against a misspelt name, the list of what may be kept, log_content = c("question") (the same as list("*" = FALSE, question = TRUE)). Mind the difference: c(question = TRUE) names one field and says nothing of the others, so it keeps everything; c("question") keeps only the question. A name is always the field of that name (a field FunctAI adds included); a one-output function's answer may also be called by its formula's name when no field has that name. FUNCTAI_LOG_CONTENT=0 drops every value, whatever the settings say. A field FunctAI adds (the reasoning, the tool calls) is written only when no field of the call is dropped. A record that does not keep every value keeps no request or reply either, and no error message.

Examples

ai_config(lm = "gpt-4.1-mini", temperature = 0)