Learn R Programming

LLMAgentR

Overview

LLMAgentR is an R package for building Language Model Agents using a modular state graph execution framework. Inspired by LangGraph and LangChain architectures, it supports iterative workflows for research, data analysis, and automation.


Installation

install.packages("LLMAgentR")

Development version

To get the latest features or bug fixes, you can install the development version of LLMAgentR from GitHub:

# If needed
install.packages("remotes")

remotes::install_github("knowusuboaky/LLMAgentR")

See the full function reference or the package website for more details.


Environment Setup

API Setup

Sys.setenv(
  OPENAI_API_KEY = "your-key",
  GROQ_API_KEY = "your-key",
  ANTHROPIC_API_KEY = "your-key",
  TAVILY_API_KEY = "your-key",
  OPENWEATHERMAP_API_KEY = "your-key"
)

LLM Support (Minimal Wrapper)

Load the package and either call an LLM directly or create a reusable wrapper:

# Load the chatLLM package
library(chatLLM)

# Direct call example
call_llm(
  prompt = "Summarize the capital of France.",
  provider = "groq",
  model = "llama3-8b",
  temperature = 0.7,
  max_tokens = 200
)

# Silent Minimal wrapper around call_llm() with verbose option
my_llm_wrapper <- function(prompt, verbose = FALSE) {
  if (verbose) {
    message("[my_llm_wrapper] Sending prompt to LLM...")
  }
  
  # Suppress only the printing, NOT the return value
  response_text <- if (verbose) {
    call_llm(
      prompt      = prompt,
      provider    = "openai",
      model       = "gpt-4o",
      max_tokens  = 3000
    )
  } else {
    suppressMessages(
      suppressWarnings(
        call_llm(
          prompt      = prompt,
          provider    = "openai",
          model       = "gpt-4o",
          max_tokens  = 3000
        )
      )
    )
  }
  
  if (verbose) {
    message("[my_llm_wrapper] Response received.")
  }
  
  return(response_text)
}

Copy Link

Version

Install

install.packages('LLMAgentR')

Monthly Downloads

601

Version

0.2.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Kwadwo Daddy Nyame Owusu Boakye

Last Published

April 29th, 2025

Functions in LLMAgentR (0.2.2)

build_code_agent

Build an R Code Generation Agent
build_data_wrangling_agent

Build a Data Wrangling Agent
build_feature_engineering_agent

Build a Feature Engineering Agent
build_researcher_agent

Build a Web Researcher Agent
build_doc_summarizer_agent

Build a Document Summarizer Agent
build_sql_agent

Build a SQL Agent Graph
build_visualization_agent

Build Visualization Agent
build_forecasting_agent

Build a Time Series Forecasting Agent
build_interpreter_agent

Build an Interpreter Agent
build_data_cleaning_agent

Build a Data Cleaning Agent
build_weather_agent

Build a Weather Agent