How internscience/internagent works
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: workflow workflow · camel camel runtime · launch.py launch.py · tasks tasks/
Components 24
Entrypoints
CLI and convenience launchers for discovery, QA, demos, and scripts.
- launch.py · Top-level CLI for discovery and QA modes.
launch.py - launch_discovery.py · Autonomous experiment loop launcher.
launch_discovery.py - launch_qa.py · Direct deep-research question answering launcher.
launch_qa.py
Core orchestration
Discovery workflows, stage coordination, and search over candidate ideas.
- stage.py · Coordinates the iterative discovery loop.
internagent/stage.py - workflow · Workflow wiring for agent iteration and scoring.
internagent/mas/workflow - MCTS node · Search node for exploring candidate ideas and solutions.
internagent/mcts_node.py - generation · Produces candidate ideas and hypotheses.
internagent/mas/agents/generation_agent.py - refinement · Improves and rewrites candidate directions.
internagent/mas/agents/refinement_agent.py - ranking · Scores and ranks candidate outputs.
internagent/mas/agents/ranking_agent.py - reflection · 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 · Entry point for deep research QA runs.
internagent/mas/agents/dr_agent.py - dr workflow · Coordinates planning, execution, and synthesis.
internagent/mas/agents/dr_agents/workflow/main.py - dr agents · Planner, executor, coordinator, and synthesizer roles.
internagent/mas/agents/dr_agents/agents - camel 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 · Provider-agnostic model and embedding adapters.
internagent/mas/models - camel models · Deep-research-specific model adapters and factories.
internagent/mas/agents/dr_agents/camel/models - memory · Task, long-term, online, and retriever-backed memory.
internagent/mas/memory - storages · Redis, JSON, object storage, vector DBs, and graph stores.
internagent/mas/agents/dr_agents/camel/storages - tools · Search, literature, code, browser, MCP, and domain tool access.
internagent/mas/tools - toolkits · 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/ · Task-specific prompts, codebases, launches, and run artifacts.
tasks - sci_tasks/ · Paper reproduction tasks and evaluation mode.
sci_tasks - AutoTTRL/verl · Embedded RL/training engine used by specific tasks.
tasks/AutoTTRL/code/verl
Evaluation
Scoring, visualization, and run inspection utilities.
- eval & vis · Offline scoring, MCTS visualization, and run inspection.
internagent/sci_eval.py
Connections 26
- 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.