Agent Laboratory

repository·main·Indexed 26 days ago

https://github.com/samuelschmidgall/agentlaboratory

An end-to-end autonomous research workflow that utilizes LLM-driven specialized agents to assist human researchers. It automates literature review, experimentation, and report writing by integrating tools such as arXiv, Hugging Face, Python, and LaTeX. The system supports various LLM backends including OpenAI (o1, gpt-4o, o3-mini) and DeepSeek, and features a Flask-based API for semantic search across indexed research papers.

Tokens
13.1K
Snippets
31
Records
41
Agent score
81%

What's inside Agent Laboratory

  1. Customize agent instructions via task_notes_LLM

    main

    To improve research outcomes, you can provide specific instructions to agents by modifying the task_notes_LLM structure within ai_lab_repo.py. This allows you to define requirements for specific research phases, such as 'plan formulation', 'data preparation', or 'running experiments'.

    You can use these notes to:

    • Specify the number of experiments.
    • Define preferred LLM models for sub-tasks (e.g., using gpt-4o-mini for experiments).
    • Provide specific code snippets for inference.
    • Inform agents about available hardware resources (e.g., GPU types, CPU cores, or using mps on MacBook).
    • Set constraints on dataset sizes or design preferences for figures.
    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["plan formulation", "data preparation",  "running experiments"],
         "note": "Please use gpt-4o-mini for your experiments."},
    
        {"phases": ["running experiments"],
         "note": f"Use the following code to inference gpt-4o-mini: \nfrom openai import OpenAI\nos.environ[\"OPENAI_API_KEY\"] = \"{api_key}\"\nclient = OpenAI()\ncompletion = client.chat.completions.create(\nmodel=\"gpt-4o-mini-2024-07-18\", messages=messages)\nanswer = completion.choices[0].message.content\n"},
    
        {"phases": ["running experiments"],
         "note": f"You have access to only gpt-4o-mini using the OpenAI API, please use the following key {api_key} but do not use too many inferences. Do not use openai.ChatCompletion.create or any openai==0.28 commands. Instead use the provided inference code."},
    
        {"phases": ["running experiments"],
         "note": "I would recommend using a small dataset (approximately only 100 data points) to run experiments in order to save time. Do not use much more than this unless you have to or are running the final tests."},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "You are running on a MacBook laptop. You can use 'mps' with PyTorch"},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "Generate figures with very colorful and artistic design."},
        ]
  2. Configure research task notes in ai_lab_repo.py

    main

    To provide specific instructions to agents (e.g., experiment details, hardware constraints, or preferred coding styles), modify the task_notes_LLM list within ai_lab_repo.py. Each note can be scoped to specific research phases like plan formulation, data preparation, or running experiments.

    Example configuration for specific phases:

    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["running experiments"],
         "note": "I would recommend using a small dataset (approximately only 100 data points) to run experiments in order to save time."},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "You are running on a MacBook laptop. You can use 'mps' with PyTorch"},
    ]
    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["plan formulation", "data preparation",  "running experiments"],
         "note": "Please use gpt-4o-mini for your experiments."},
    
        {"phases": ["running experiments"],
         "note": f"Use the following code to inference gpt-4o-mini: \nfrom openai import OpenAI\nos.environ[\"OPENAI_API_KEY\"] = \"{api_key}\"\nclient = OpenAI()\ncompletion = client.chat.completions.create(\nmodel=\"gpt-4o-mini-2024-07-18\", messages=messages)\nanswer = completion.choices[0].message.content\n"},
    
        {"phases": ["running experiments"],
         "note": f"You have access to only gpt-4o-mini using the OpenAI API, please use the following key {api_key} but do not use too many inferences. Do not use openai.ChatCompletion.create or any openai==0.28 commands. Instead use the provided inference code."},
    
        {"phases": ["running experiments"],
         "note": "I would recommend using a small dataset (approximately only 100 data points) to run experiments in order to save time. Do not use much more than this unless you have to or are running the final tests."},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "You are running on a MacBook laptop. You can use 'mps' with PyTorch"},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "Generate figures with very colorful and artistic design."},
        ]
  3. Resume research from a checkpoint

    main

    If a process is interrupted (e.g., loss of internet or sub-task failure), you can resume from a previous state using the state_saves directory. Use the --load-existing and --load-existing-path flags to specify the checkpoint location.

    python ai_lab_repo.py --api-key "API_KEY_HERE" --research-topic "YOUR RESEARCH IDEA" --llm-backend "o1-mini" --load-existing True --load-existing-path "save_states/LOAD_PATH"
  4. Customize agent behavior using task_notes_LLM

    main

    To improve research outcomes, you can provide detailed instructions to the agents by modifying the task_notes_LLM structure within ai_lab_repo.py. These notes allow you to specify:

    • Project goals and stylistic preferences.
    • Specific experiments to perform.
    • API keys for required services.
    • Hardware and compute resource availability (e.g., GPU types, CPU cores, storage limits, or using 'mps' with PyTorch on MacBook).
    • Preferred models for specific phases.

    Each note is associated with specific research phases (e.g., plan formulation, data preparation, running experiments).

    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["plan formulation", "data preparation",  "running experiments"],
         "note": "Please use gpt-4o-mini for your experiments."},
    
        {"phases": ["running experiments"],
         "note": f"Use the following code to inference gpt-4o-mini: \nfrom openai import OpenAI\nos.environ[\"OPENAI_API_KEY\"] = \"{api_key}\"\nclient = OpenAI()\ncompletion = client.chat.completions.create(\nmodel=\"gpt-4o-mini-2024-07-18\", messages=messages)\nanswer = completion.choices[0].message.content\n"},
    
        {"phases": ["running experiments"],
         "note": f"You have access to only gpt-4o-mini using the OpenAI API, please use the following key {api_key} but do not use too many inferences. Do not use openai.ChatCompletion.create or any openai==0.28 commands. Instead use the provided inference code."},
    
        {"phases": ["running experiments"],
         "note": "I would recommend using a small dataset (approximately only 100 data points) to run experiments in order to save time. Do not use much more than this unless you have to or are running the final tests."},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "You are running on a MacBook laptop. You can use 'mps' with PyTorch"},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "Generate figures with very colorful and artistic design."},
        ]
  5. Provide detailed notes to the agent via task_notes_LLM

    main

    To improve research outcomes, you can provide the agent with specific instructions, style preferences, API keys, or hardware specifications (GPU/CPU/Memory). This is done by modifying the task_notes_LLM list within the ai_lab_repo.py file. Each note is associated with specific research phases (e.g., plan formulation, data preparation, running experiments).

    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["plan formulation", "data preparation",  "running experiments"],
         "note": "Please use gpt-4o-mini for your experiments."},
    
        {"phases": ["running experiments"],
         "note": f"Use the following code to inference gpt-4o-mini: \nfrom openai import OpenAI\nos.environ[\"OPENAI_API_KEY\"] = \"{api_key}\"\nclient = OpenAI()\ncompletion = client.chat.completions.create(\nmodel=\"gpt-4o-mini-2024-07-18\", messages=messages)\nanswer = completion.choices[0].message.content\n"},
    
        {"phases": ["running experiments"],
         "note": f"You have access to only gpt-4o-mini using the OpenAI API, please use the following key {api_key} but do not use too many inferences. Do not use openai.ChatCompletion.create or any openai==0.28 commands. Instead use the provided inference code."},
    
        {"phases": ["running experiments"],
         "note": "I would recommend using a small dataset (approximately only 100 data points) to run experiments in order to save time. Do not use much more than this unless you have to or are running the final tests."},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "You are running on a MacBook laptop. You can use 'mps' with PyTorch"},
    
        {"phases": ["data preparation", "running experiments"],
         "note": "Generate figures with very colorful and artistic design."},
        ]
  6. Run Agent Laboratory in non-English languages

    main

    You can instruct the agents to conduct research in languages other than English by using the --language flag. For example, to run in Chinese:

    python ai_lab_repo.py --api-key "API_KEY_HERE" --research-topic "YOUR RESEARCH IDEA (in your language)" --llm-backend "o1-mini" --language "中文"
    python ai_lab_repo.py --api-key "API_KEY_HERE" --research-topic "YOUR RESEARCH IDEA (in your language)" --llm-backend "o1-mini" --language "中文"
  7. Configure research instructions with task_notes_LLM

    main

    To provide specific guidance, hardware constraints, or coding preferences to the agents, modify the task_notes_LLM list within ai_lab_repo.py. This allows you to define instructions for specific research phases (e.g., plan formulation, data preparation, running experiments).

    Example configuration:

    task_notes_LLM = [
        {"phases": ["plan formulation"],
         "note": f"You should come up with a plan for TWO experiments."},
    
        {"phases": ["plan formulation", "data preparation",  "running experiments"],
         "note": "Please use gpt-4o-mini for your experiments."},
    
        {"phases": ["running experiments"],
         "note": "Generate figures with very colorful and artistic design."},
        }
    ]
  8. Install Agent Laboratory

    main

    Follow these steps to set up Agent Laboratory using a Python virtual environment (recommended Python 3.12):

    1. Clone the repository:
    git clone git@github.com:SamuelSchmidgall/AgentLaboratory.git
    1. Set up and activate the Python environment:
    python -m venv venv_agent_lab
    source venv_agent_lab/bin/activate
    1. Install dependencies:
    pip install -r requirements.txt
    1. Install pdflatex (Optional): To enable agents to compile LaTeX source, install pdflatex via sudo apt install pdflatex. If you do not have sudo access, disable LaTeX compilation by passing the --compile-latex "false" flag when running the application.
    # Installation sequence
    git clone git@github.com:SamuelSchmidgall/AgentLaboratory.git
    python -m venv venv_agent_lab
    source venv_agent_lab/bin/activate
    pip install -r requirements.txt
    # Optional: sudo apt install pdflatex
    python ai_lab_repo.py --yaml-location "experiment_configs/MATH_agentlab.yaml"
  9. Resume research from checkpoints

    main

    If a research session is interrupted (e.g., loss of internet or task failure), you can resume from a previous state using the --load-existing and --load-existing-path flags. Progress is automatically saved in the state_saves directory.

    python ai_lab_repo.py --api-key "API_KEY_AQUI" --research-topic "SUA IDEIA DE PESQUISA" --llm-backend "o1-mini" --load-existing True --load-existing-path "save_states/LOAD_PATH"
  10. Run research in languages other than English

    main

    To conduct research in a language other than English, provide the --language flag with the name of the desired language. Note that the research topic should also be provided in that language.

    Example for Chinese:

    python ai_lab_repo.py --api-key "API_KEY_HERE" --research-topic "YOUR RESEARCH IDEA (in your language)" --llm-backend "o1-mini" --language "中文"
  11. Configure LaTeX compilation for Agent Laboratory

    main

    Agent Laboratory can use pdflatex to compile LaTeX sources generated by agents into PDF reports.

    • To enable PDF compilation: Install pdflatex on your system:
      sudo apt install pdflatex
    • To disable PDF compilation: If you do not have sudo access or prefer not to use LaTeX, disable the compilation feature using the --compile_latex=False flag when running the application.
  12. Install Agent Laboratory via Python venv

    main

    Follow these steps to set up the Agent Laboratory environment using a Python virtual environment:

    1. Clone the repository:
      git clone git@github.com:SamuelSchmidgall/AgentLaboratory.git
    2. Create and activate the virtual environment:
      python -m venv venv_agent_lab
      source venv_agent_lab/bin/activate
    3. Install dependencies:
      pip install -r requirements.txt
    4. Install pdflatex (Optional): If you want agents to compile LaTeX code into PDFs, install pdflatex via system package manager:
      sudo apt install pdflatex
      Note: If you cannot install pdflatex, you can disable LaTeX compilation using the --compile_latex=False flag when running the application.
    git clone git@github.com:SamuelSchmidgall/AgentLaboratory.git
    python -m venv venv_agent_lab
    source venv_agent_lab/bin/activate
    pip install -r requirements.txt