Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pranavkrishnasuresh/chemAgent/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The process_input() function is the main entry point for running the ChemAgent. It processes chemistry-related queries, optionally extracts text from images, performs RAG-based information retrieval, and returns comprehensive results including the agent’s response, completion status, and error information.

Function Signature

async def process_input(
    input_prompt: str,
    image_path: str = None,
    use_rag: bool = False
) -> tuple

Parameters

input_prompt
str
required
The input query or prompt to process. This should be a chemistry-related question or task, such as:
  • IUPAC to SMILES conversion
  • Molecular formula calculation
  • Property prediction queries
  • Chemical reaction synthesis
Example: "Could you provide the SMILES for 4-ethyl-4-methyloxolan-2-one?"
image_path
str
default:"None"
Optional path to an image file containing chemistry text. When provided, GPT-4o will extract relevant chemistry-related text from the image to augment the query.The image should contain:
  • Chemical structures
  • Chemical formulas
  • IUPAC names
  • Other chemistry-related text
Example: "/path/to/chemistry_diagram.png"
use_rag
bool
default:"False"
Enable RAG (Retrieval-Augmented Generation) to fetch additional information from PubChem database. When enabled, the agent retrieves relevant chemical information to enhance the response accuracy.

Return Value

Returns a tuple containing six elements:
tuple[0]
str
Final Response: The last response from the agent containing the answer to the query. Returns None if the process failed due to recursion limits.
tuple[1]
bool
Completion Status: True if the process completed successfully, False if it failed due to GraphRecursionError or other issues.
tuple[2]
int
Replanning Attempts: The number of times the agent replanned during execution. Higher values indicate more complex queries. Returns 0 if the process failed.
tuple[3]
str | None
LlaSMol Response: The raw response from the LlaSMol model. Contains detailed model output for chemistry-specific tasks. Returns None if the model was not used or execution failed.
tuple[4]
str
LlaSMol Errors: Error messages from chemistry parsing and SMILES validation. Multiple errors are separated by $ characters. Returns empty string if no errors occurred.
tuple[5]
str
Formatted Input: The input query after being structured and tagged by the planner. Shows how the agent interpreted and reformatted the original prompt with <SMILES> and <IUPAC> tags.

Usage Examples

Basic Usage

import asyncio
from plan_execute_agent.rdkit_agent import process_input

async def main():
    # Simple IUPAC to SMILES conversion
    result = await process_input(
        "Provide the SMILES for 4-ethyl-4-methyloxolan-2-one"
    )
    
    response, completed, attempts, llasmol_response, errors, formatted_input = result
    
    print(f"Response: {response}")
    print(f"Completed: {completed}")
    print(f"Attempts: {attempts}")

asyncio.run(main())

With Image Extraction

import asyncio
from plan_execute_agent.rdkit_agent import process_input

async def main():
    # Extract chemistry text from an image and process
    result = await process_input(
        "What is the molecular formula of the compound in this image?",
        image_path="/path/to/molecule.png"
    )
    
    response, completed, attempts, _, errors, _ = result
    
    if completed:
        print(f"Answer: {response}")
    else:
        print("Failed to process image")

asyncio.run(main())

With RAG Enhancement

import asyncio
from plan_execute_agent.rdkit_agent import process_input

async def main():
    # Use PubChem RAG for enhanced information
    result = await process_input(
        "How soluble is aspirin?",
        use_rag=True
    )
    
    response, completed, attempts, llasmol_response, errors, formatted_input = result
    
    print(f"Formatted Query: {formatted_input}")
    print(f"Response: {response}")
    print(f"Validation Errors: {errors}")

asyncio.run(main())

Handling Errors

import asyncio
from plan_execute_agent.rdkit_agent import process_input

async def main():
    result = await process_input("Generate SMILES for caffeine")
    
    response, completed, attempts, llasmol_response, errors, formatted_input = result
    
    if not completed:
        print("Agent failed to complete the task")
        print(f"Attempts made: {attempts}")
    elif errors:
        print("Task completed with validation errors:")
        error_list = errors.split('$')
        for error in error_list:
            if error.strip():
                print(f"  - {error}")
    else:
        print(f"Success: {response}")

asyncio.run(main())

Supported Query Types

Error Handling

The function handles several error scenarios:

Configuration

The function uses these configuration settings:
  • Recursion Limit: Maximum 50 planning/execution cycles
  • LLM Model: GPT-4o for planning and replanning
  • Chemistry Model: LlaSMol-Mistral-7B for specialized chemistry tasks
  • RAG Source: PubChem database for chemical information retrieval

Notes

This is an async function and must be called with await or asyncio.run().
The agent automatically structures your input by adding <SMILES> and <IUPAC> tags. You can see the formatted version in the returned tuple.
Enable use_rag=True for queries about specific compounds to get enhanced information from PubChem.

Build docs developers (and LLMs) love