How takuyakubo/ai-scientist-v2 works
Main Components
• Frontend/Output Layers: Although there isn’t an explicit “frontend” directory, the project generates outputs in the form of scientific papers (via LaTeX templates) and visualization (e.g., unified_tree_viz.html in the experiments logs). The LaTeX directories (blank_icbinb_latex and blank_icml_latex) serve as templates for paper writeups.
• Agentic Tree Search Engine: The “treesearch” directory is a key component. It contains modules for:
• Agent management (agent_manager.py)
• Backends for integrating LLMs (backend_anthropic.py, backend_openai.py)
• Utilities like debugging, log summarization, and export (bfts_utils.py, log_summarization.py, tree_export.py)
• The orchestration of experiments and the overall search process (perform_experiments_bfts_with_agentmanager.py)
• Core AI Scientist Logic: The “ai_scientist” directory (with files like llm.py, perform_ideation.py, perform_llm_review.py, and perform_writeup.py) implements the essential logic for hypothesis generation, experiment management, review phases, and writeup creation.
• Supporting Tools and APIs:
• “tools” directory encapsulates integrations like Semantic Scholar search (semantic_scholar.py) for literature and citation gathering.
• External dependencies and API keys for OpenAI, Claude (via Bedrock), and Semantic Scholar are critical, as noted in the README.
• Experimental Configurations: The “bfts_config.yaml” file is central for tuning the best-first tree search parameters. This configuration drives how experiments are launched.
Relationships and Data Flow
• Input Flow: The system starts with an idea (from the “ideas” folder) or a user-provided prompt. The idea file is injected into the system to seed the exploration process.
• Tree Search Orchestration: Once activated through the “launch_scientist_bfts.py” script, the agent manager in the treesearch module coordinates multiple agents with different roles (hypothesis generation, experiment execution, writeup, and review). This orchestration uses different backend modules to route calls to the appropriate language models (OpenAI or Anthropic).
• Execution Modules: Functions such as perform_llm_review, perform_writeup, perform_plotting, and perform_ideation manage individual phases of the scientific discovery pipeline, each interacting with one or more agents.
• Output Generation: The system uses LaTeX templates (from blank_icbinb_latex and blank_icml_latex folders) to generate final papers. In addition, visualization templates (under treesearch/utils/viz_templates) and log aggregators (journal and tree_export) build a record of the process.
• External Integrations: API calls to language model services and the Semantic Scholar API play a crucial role in hypothesis validation, idea novelty checking, and citation gathering.
Architectural Patterns and Design Principles
• Modular Design: The project is clearly divided into modules handling distinct responsibilities (idea generation, experimental orchestration, external service integration, and output formatting).
• Agent-Based System: The use of an agent manager coordinating multiple workers (agents) in a tree search paradigm is central. This fits a microservices or modular agent architecture, where each module is responsible for a specific part of the process.
• Configurable Search: Using the YAML configuration (bfts_config.yaml) allows decoupling parameters from code, emphasizing flexibility and experimentation.
• Pipeline Processing: The system executes a pipeline from ideation, through experimentation and review, to final paper generation.