Budgets are hard limits, checked before every model call. When a limit
would be exceeded, the agent raises a condition of class
llmragent_budget_error instead of calling the API, so a runaway loop
cannot spend without leaving a record. Catch it with tryCatch() if you want
graceful degradation.
Examples
b <- budget(max_calls = 10, max_tokens = 50000)
if (FALSE) { # \dontrun{
cfg <- LLMR::llm_config("groq", "openai/gpt-oss-20b")
frugal <- agent("Frugal", cfg, budget = budget(max_calls = 2))
frugal$chat("one")
frugal$chat("two")
tryCatch(frugal$chat("three"),
llmragent_budget_error = function(e) "refused before spending")
} # }