# internscience/internagent architecture

> Architecture diagram of the GitHub repository internscience/internagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/internscience/internagent
- Repository: https://github.com/internscience/internagent

## Overview

1. **Repository shape**
   - This is a Python 3.11 agent framework, not a single application.
   - The top-level system splits into: **discovery workflows**, **deep-research QA**, **persistent memory**, **model/tool abstractions**, and a large **task/benchmark workspace**.

2. **Main entry points**
   - `launch.py` is the unified CLI for both major modes.
   - `launch_discovery.py` runs the autonomous experiment loop for a chosen task.
   - `launch_qa.py` runs a direct research-question answering pipeline.
   - `demo.py`, `mcp_demo.py`, and the `scripts/` shell wrappers are convenience launchers around those flows.

3. **Configuration and runtime wiring**
   - Runtime behavior is driven by YAML under `config/` plus `.env` secrets.
   - `default_config.yaml` is the main discovery config; `openrouter_config.yaml` switches model access through OpenRouter.
   - The repo relies on external API keys for model access and embeddings, so provider choice is a key architectural boundary.

4. **Discovery orchestration layer**
   - `internagent/mas/agents/` contains the high-level scientific workflow agents: generation, refinement, ranking, reflection, evolution, survey, scholarship, and method-development roles.
   - `internagent/mas/workflow/` and `internagent/stage.py` coordinate these agents into an iterative loop that turns ideas into experiments and then into scored outcomes.
   - `internagent/mcts_node.py` and the MCTS utilities indicate search-style exploration over candidate ideas/solutions.

5. **Deep research / QA subsystem**
   - The `dr_agent.py` path and the large `internagent/mas/agents/dr_agents/` tree implement the deep-research stack.
   - This stack decomposes a question into subtasks, assigns roles such as planner/execution/coordinator/synthesizer, gathers evidence, and produces a synthesized answer.
   - The `camel/` subtree under `dr_agents` is the low-level agent runtime: it contains agents, prompts, messages, environments, terminators, interpreters, and tool agents.

6. **Model abstraction boundary**
   - `internagent/mas/models/` and `internagent/mas/agents/dr_agents/camel/models/` provide provider-specific adapters.
   - The architecture is provider-agnostic at the orchestration level, with adapters for OpenAI, OpenRouter, Anthropic, Gemini, DeepSeek, Qwen, local runtimes like Ollama/vLLM/LM Studio, and embedding models.
   - Model factories/managers isolate the rest of the system from vendor-specific APIs and model configurations.

7. **Memory and retrieval**
   - `internagent/mas/memory/` and `internagent/mas/agents/dr_agents/camel/memories/` handle persistence across runs.
   - The memory layer spans in-memory/file-based/task memory, vector retrieval, and long-term/online memory concepts.
   - Under `camel/storages/` the system supports multiple backends: Redis, JSON/in-memory, cloud object storage, vector DBs like Milvus/Qdrant/TiDB/OceanBase, and graph stores like Neo4j/Nebula.

8. **Tooling and external integrations**
   - Tool access is centralized in `internagent/mas/tools/` and `camel/toolkits/`.
   - It includes web and academic search, code search, literature search, browser automation, MCP tools, and many domain-specific toolkits.
   - External services are first-class architectural dependencies: search APIs, academic databases, browser/scraping services, and MCP servers.

9. **Task workspace and benchmark structure**
   - `tasks/` is a large benchmark/workspace directory, not product code.
   - Each task typically has a `prompt.json`, baseline `code/`, `launcher.sh`, and run artifacts such as `run_0/` with saved outputs and `final_info.json`.
   - This makes the repo behave like a research platform where the agent is evaluated against many task-specific codebases.

10. **Scientific reproduction mode**
   - `sci_tasks/` is a separate operating mode for paper reproduction, referenced in the README as coming from ResearchClawBench.
   - This mode uses paper/data-driven tasks rather than open-ended discovery, but still feeds through the same agentic orchestration and evaluation mindset.

11. **Subproject vendoring for training / RL**
   - `tasks/AutoTTRL/code/verl/` is a full embedded subproject with its own trainers, workers, reward models, rollout servers, model-merger logic, and distributed execution utilities.
   - That subtree is effectively its own ML training framework, supporting PPO/SFT/DAPO/GRPO/SPIN/SPPO-style workflows, often using Ray, FSDP, Megatron, vLLM, and SGLang.
   - In the architecture diagram, treat it as a vendored execution engine used by specific tasks, not as the core orchestration layer.

