MyNixOS website logo
Description

Reasoning and Acting Workflow for Automated Data Analysis.

Provides a framework for integrating Large Language Models (LLMs) with R programming through workflow automation. Built on the ReAct (Reasoning and Acting) architecture, enables bi-directional communication between LLMs and R environments. Features include automated code generation and execution, intelligent error handling with retry mechanisms, persistent session management, structured JSON output validation, and context-aware conversation management.

llmflow

R-CMD-check CRAN status r-universe

Overview

llmflow provides a framework for automated data analysis through the integration of Large Language Models (LLMs) with R. Built on the ReAct (Reasoning and Acting) architecture, the package enables iterative problem-solving by alternating between reasoning steps and code execution, allowing LLMs to autonomously analyze data, handle errors, and refine solutions.

Key Features

  • ReAct Architecture: Iterative reasoning and acting loops for complex analytical tasks
  • Automated Code Execution: LLM-generated R code runs in isolated sessions with error handling
  • Intelligent Error Recovery: Automatic retry mechanisms with progressive error escalation
  • Session Persistence: Maintain R session state across multiple LLM interactions
  • Structured Output: JSON schema validation for reliable, parseable responses
  • RAG Integration: Retrieval-augmented generation with R function documentation

Installation

From R-universe:

install.packages("llmflow", repos = c("https://zaoqu-liu.r-universe.dev", "https://cloud.r-project.org"))

From GitHub:

# install.packages("pak")
pak::pak("Zaoqu-Liu/llmflow")

Requirements

The package requires ellmer for LLM communication:

install.packages("ellmer")

Quick Start

library(llmflow)
library(ellmer)

# Initialize LLM client
llm <- chat_openai(model = "gpt-4o")

# Automated analysis with ReAct workflow
result <- AutoFlow(
 react_llm = llm,
 task_prompt = "Perform linear regression of mpg on hp and wt using mtcars"
)

Core Functions

FunctionDescription
AutoFlow()Complete workflow combining RAG and ReAct
react_r()ReAct loop for iterative problem solving
response_to_r()Execute LLM-generated R code
response_as_json()Structured JSON output with schema validation
retrieve_docs()Retrieve R function documentation for RAG

Usage Examples

ReAct Workflow

result <- react_r(
 chat_obj = llm,
 task = "Calculate correlation matrix for iris numeric columns",
 max_turns = 10,
 verbose = TRUE
)

# Access results
result$final_answer
result$code_summary$complete_script

JSON Response with Schema Validation

schema <- list(
 type = "object",
 properties = list(
   analysis_type = list(type = "string"),
   findings = list(type = "array", items = list(type = "string"))
 ),
 required = c("analysis_type", "findings")
)

response <- response_as_json(
 chat_obj = llm,
 prompt = "Summarize the iris dataset",
 schema = schema,
 schema_strict = TRUE
)

Code Generation and Execution

result <- response_to_r(
 chat_obj = llm,
 prompt = "Create a scatter plot of mpg vs hp from mtcars",
 pkgs_to_use = c("ggplot2"),
 return_mode = "full"
)

License

GPL (>= 3)

Citation

Liu Z (2026). llmflow: Reasoning and Acting Workflow for Automated Data Analysis.
R package version 3.0.1, https://github.com/Zaoqu-Liu/llmflow

Author

Zaoqu Liu

Metadata

Version

3.0.2

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows