Learn R Programming

LLMAgentR (version 0.2.2)

build_code_agent: Build an R Code Generation Agent

Description

Constructs an LLM-based agent for generating, debugging, explaining, or optimizing R code using structured prompts. The agent handles retries and provides comprehensive code assistance.

Value

A list containing:

  • input - The user's original query

  • llm_response - The processed LLM response

  • system_prompt - The system instructions used

  • success - Logical indicating if call succeeded

  • attempts - Number of tries made

Arguments

llm

A function that accepts a character prompt and returns an LLM response.

system_prompt

Optional system-level instructions for the agent's behavior.

user_input

The user's task/query (e.g., "Write function to filter NAs").

max_tries

Maximum number of attempts for LLM calls (default: 3).

backoff

Seconds to wait between retries (default: 2).

verbose

Logical controlling progress messages (default: TRUE).

Examples

Run this code
if (FALSE) {
coder_agent <- build_code_agent(
  llm = my_llm_wrapper,
  user_input = "Write an R function to standardize numeric columns in a data frame using dplyr.",
  max_tries = 3,
  backoff = 2,
  verbose = FALSE
)
}

Run the code above in your browser using DataLab