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.
- Task Classifier: An LLM routes each request into
simple,complex, ormeta_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.
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 |
- Docker Desktop
- OpenAI API key from platform.openai.com
- A Supabase project: used as the PostgreSQL backend for LangGraph checkpointing and user authentication (copy its connection string). (Optional) We also have a self-hosted template for Supabase if you need one.
- The prebuilt persistence/ folder: it will be downloaded separately (see step 2 below)
- (Optional) LangSmith account for tracing from smith.langchain.com
# 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:trialOpen http://localhost:7860 to access the Gradio application.
# 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- Create an account at smith.langchain.com
- Get your API key from the settings page
- Add the
LANGSMITH_*variables to your.envfile as shown above - Rebuild/restart the container to apply the changes
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)
