

PlantbreedAIAgent is an intelligent, autonomous data analysis engine designed specifically for plant breeders, quantitative geneticists, and agricultural biometricians.
It bridges the gap between natural language and complex statistical computing. Users can chat with the agent to design field trials, fit spatial mixed models, analyze Genotype-by-Environment (GxE) interactions, and calculate genomic relationships. Under the hood, the AI orchestrates a robust suite of native R and Python packages.
# 

plantbreeding (R) and plantbreeding_py (Python). Both can be used by the AI Agent or installed separately as standalone packages.
## π Directory Structure
The repository is strictly separated into the AI Orchestration layer and the Core Statistical Logic.
```text
PlantbreedAIAgent/
β
βββ frontend/ # Streamlit User Interface
β βββ app.py # Dual-pane Chat & Workspace UI
β
βββ api/ # FastAPI Backend Server
β βββ server.py # Exposes the /chat endpoint
β
βββ agent_core/ # The LangChain AI "Brain"
β βββ orchestrator.py # The PlantbreedAIAgent ReAct loop
β βββ prompts.py # System instructions & persona
β βββ state.py # Memory management
β
βββ tools/ # Tool wrappers exposing code to the LLM
β βββ tool_registry.py # Master list of available tools
β βββ python_wrappers.py # LangChain wrappers for Python logic
β βββ r_wrappers.py # rpy2 integration for R scripts
β
βββ core_logic/ # Standalone Statistical Packages
β βββ python_package/ # Native Python biometric tools
β β βββ setup.py # Pip installation file
β β βββ plantbreeding_py/ # The Python module & __init__.py
β β
β βββ r_package/ # Native R biometric tools
β βββ plantbreeding/
β βββ DESCRIPTION # R dependencies (lme4, metan, etc.)
β βββ NAMESPACE # Auto-exports functions
β βββ R/ # The raw .R scripts
β
βββ workspace/ # Shared Agent Scratchpad
βββ inputs/ # User uploads (CSVs, datasets)
βββ outputs/ # Agent-generated Plots, PDFs, and HTML widgets
To run the conversational agent with the UI, you need to start both the backend API and the frontend application.
lme4, emmeans, metan, agricolae, ggplot2, etc.)ollama run llama3).Clone the repository and install the required Python orchestration libraries (FastAPI, Streamlit, LangChain, and rpy2):
git clone [https://github.com/yourusername/PlantbreedAIAgent.git](https://github.com/yourusername/PlantbreedAIAgent.git)
cd PlantbreedAIAgent
pip install -r requirements.txt
The FastAPI server initializes the LangChain agent and binds the statistical tools.
uvicorn api.server:app --reload
*The API will be available at http://127.0.0.1:8000*
In a new terminal window, launch the Streamlit interface.
streamlit run frontend/app.py
Upload your datasets to workspace/inputs/ and ask the agent to analyze them!
If you are a developer or biometrician and just want to use the statistical functions in your own scripts without the AI agent, you can easily install the core packages separately.
plantbreeding)The R package utilizes a modern DESCRIPTION file managing all dependencies, and a NAMESPACE utilizing exportPattern("^[[:alpha:]]+") to automatically expose all main functions.
You can install it directly from GitHub using devtools:
# In your R console
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
devtools::install_github("yourusername/PlantbreedAIAgent",
subdir = "core_logic/r_package/plantbreeding")
# Load the package
library(plantbreeding)
# Example usage
my_design <- generate_lattice_plan(lines = c("L1", "L2", "L3"), checks = "C1",
n_locs = 2, n_reps = 2, k = 2)
plantbreeding_py)The Python package mirrors the R functionality using statsmodels, scikit-learn, and pandas. It is configured with a standard setup.py.
To install it locally from the cloned repository:
cd core_logic/python_package
pip install .
To install it directly from GitHub into any Python environment:
pip install git+[https://github.com/yourusername/PlantbreedAIAgent.git#subdirectory=core_logic/python_package](https://github.com/yourusername/PlantbreedAIAgent.git#subdirectory=core_logic/python_package)
# In your Python script
import pandas as pd
from plantbreeding_py import eberhart_russell_stability
df = pd.read_csv("yield_data.csv")
results = eberhart_russell_stability(df, trait="Yield", geno="Genotype", env="Location")
PlantbreedAIAgent is highly extensible. To teach the AI a new biometric skill:
.R or .py script to the respective folder inside core_logic/.tools/r_wrappers.py (or python_wrappers.py) and create a @tool decorated function. Ensure the """docstring""" clearly explains to the AI exactly when and how to use the tool.get_all_tools() list inside tools/tool_registry.py.This project is licensed under the MIT License - see the LICENSE file for details.