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)
}