IntegrationsAI Agents

Build an Autonomous Drug Discovery Agent with LangChain + SciRouter

Build an AI drug discovery agent with LangChain and SciRouter MCP. Autonomous target analysis, compound screening, and ADMET scoring in 100 lines of Python.

Ryan Bethencourt
April 8, 2026
10 min read

The Vision: AI That Does Drug Discovery While You Sleep

Drug discovery today is a fundamentally manual process. A medicinal chemist proposes a target, an computational chemist runs docking simulations, a DMPK scientist evaluates ADMET properties, and a project team meets weekly to decide which compounds to advance. Each step involves different tools, different file formats, and different people. The cycle time from "interesting target" to "ranked compound list" is measured in weeks or months.

What if an AI agent could do all of this autonomously? Given a target protein and a therapeutic hypothesis, the agent would fold the protein, detect binding pockets, generate candidate molecules, dock them, predict ADMET properties, rank the results, and produce a prioritized hit list – all without human intervention. Not replacing the scientists, but compressing the computational triage that currently takes weeks into a single overnight run.

This is not science fiction. The tools exist today. LLMs like GPT-4 and Claude can reason about molecular structures and biological targets. SciRouter provides 40+ science computation tools as API endpoints. LangChain provides the agent framework that connects reasoning to action. In this guide, we will build a complete autonomous drug discovery agent from scratch, run it against a real target (KRAS G12C), and analyze the results.

Architecture: LangChain + SciRouter MCP

The agent architecture has three layers:

  • Reasoning Engine (LLM) – GPT-4o or Claude Sonnet, responsible for planning the discovery workflow, interpreting results, and making decisions about which compounds to advance
  • Tool Layer (SciRouter MCP) – 40+ science tools exposed via the Model Context Protocol, including protein folding, pocket detection, molecular docking, ADMET prediction, molecule generation, and similarity search
  • Orchestration (LangChain) – The framework that connects the LLM to the tools, manages conversation history, handles tool calling, and maintains the agent loop
Note
MCP (Model Context Protocol) is the key integration layer. SciRouter's MCP server at mcp.scirouter.dev/sse exposes all science tools in a format that any MCP-compatible agent can discover and call. The agent does not need to know the API details in advance – it discovers available tools at runtime.

How the Agent Loop Works

The LangChain agent follows a ReAct (Reason + Act) loop:

  • Observe: The agent reads the current state (target information, previous results, constraints)
  • Think: The LLM reasons about what to do next ("I have the protein structure. I should detect binding pockets before docking.")
  • Act: The agent calls a SciRouter tool (e.g., pocket detection)
  • Observe: The agent reads the tool output (pocket locations, druggability scores)
  • Repeat until the task is complete or a stopping criterion is met

Each iteration of the loop is a decision point where the LLM evaluates the results so far and decides the next action. This is fundamentally different from a hardcoded pipeline: the agent can adapt its strategy based on intermediate results. If the first pocket scores low for druggability, it might check alternative pockets. If generated molecules fail ADMET screening, it might adjust the generation parameters.

Setup: Dependencies and API Keys

You need three things to build the agent: Python packages, a SciRouter API key, and an LLM API key. Here is the complete setup:

bash
# Install required packages
pip install langchain langchain-openai scirouter httpx

# Set environment variables
export SCIROUTER_API_KEY="sk-sci-YOUR_KEY"
export OPENAI_API_KEY="sk-YOUR_OPENAI_KEY"  # Or use Anthropic

Create a free SciRouter account at scirouter.ai/signup to get your API key. The free tier (5,000 calls/month) is sufficient for running the agent dozens of times during development. For production use, the Pro tier ($29/month) provides 100,000 calls.

Registering SciRouter Tools with LangChain

The first step is to expose SciRouter's science tools as LangChain tools that the agent can call. We will create wrapper functions for the key endpoints:

python
import os
import scirouter
from langchain.tools import tool
from langchain_openai import ChatOpenAI

client = scirouter.SciRouter(api_key=os.environ["SCIROUTER_API_KEY"])

@tool
def fold_protein(sequence: str) -> str:
    """Predict the 3D structure of a protein from its amino acid sequence.
    Returns PDB format structure and per-residue confidence scores (pLDDT).
    Use this when you need a protein structure for docking or analysis."""
    result = client.proteins.fold(sequence=sequence)
    avg_plddt = sum(result.plddt_scores) / len(result.plddt_scores)
    return (
        f"Structure predicted successfully. "
        f"Average pLDDT: {avg_plddt:.1f}/100. "
        f"Residues: {len(result.plddt_scores)}. "
        f"High-confidence regions (pLDDT>85): "
        f"{sum(1 for s in result.plddt_scores if s > 85)}/{len(result.plddt_scores)}"
    )

