Skip to content

About

AI Agent for Chemical Safety

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

193 Commits

Folders and files

Repository files navigation

ChemSafeAgent - An AI Agent for Chemical Safety

Overview

Chemical safety assessment requires reasoning over heterogeneous data (molecular structures, regulatory Standard Operating Procedures (SOPs), toxicological endpoints, and scientific literature) while keeping every safety-relevant decision traceable to an authoritative source. ChemSafeAgent is a multi-agent system that autonomously plans, executes, and summarizes chemical safety workflows under human-in-the-loop supervision. It combines a LangGraph orchestration graph, a restricted Python execution environment, retrieval-augmented access to professional SOPs, and a library of domain skills (cheminformatics, database traversal, weight-of-evidence reasoning) so that any chemical, threshold, or exposure decision is grounded in a verifiable source or explicitly flagged as unverified.

Core Agent Architecture

  • Task Classifier: An LLM routes each request into simple, complex, or meta_query, choosing the appropriate execution path.
  • Planning Agent: Decomposes complex tasks into a step-by-step plan, drawing on the relevant SOPs and skills before any execution begins.
  • Human Approval (Human-in-the-Loop): Plans are never auto-approved — the graph pauses for plan review and only proceeds once the user's free-text feedback is judged as an approval.
  • Execute Agent (CodeAct): A ReAct agent that carries out the work by writing and running code, reading files, and loading domain skills on demand.
  • Summary Agent: Synthesizes results into a grounded, source-attributed report.
  • Critics Agent (under development): Will review the Execute Agent's intermediate work and provide corrective feedback in a critique loop before results are summarized.

Tool Surface & Skills

  • python_executor: Code runs through a custom restricted interpreter, with only an allow-listed set of imports (RDKit, pandas, admet-ai, DeepChem, requests, and the repo's own modules).
  • read_files: Reads repo files, skill playbooks, and scoped artifacts, all behind a strict path sandbox.

Domain Skills are markdown playbooks (plus additional scripts/references) the agent loads on demand. They draw on the following resources:

Category Resources
Databases ECHA, PubChem, NIOSH, OPCW
Guidelines ECHA, NIH, UN,
Predictive models Models from MISTRA's tool box and ADMET-AI
Cheminformatics tools RDKit

Quick Start

Prerequisites

Initial Setup

# 1. Clone repository
git clone https://github.com/your-username/chemsafe-agent.git
cd chemsafe-agent

# 2. Download the prebuilt persistence/ folder and place it under chemsafe-agent/
#    Download persistence.zip (~6 GB, including guidelines vector store and pre-trained ML models) from Google Drive:
#      https://drive.google.com/file/d/1Z9l_eHd6tAPct4ZiLIgsIjcN9-ykmJP5/view?usp=sharing
#    Then unzip it and put it under chemsafe-agent/, for example:
unzip ~/Downloads/persistence.zip -d ./

# 3. Create a .env file with the required credentials
## Mandatory: OpenAI API key
echo "OPENAI_API_KEY=your-openai-api-key-here" > .env

## Mandatory: Supabase PostgreSQL connection string
echo "DATABASE_URL=postgresql://postgres:[your-password]@[your-project].supabase.co:5432/postgres" >> .env

## Optional: LangSmith tracing
echo "LANGSMITH_TRACING=true" >> .env
echo "LANGSMITH_ENDPOINT=https://api.smith.langchain.com" >> .env
echo "LANGSMITH_API_KEY=your-langsmith-api-key-here" >> .env
echo "LANGSMITH_PROJECT=chemsafe-agent" >> .env

# 4. Build the Docker image
docker build --platform linux/amd64 -t chemsafeagent:trial .

# 5. Run the container (passing your .env)
docker run --rm -it --env-file .env -p 7860:7860 chemsafeagent:trial

Open http://localhost:7860 to access the Gradio application.

Daily Usage

# Start the application (after initial setup)
docker run --rm -it --env-file .env -p 7860:7860 chemsafeagent:trial

# Stop the application
# Press Ctrl+C in the terminal running the container

LangSmith Setup (Optional)

  1. Create an account at smith.langchain.com
  2. Get your API key from the settings page
  3. Add the LANGSMITH_* variables to your .env file as shown above
  4. Rebuild/restart the container to apply the changes

Project Structure

chemsafe-agent/
├── app/            # Gradio UI, streaming, auth, and file-download routes
├── core/           # Agent graph, prompts, tools, and domain skills
├── backend/        # Persistence, path sandbox, auth, and SOP RAG
├── persistence/    # Scoped data, results, and memory roots
├── images/         # Diagrams and logos
├── Dockerfile      # Self-contained build (pre-caches the RAG embedding model)
├── requirements.txt
└── main.py         # Entry point (launches the Gradio app)

About

AI Agent for Chemical Safety

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages