The ChemAgent is built on LangGraph, a framework for creating stateful, multi-step AI workflows. This page documents the configuration options and customization points for the agent’s plan-and-execute architecture.
Maximum number of planning and execution cycles the agent can perform. This prevents infinite loops while allowing complex multi-step reasoning.Recommended Values:
Simple queries (name conversions): 10-20
Complex queries (property predictions): 30-50
Advanced tasks (synthesis planning): 50-100
Setting this too low may cause the agent to fail on complex tasks. Setting it too high may result in long execution times.
System prompt that guides the initial planning phase:
planner_prompt = ChatPromptTemplate.from_messages([ ("system", """For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps."""), ("placeholder", "{messages}"),])
Customization:
Modify the system message to change planning behavior
Add examples for domain-specific planning patterns
Adjust temperature (default: 0) for more creative plans
Structures and tags chemical information in the input query with <SMILES> and <IUPAC> tags.Usage: Must be called first in every plan to format the query properly.
Show validate_smiles_rdkit
Validates SMILES strings using RDKit and the chemistry parser.Returns: Validity status and detailed error messages (validity vectors).
Show answer_chemistry_query
Uses the LlaSMol model to answer chemistry-specific queries.Requires: VRAM ≥15GB (disabled when LOW_VRAM = True).
replanner_prompt = ChatPromptTemplate.from_template( """For the given objective, come up with a simple step by step plan. This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps. Your objective was this: {input} Your original plan was this: {plan} You have currently done the follow steps: {past_steps} Update your plan accordingly. If no more steps are needed OR VRAM is LOW and you can return to the user, then respond with that. Otherwise, fill out the plan. Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.""")
Key Features:
Receives full context: original objective, plan, and completed steps
Can decide to respond directly or continue planning
from langchain_openai import ChatOpenAIfrom langgraph.prebuilt import create_react_agent# Custom prompt for specialized chemistry domaincustom_prompt = """You are an expert medicinal chemist specializing in drug design.Focus on drug-like properties and ADMET predictions."""llm = ChatOpenAI(model="gpt-4o")agent_executor = create_react_agent(llm, tools, state_modifier=custom_prompt)
Decides whether to continue with updated plan or return final response.
Show should_end()
def should_end(state: PlanExecute): global replanning_attempts if "response" in state and state["response"]: return END else: replanning_attempts += 1 return "agent"
Determines if the workflow should end or continue to the next step.