@tool
def detect_pockets(pdb_id: str) -> str:
    """Detect druggable binding pockets on a protein structure.
    Input is a PDB ID (e.g., '6OIM'). Returns ranked pockets with
    druggability scores, volumes, and residue lists."""
    result = client.proteins.detect_pockets(pdb_id=pdb_id)
    lines = []
    for i, pocket in enumerate(result.pockets[:5]):
        lines.append(
            f"Pocket {i+1}: druggability={pocket.druggability_score:.2f}, "
            f"volume={pocket.volume:.0f} A^3, "
            f"residues={len(pocket.residues)}"
        )
    return "\n".join(lines)

@tool
def dock_molecule(protein_pdb_id: str, ligand_smiles: str) -> str:
    """Dock a small molecule into a protein using DiffDock.
    Returns binding confidence score and predicted pose.
    Higher confidence means more likely to bind."""
    result = client.docking.diffdock(
        protein_pdb_id=protein_pdb_id,
        ligand_smiles=ligand_smiles,
    )
    return (
        f"Docking complete. Confidence: {result.confidence:.2f}. "
        f"Top pose RMSD: {result.top_pose_rmsd:.2f} A."
    )

@tool
def predict_admet(smiles: str) -> str:
    """Predict ADMET properties for a molecule given its SMILES string.
    Returns drug-likeness, toxicity flags, and pharmacokinetic predictions."""
    result = client.chemistry.admet(smiles=smiles)
    flags = []
    if result.herg_inhibitor:
        flags.append("hERG_RISK")
    if result.ames_mutagenic:
        flags.append("MUTAGENIC")
    if result.hepatotoxicity:
        flags.append("HEPATOTOXIC")
    flag_str = ", ".join(flags) if flags else "CLEAN"
    return (
        f"LogP: {result.logp:.2f}, Lipinski violations: {result.lipinski_violations}, "
        f"Caco-2: {result.caco2_class}, BBB: {result.bbb_penetration}, "
        f"CYP3A4 inhibitor: {result.cyp3a4_inhibitor}, "
        f"Safety flags: {flag_str}"
    )

@tool
def calculate_properties(smiles: str) -> str:
    """Calculate molecular properties from a SMILES string.
    Returns molecular weight, LogP, H-bond donors/acceptors, etc."""
    result = client.chemistry.properties(smiles=smiles)
    return (
        f"MW: {result.molecular_weight:.1f} Da, LogP: {result.logp:.2f}, "
        f"HBD: {result.h_bond_donors}, HBA: {result.h_bond_acceptors}, "
        f"RotBonds: {result.rotatable_bonds}, TPSA: {result.tpsa:.1f} A^2, "
        f"Lipinski violations: {result.lipinski_violations}"
    )

@tool
def generate_molecules(target_description: str, num_molecules: int = 5) -> str:
    """Generate novel drug-like molecules targeting a specific protein or pathway.
    Returns SMILES strings for generated candidates."""
    result = client.generate.molecules(
        target=target_description,
        num_molecules=num_molecules,
    )
    lines = [f"Generated {len(result.molecules)} molecules:"]
    for i, mol in enumerate(result.molecules):
        lines.append(f"  {i+1}. {mol.smiles} (SA score: {mol.sa_score:.2f})")
    return "\n".join(lines)

@tool
def compare_molecules(smiles_a: str, smiles_b: str) -> str:
    """Calculate Tanimoto similarity between two molecules.
    Returns similarity score from 0 (dissimilar) to 1 (identical)."""
    result = client.chemistry.similarity(smiles_a=smiles_a, smiles_b=smiles_b)
    return f"Tanimoto similarity: {result.tanimoto:.3f}"

# Collect all tools
tools = [
    fold_protein,
    detect_pockets,
    dock_molecule,
    predict_admet,
    calculate_properties,
    generate_molecules,
    compare_molecules,
]

Each tool has a detailed docstring that the LLM reads to understand when and how to use it. The docstrings are critical – they are the agent's instruction manual for the science tools. Clear, specific docstrings lead to better tool selection and fewer errors.

The Agent: Target to Lead in 100 Lines

Now we assemble the full agent. The system prompt gives the agent its drug discovery expertise, the tools give it capabilities, and the LangChain agent executor manages the ReAct loop.

python
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder

# Define the system prompt with drug discovery expertise
system_prompt = """You are an expert computational drug discovery scientist.
Your goal is to evaluate drug targets and identify promising lead compounds.

For each target, follow this systematic workflow:
1. UNDERSTAND the target: What protein is it? What disease does it drive?
2. STRUCTURE: Get or predict the protein structure. Check pLDDT for quality.
3. POCKETS: Detect druggable binding pockets. Evaluate druggability scores.
4. GENERATE: Generate candidate molecules targeting the identified pocket.
5. DOCK: Dock the top candidates into the target pocket.
6. ADMET: Screen candidates for drug-likeness and toxicity.
7. RANK: Produce a final ranked list with justification for each compound.

Always explain your reasoning. If a step fails or produces poor results,
adapt your strategy. Prioritize compounds that are:
- Drug-like (few Lipinski violations)
- Non-toxic (no hERG, AMES, or hepatotoxicity flags)
- Synthetically accessible (SA score < 4)
- Predicted to bind the target (docking confidence > 0.5)

Be thorough but efficient. Do not repeat analyses unnecessarily."""

prompt = ChatPromptTemplate.from_messages([
    ("system", system_prompt),
    ("human", "{input}"),
    MessagesPlaceholder(variable_name="agent_scratchpad"),
])

# Initialize the LLM
llm = ChatOpenAI(model="gpt-4o", temperature=0)

# Create the agent
agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    verbose=True,      # Print the agent's reasoning
    max_iterations=20, # Safety limit
    handle_parsing_errors=True,
)

# Run the agent on a real target
result = agent_executor.invoke({
    "input": (
        "Evaluate KRAS G12C (PDB: 6OIM) as a drug target. "
        "Detect binding pockets, generate 5 candidate molecules, "
        "dock them, screen for ADMET, and produce a ranked lead list. "
        "The reference inhibitor is sotorasib "
        "(SMILES: C=CC(=O)N1CCN(c2nc(Nc3ccc(N4CCN(C)CC4)c(C)c3)c3[nH]cnc3n2)CC1)."
    )
})

print("\n" + "=" * 60)
print("FINAL AGENT OUTPUT:")
print("=" * 60)
print(result["output"])

What the Agent Does: Step by Step

When you run this agent against KRAS G12C, here is what happens in the ReAct loop:

Step 1: Target Analysis

The agent first uses its built-in knowledge (from the LLM) to explain that KRAS G12C is the most frequently mutated oncogene in non-small cell lung cancer, colorectal cancer, and pancreatic cancer. It notes that the G12C mutation (glycine to cysteine at position 12) creates a unique covalent drug target and that sotorasib (Lumakras) was the first FDA-approved KRAS G12C inhibitor.

Step 2: Pocket Detection

The agent calls detect_pockets("6OIM") and receives the ranked pocket list. It identifies the Switch-II allosteric pocket (typically ranked second) as the relevant site based on its drug discovery knowledge. It notes the druggability score and volume and decides this pocket is suitable for small-molecule targeting.

Step 3: Molecule Generation

The agent calls generate_molecules requesting 5 candidates targeting the KRAS G12C Switch-II pocket. It receives SMILES strings for novel molecules with synthetic accessibility scores. Molecules with SA scores above 5 (hard to synthesize) are noted for potential redesign.

Step 4: Docking

The agent docks each generated molecule into the KRAS G12C structure usingdock_molecule. It also docks the reference compound (sotorasib) to establish a benchmark confidence score. Candidates that dock with confidence comparable to or better than sotorasib are flagged as promising.

Step 5: ADMET Screening

Each candidate is screened through predict_admet. The agent looks for red flags: hERG inhibition, AMES mutagenicity, hepatotoxicity, and excessive Lipinski violations. Compounds with clean ADMET profiles are prioritized.

Step 6: Ranking and Report

The agent produces a final ranked list, typically in a format like this:

text
=== KRAS G12C Lead Compound Report ===

Rank 1: COMPOUND-3
  SMILES: C=CC(=O)N1CCN(c2nc(Nc3ccc(F)cc3)c3c[nH]nc3n2)CC1
  Docking confidence: 0.74 (reference sotorasib: 0.78)
  ADMET: CLEAN (no flags)
  MW: 382.4 Da, LogP: 2.1, Lipinski violations: 0
  SA score: 2.8 (readily synthesizable)
  Rationale: Retains acrylamide warhead and piperazine-pyrimidine core
  from sotorasib with simplified aniline substituent. Clean ADMET profile
  and good synthetic accessibility make this an attractive starting point.

