plantbreedAIagent

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.

# ![PlantbreedAIAgent UI](https://via.placeholder.com/800x400.png?text=Replace+with+your+Streamlit+Screenshot)

🌟 Key Features


## πŸ“‚ 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

πŸš€ Running the Full AI Agent

To run the conversational agent with the UI, you need to start both the backend API and the frontend application.

Prerequisites

1. Install Dependencies

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

2. Start the Engine (Backend)

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*

3. Start the Workspace (Frontend)

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!


πŸ“¦ Using the Packages Standalone

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.

Installing the R Package (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)

Installing the Python Package (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")


πŸ› οΈ Adding New Tools to the Agent

PlantbreedAIAgent is highly extensible. To teach the AI a new biometric skill:

  1. Write the Logic: Add your new .R or .py script to the respective folder inside core_logic/.
  2. Write the Wrapper: Go to 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.
  3. Register It: Add your wrapper to the get_all_tools() list inside tools/tool_registry.py.
  4. Restart the API: The agent will now automatically know how to use your new function.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.