12. **Evaluation and reporting**
   - `internagent/sci_eval.py`, `internagent/vis.py`, `internagent/vis_tree.py`, and the MCTS visualization scripts support scoring and inspection of agent runs.
   - The repo produces structured artifacts per run, enabling offline analysis, comparison, and debugging of agent trajectories.

13. **Important architectural boundary**
   - The clearest boundary is between:
     - **orchestration** (agents/workflows),
     - **knowledge access** (memory/retrieval/tools),
     - **model execution** (provider adapters and runtimes),
     - and **task-specific environments** (`tasks/`, `sci_tasks/`, vendored subprojects).
   - That separation is what lets InternAgent switch between discovery, QA, and reproduction while reusing the same underlying infrastructure.

Main entry points: [`internagent/mas/workflow`](https://github.com/internscience/internagent/tree/main/internagent/mas/workflow) (workflow), [`internagent/mas/agents/dr_agents/camel`](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel) (camel runtime), [`launch.py`](https://github.com/internscience/internagent/blob/main/launch.py) (launch.py), [`tasks`](https://github.com/internscience/internagent/tree/main/tasks) (tasks/)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_launch["launch.py<br/>unified CLI<br/>[launch.py]"]
  node_launch_discovery["launch_discovery.py<br/>discovery runner"]
  node_launch_qa["launch_qa.py<br/>qa runner<br/>[launch_qa.py]"]
end

subgraph group_core["Core orchestration"]
  node_stage["stage.py<br/>discovery stage<br/>[stage.py]"]
  node_workflow["workflow<br/>orchestration"]
  node_mcts(("MCTS node<br/>search state<br/>[mcts_node.py]"))
  node_generation["generation<br/>idea proposal"]
  node_refinement["refinement<br/>idea editing"]
  node_ranking["ranking<br/>selection<br/>[ranking_agent.py]"]
  node_reflection["reflection<br/>self-check"]
end

subgraph group_dr["Deep research"]
  node_dr_agent["dr_agent.py<br/>qa orchestrator<br/>[dr_agent.py]"]
  node_dr_workflow["dr workflow<br/>qa pipeline<br/>[main.py]"]
  node_dr_agents["dr agents<br/>role stack"]
  node_camel_runtime["camel runtime<br/>agent runtime"]
end

subgraph group_infra["Shared infra"]
  node_models[("model factory<br/>provider adapters")]
  node_dr_models[("camel models<br/>provider adapters")]
  node_memory[("memory<br/>persistent state")]
  node_camel_storage[("storages<br/>backends")]
  node_tools["tools<br/>external access"]
  node_camel_toolkits["toolkits<br/>integration layer"]
end

subgraph group_tasks["Task workspace"]
  node_tasks_dir["tasks/<br/>benchmark workspace"]
  node_sci_tasks["sci_tasks/<br/>reproduction mode"]
  node_verl["AutoTTRL/verl<br/>vendored trainer"]
end

subgraph group_eval["Evaluation"]
  node_eval_vis["eval & vis<br/>reporting<br/>[sci_eval.py]"]
end

node_launch -->|"mode"| node_launch_discovery
node_launch -->|"mode"| node_launch_qa
node_launch -->|"bootstrap"| node_stage
node_launch_discovery -->|"orchestrate"| node_workflow
node_launch_qa -->|"start"| node_dr_agent
node_stage -->|"loop"| node_workflow
node_workflow -->|"propose"| node_generation
node_workflow -->|"revise"| node_refinement
node_workflow -->|"score"| node_ranking
node_workflow -->|"reflect"| node_reflection
node_workflow -->|"search"| node_mcts
node_mcts -.->|"expand"| node_generation
node_dr_agent -->|"coordinate"| node_dr_workflow
node_dr_workflow -->|"roles"| node_dr_agents
node_dr_agents -->|"run"| node_camel_runtime
node_camel_runtime -->|"llm"| node_dr_models
node_camel_runtime -->|"tools"| node_camel_toolkits
node_camel_runtime -->|"state"| node_camel_storage
node_models -.->|"embeddings"| node_memory
node_tools -->|"bridge"| node_camel_toolkits
node_tasks_dir -->|"contains"| node_verl
node_tasks_dir -->|"parallel mode"| node_sci_tasks
node_tasks_dir -.->|"artifacts"| node_eval_vis
node_dr_workflow -->|"evidence"| node_tools
node_workflow -->|"llm"| node_models
node_workflow -.->|"persist"| node_memory

click node_launch "https://github.com/internscience/internagent/blob/main/launch.py"
click node_launch_discovery "https://github.com/internscience/internagent/blob/main/launch_discovery.py"
click node_launch_qa "https://github.com/internscience/internagent/blob/main/launch_qa.py"
click node_stage "https://github.com/internscience/internagent/blob/main/internagent/stage.py"
click node_workflow "https://github.com/internscience/internagent/tree/main/internagent/mas/workflow"
click node_mcts "https://github.com/internscience/internagent/blob/main/internagent/mcts_node.py"
click node_generation "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/generation_agent.py"
click node_refinement "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/refinement_agent.py"
click node_ranking "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/ranking_agent.py"
click node_reflection "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/reflection_agent.py"
click node_dr_agent "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/dr_agent.py"
click node_dr_workflow "https://github.com/internscience/internagent/blob/main/internagent/mas/agents/dr_agents/workflow/main.py"
click node_dr_agents "https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/agents"
click node_camel_runtime "https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel"
click node_models "https://github.com/internscience/internagent/tree/main/internagent/mas/models"
click node_dr_models "https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/models"
click node_memory "https://github.com/internscience/internagent/tree/main/internagent/mas/memory"
click node_camel_storage "https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/storages"
click node_tools "https://github.com/internscience/internagent/tree/main/internagent/mas/tools"
click node_camel_toolkits "https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/toolkits"
click node_tasks_dir "https://github.com/internscience/internagent/tree/main/tasks"
click node_sci_tasks "https://github.com/internscience/internagent/tree/main/sci_tasks"
click node_verl "https://github.com/internscience/internagent/tree/main/tasks/AutoTTRL/code/verl"
click node_eval_vis "https://github.com/internscience/internagent/blob/main/internagent/sci_eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_launch,node_launch_discovery,node_launch_qa toneBlue
class node_stage,node_workflow,node_mcts,node_generation,node_refinement,node_ranking,node_reflection toneAmber
class node_dr_agent,node_dr_workflow,node_dr_agents,node_camel_runtime toneMint
class node_models,node_dr_models,node_memory,node_camel_storage,node_tools,node_camel_toolkits toneRose
class node_tasks_dir,node_sci_tasks,node_verl toneIndigo
class node_eval_vis toneTeal
```

## Components

### Entrypoints

CLI and convenience launchers for discovery, QA, demos, and scripts.

- [launch.py](https://github.com/internscience/internagent/blob/main/launch.py): unified CLI · Top-level CLI for discovery and QA modes. · `launch.py`
- [launch_discovery.py](https://github.com/internscience/internagent/blob/main/launch_discovery.py): discovery runner · Autonomous experiment loop launcher. · `launch_discovery.py`
- [launch_qa.py](https://github.com/internscience/internagent/blob/main/launch_qa.py): qa runner · Direct deep-research question answering launcher. · `launch_qa.py`

### Core orchestration

Discovery workflows, stage coordination, and search over candidate ideas.

- [stage.py](https://github.com/internscience/internagent/blob/main/internagent/stage.py): discovery stage · Coordinates the iterative discovery loop. · `internagent/stage.py`
- [workflow](https://github.com/internscience/internagent/tree/main/internagent/mas/workflow): orchestration · Workflow wiring for agent iteration and scoring. · `internagent/mas/workflow`
- [MCTS node](https://github.com/internscience/internagent/blob/main/internagent/mcts_node.py): search state · Search node for exploring candidate ideas and solutions. · `internagent/mcts_node.py`
- [generation](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/generation_agent.py): idea proposal · Produces candidate ideas and hypotheses. · `internagent/mas/agents/generation_agent.py`
- [refinement](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/refinement_agent.py): idea editing · Improves and rewrites candidate directions. · `internagent/mas/agents/refinement_agent.py`
- [ranking](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/ranking_agent.py): selection · Scores and ranks candidate outputs. · `internagent/mas/agents/ranking_agent.py`
- [reflection](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/reflection_agent.py): self-check · Evaluates progress and feeds back into iteration. · `internagent/mas/agents/reflection_agent.py`

### Deep research

Question answering workflow and its agent/runtime stack.

- [dr_agent.py](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/dr_agent.py): qa orchestrator · Entry point for deep research QA runs. · `internagent/mas/agents/dr_agent.py`
- [dr workflow](https://github.com/internscience/internagent/blob/main/internagent/mas/agents/dr_agents/workflow/main.py): qa pipeline · Coordinates planning, execution, and synthesis. · `internagent/mas/agents/dr_agents/workflow/main.py`
- [dr agents](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/agents): role stack · Planner, executor, coordinator, and synthesizer roles. · `internagent/mas/agents/dr_agents/agents`
- [camel runtime](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel): agent runtime · Low-level runtime for prompts, messages, environments, and agent loops. · `internagent/mas/agents/dr_agents/camel`

### Shared infra

Model, memory, and tool abstraction layers reused across modes.

- [model factory](https://github.com/internscience/internagent/tree/main/internagent/mas/models): provider adapters · Provider-agnostic model and embedding adapters. · `internagent/mas/models`
- [camel models](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/models): provider adapters · Deep-research-specific model adapters and factories. · `internagent/mas/agents/dr_agents/camel/models`
- [memory](https://github.com/internscience/internagent/tree/main/internagent/mas/memory): persistent state · Task, long-term, online, and retriever-backed memory. · `internagent/mas/memory`
- [storages](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/storages): backends · Redis, JSON, object storage, vector DBs, and graph stores. · `internagent/mas/agents/dr_agents/camel/storages`
- [tools](https://github.com/internscience/internagent/tree/main/internagent/mas/tools): external access · Search, literature, code, browser, MCP, and domain tool access. · `internagent/mas/tools`
- [toolkits](https://github.com/internscience/internagent/tree/main/internagent/mas/agents/dr_agents/camel/toolkits): integration layer · Large toolkit set used by deep-research agents. · `internagent/mas/agents/dr_agents/camel/toolkits`

### Task workspace

Benchmark and reproduction environments, including vendored ML training engines.

- [tasks/](https://github.com/internscience/internagent/tree/main/tasks): benchmark workspace · Task-specific prompts, codebases, launches, and run artifacts. · `tasks`
- [sci_tasks/](https://github.com/internscience/internagent/tree/main/sci_tasks): reproduction mode · Paper reproduction tasks and evaluation mode. · `sci_tasks`
- [AutoTTRL/verl](https://github.com/internscience/internagent/tree/main/tasks/AutoTTRL/code/verl): vendored trainer · Embedded RL/training engine used by specific tasks. · `tasks/AutoTTRL/code/verl`

### Evaluation

Scoring, visualization, and run inspection utilities.

- [eval & vis](https://github.com/internscience/internagent/blob/main/internagent/sci_eval.py): reporting · Offline scoring, MCTS visualization, and run inspection. · `internagent/sci_eval.py`

## Connections

- launch.py → launch_discovery.py: mode · Unified CLI dispatches into discovery runs.
- launch.py → launch_qa.py: mode · Unified CLI dispatches into QA runs.
- launch.py → stage.py: bootstrap · CLI wires shared discovery runtime.
- launch_discovery.py → workflow: orchestrate · Runs the iterative discovery workflow.
- launch_qa.py → dr_agent.py: start · Runs the deep-research QA pipeline.
- stage.py → workflow: loop · Stage coordinates workflow iterations.
- workflow → generation: propose · Workflow requests candidate ideas.
- workflow → refinement: revise · Workflow refines candidates between rounds.
- workflow → ranking: score · Workflow ranks candidate outputs.
- workflow → reflection: reflect · Workflow uses reflective feedback.
- workflow → MCTS node: search · Discovery loop explores candidates via search.
- MCTS node → generation: expand · Search expands new proposal states.
- dr_agent.py → dr workflow: coordinate · QA entrypoint delegates to workflow.
- dr workflow → dr agents: roles · Workflow assigns planner/executor/coordinator/synthesizer roles.
- dr agents → camel runtime: run · High-level roles execute via the agent runtime.
- camel runtime → camel models: llm · Runtime calls provider adapters.
- camel runtime → toolkits: tools · Runtime invokes toolkits and external integrations.
- camel runtime → storages: state · Runtime persists and retrieves shared state.
- model factory → memory: embeddings · Core model layer supports embedding-backed retrieval.
- tools → toolkits: bridge · Shared tool layer feeds the deeper toolkit stack.
- tasks/ → AutoTTRL/verl: contains · Some tasks vendor a full training engine.
- tasks/ → sci_tasks/: parallel mode · Benchmark tasks coexist with scientific reproduction tasks.
- tasks/ → eval & vis: artifacts · Task runs produce structured outputs for analysis.
- dr workflow → tools: evidence · QA workflow depends on search and evidence tools.
- workflow → model factory: llm · Discovery agents use shared model abstractions.
- workflow → memory: persist · Discovery loop can write and read persistent memory.