Rank 2: COMPOUND-1
  SMILES: C=CC(=O)N1CCN(c2nc(Nc3ccncc3)c3[nH]cnc3n2)CC1
  Docking confidence: 0.68
  ADMET: CYP3A4 inhibitor (manageable)
  MW: 365.2 Da, LogP: 1.8, Lipinski violations: 0
  SA score: 3.1
  Rationale: Pyridine replacement for aniline reduces lipophilicity.
  CYP3A4 flag is a monitoring issue, not a hard stop.

[... continues for all candidates ...]

The agent's reasoning is transparent at every step. You can see why it chose each tool, how it interpreted the results, and what tradeoffs it considered in the final ranking. This is not a black box – it is an explainable, auditable computational triage.

Using SciRouter MCP Directly with Claude

If you prefer to use Claude Desktop or another MCP-compatible agent instead of building a custom LangChain agent, SciRouter's MCP server provides the same tools without any code:

json
// claude_desktop_config.json
{
  "mcpServers": {
    "scirouter": {
      "url": "https://mcp.scirouter.dev/sse",
      "headers": {
        "Authorization": "Bearer sk-sci-YOUR_KEY"
      }
    }
  }
}

With this configuration, Claude Desktop automatically discovers all 40+ SciRouter science tools. You can then ask Claude to run the same drug discovery workflow conversationally: "Evaluate KRAS G12C as a drug target, find binding pockets, generate candidates, dock them, and rank by ADMET profile." Claude will call the same tools in the same order, with the same scientific reasoning.

Note
The MCP approach is ideal for interactive exploration, while the LangChain approach is better for automated, reproducible pipelines. Both use the same SciRouter tools and produce the same results – the difference is whether a human or a script initiates the workflow.

Advanced: Multi-Agent Drug Discovery Pipelines

A single agent can handle the target-to-lead workflow for one target. For more complex scenarios – screening multiple targets, running parallel SAR campaigns, or coordinating hit-to-lead optimization – you can build multi-agent systems where specialized agents handle different stages.

Target Evaluation Agent

Specialized in assessing target tractability: folds the protein, detects pockets, evaluates druggability, and produces a go/no-go recommendation with confidence level. Passes druggable targets to the screening agent.

Compound Screening Agent

Focused on molecular evaluation: generates candidates, docks them, screens ADMET, and ranks results. Takes a validated target from the evaluation agent and produces a prioritized hit list.

Lead Optimization Agent

Iteratively improves the top hits: analyzes SAR from the initial screen, suggests modifications to improve potency or ADMET, generates analogs, and re-evaluates. This agent runs multiple optimization cycles until convergence.

python
# Multi-agent pipeline sketch
from langchain.agents import AgentExecutor

# Agent 1: Target evaluation
target_agent = build_agent(
    tools=[fold_protein, detect_pockets],
    system_prompt="You evaluate protein targets for druggability..."
)

# Agent 2: Compound screening
screening_agent = build_agent(
    tools=[generate_molecules, dock_molecule, predict_admet, calculate_properties],
    system_prompt="You screen compounds against validated targets..."
)

# Agent 3: Lead optimization
optimization_agent = build_agent(
    tools=[generate_molecules, dock_molecule, predict_admet, compare_molecules],
    system_prompt="You optimize lead compounds through iterative SAR..."
)

# Pipeline: target -> screen -> optimize
target_result = target_agent.invoke({
    "input": "Evaluate KRAS G12C (PDB: 6OIM) for druggability"
})

if "druggable" in target_result["output"].lower():
    screen_result = screening_agent.invoke({
        "input": f"Screen compounds for KRAS G12C. {target_result['output']}"
    })

    optimization_result = optimization_agent.invoke({
        "input": f"Optimize the top hits. {screen_result['output']}"
    })

    print("Final optimized leads:")
    print(optimization_result["output"])

Limitations and Responsible Use

Autonomous drug discovery agents are powerful tools, but they have important limitations that must be understood:

  • Computational predictions are not experimental validation. Docking scores, ADMET predictions, and generated molecules are hypotheses. They must be tested experimentally before any clinical decisions are made.
  • LLMs can hallucinate. The agent's reasoning about biology and chemistry is based on LLM training data, which may contain errors. Always verify the agent's biological claims against primary literature.
  • Garbage in, garbage out. If the protein structure is wrong (low pLDDT) or the SMILES is invalid, downstream results will be meaningless. The agent should always check input quality, and we have designed the tools to return quality metrics.
  • No novelty guarantee. Generated molecules may resemble existing patented compounds. Always run similarity checks against patent databases before advancing candidates.
  • Agent errors compound. In a multi-step pipeline, errors in early steps propagate and amplify. A wrong pocket selection leads to irrelevant docking, which leads to wrong rankings. Build in validation checkpoints.

The agent is a tireless computational assistant that can run analyses 24/7, explore chemical space systematically, and never forget to check ADMET. It is not a replacement for scientific expertise – it is a force multiplier that lets scientists focus on the creative, hypothesis-generating work while the agent handles the computational heavy lifting.

What Comes Next: The Future of AI Drug Discovery Agents

The agent we built in this guide operates on a single target with a fixed workflow. The next generation of drug discovery agents will be more capable:

  • Multi-target campaigns – Agents that simultaneously evaluate dozens of targets and allocate resources to the most promising ones
  • Active learning loops – Agents that design experiments, send compounds for synthesis, receive experimental results, and update their models
  • Literature-integrated reasoning – Agents that search PubMed, read papers, and incorporate published SAR data into their decision-making
  • Collaborative multi-agent systems – Specialized agents for biology, chemistry, DMPK, and toxicology that debate and collaborate like a real drug discovery team

SciRouter is building toward this future by expanding the tool library (currently 40+ tools across 12 scientific domains) and improving the MCP integration that makes these tools accessible to any AI agent framework.

Get Started: Build Your First Agent Today

Everything you need is available right now:

  • Create a free SciRouter account at scirouter.ai/signup (5,000 API calls/month, no credit card)
  • Install the SDK: pip install scirouter langchain langchain-openai
  • Copy the code from this guide and replace the API keys
  • Run the agent against your target of interest

For MCP-based integration with Claude Desktop, configure the SciRouter MCP server using the JSON snippet above. The agent will discover all 40+ science tools automatically.

The tools for autonomous drug discovery are here. The question is no longer "can AI help with drug discovery?" but "how do you want to deploy it?" Whether you build a custom LangChain agent, use Claude Desktop with MCP tools, or integrate SciRouter into your existing pipeline, the computational infrastructure for AI-driven drug discovery is ready. The compounds are not going to discover themselves – but your agent might.

Frequently Asked Questions

What is an autonomous drug discovery agent?

An autonomous drug discovery agent is an AI system that can independently execute multi-step drug discovery workflows: identifying targets, screening compounds, predicting properties, and ranking candidates without human intervention at each step. Unlike a chatbot that answers questions, an agent takes actions — it calls APIs, interprets results, makes decisions, and iterates. The agent uses an LLM (like GPT-4 or Claude) as its reasoning engine and science tools (like SciRouter) as its hands.

Do I need a GPU to run a drug discovery agent?

No. The agent itself runs on CPU — it is a Python script that orchestrates API calls. All the heavy computation (protein folding, molecular docking, ADMET prediction, molecule generation) happens on remote GPU servers through the SciRouter API. Your local machine only needs to run Python, LangChain, and make HTTP requests. A laptop with 8 GB RAM is sufficient.

How much does it cost to run an autonomous drug discovery pipeline?

The SciRouter free tier provides 5,000 API calls per month, which is enough for approximately 50-100 complete agent runs (each run typically makes 30-80 API calls across folding, docking, properties, and ADMET). The LLM cost depends on your provider: GPT-4o costs roughly $0.01-0.05 per agent run, Claude Sonnet is similar. For production-scale screening, the SciRouter Pro tier ($29/month, 100,000 calls) supports thousands of agent runs.

Can the agent discover a real drug?

The agent can identify promising computational hits — compounds that score well on predicted binding affinity, drug-likeness, and ADMET properties. However, computational predictions are not a substitute for experimental validation. Real drug discovery requires synthesis of the top candidates, in vitro binding assays, cell-based activity assays, and ultimately animal studies and clinical trials. The agent dramatically accelerates the computational triage stage, reducing months of manual work to hours.

What LLM works best for drug discovery agents?

GPT-4o and Claude Sonnet 4 are currently the best choices for drug discovery agents. They have strong scientific reasoning, reliable function calling, and good context window management. GPT-4o-mini and Claude Haiku work for simpler tasks (property lookup, format conversion) but struggle with multi-step reasoning about SAR and ADMET tradeoffs. Open-source models like Llama 3.1 70B can work but require more prompt engineering and have less reliable tool calling.

What is MCP and how does it relate to LangChain?

MCP (Model Context Protocol) is a standard for connecting AI models to external tools. SciRouter exposes its 40+ science tools as MCP tools that any MCP-compatible agent can discover and call. LangChain is a Python framework for building AI agents that supports MCP tool integration. When you connect LangChain to SciRouter's MCP server, the agent automatically discovers all available science tools (protein folding, docking, ADMET, etc.) and can call them as needed during its reasoning process.

Try this yourself

500 free credits. No credit card required.