System Architecture
BioAgents implements a multi-agent architecture where independent, specialized agents collaborate to perform scientific research. Each agent is a self-contained function that performs a specific task in the research workflow.Core Design Principles
Modularity
Agents are independent functions that can be composed and reused
Specialization
Each agent focuses on one specific task (planning, literature, analysis, etc.)
State Management
Clear separation between ephemeral message state and persistent conversation state
Parallel Execution
Tasks execute concurrently for maximum performance
Agent Types
BioAgents includes seven specialized agents:1. Planning Agent
Purpose: Decides WHAT tasks to run based on current state and user input Location:src/agents/planning/index.ts
Key Responsibilities:
- Analyzes available datasets and research context
- Generates task sequences (LITERATURE or ANALYSIS)
- Updates current research objectives
2. Literature Agent
Purpose: Searches and synthesizes scientific literature Location:src/agents/literature/
Supported Backends:
- OPENSCHOLAR: General scientific literature with citations
- EDISON: Deep research mode literature search
- BIO: BioAgents literature API (recommended)
- KNOWLEDGE: Custom knowledge base with semantic search
(claim)[DOI or URL]
3. Analysis Agent
Purpose: Performs data analysis on uploaded datasets Location:src/agents/analysis/
Supported Backends:
- EDISON: Deep analysis via Edison AI agent
- BIO: BioAgents Data Analysis Agent (state-of-the-art)
- Uploads datasets to analysis service
- Executes analysis code
- Retrieves results and artifacts (plots, figures)
4. Hypothesis Agent
Purpose: Generates research hypotheses from completed tasks Location:src/agents/hypothesis/
Key Responsibilities:
- Synthesizes findings from literature and analysis
- Creates testable hypotheses with inline citations
- Considers current research context and objectives
currentHypothesis
5. Reflection Agent
Purpose: Reflects on research progress and extracts insights Location:src/agents/reflection/
Key Responsibilities:
- Extracts key insights and discoveries
- Updates research methodology
- Maintains conversation-level understanding
- Updates conversation title
currentObjective, keyInsights, methodology, conversationTitle
6. Discovery Agent
Purpose: Identifies novel claims with evidence links Location:src/agents/discovery/
Key Responsibilities:
- Identifies novel scientific claims
- Links claims to supporting evidence (taskId, jobId)
- Maintains traceability: claims → evidence → tasks
discoveries[]
7. Reply Agent
Purpose: Generates user-facing responses Location:src/agents/reply/
Modes:
- Deep Research Mode: Includes current objective, next steps, asks for feedback
- Chat Mode: Concise answers without next steps
- Preserves inline citations throughout
- Adapts tone based on mode
Agent Collaboration Pattern
Two Main Routes
BioAgents operates through two primary routes:Chat Route
Endpoint:POST /api/chat
Purpose: Agent-based chat for general research questions with automatic literature search
File: src/routes/chat.ts:46
Workflow:
- File Upload Agent (if files provided)
- Planning Agent (literature tasks only)
- Literature Agent (parallel execution)
- Hypothesis Agent (if needed)
- Reflection Agent (if hypothesis generated)
- Reply Agent (concise response)
Deep Research Route
Endpoint:POST /api/deep-research/start
Purpose: Iterative hypothesis-driven investigation with human-in-the-loop steering
File: src/routes/deep-research/start.ts:115
Workflow:
- File Upload Agent (if files provided)
- Planning Agent (literature + analysis tasks)
- Execute tasks in parallel (Literature + Analysis)
- Hypothesis Agent (synthesize findings)
- Reflection Agent + Discovery Agent (parallel)
- Planning Agent (“next” mode - plan next iteration)
- Continue Research Agent (decide if autonomous continuation)
- Reply Agent (with next steps and feedback request)
Execution Modes
BioAgents supports two execution modes:In-Process Mode (Default)
- Jobs execute directly in the main process
- Simpler for development
- Lower latency
Queue Mode (Production)
- Jobs queued in Redis via BullMQ
- Processed by separate worker processes
- Horizontal scaling support
- Automatic retries
- Admin dashboard at
/admin/queues
See Job Queue documentation for detailed configuration.
Adding New Agents
To add a new agent:- Create folder in
src/agents/ - Implement main function in
index.ts - Add supporting logic in separate files
- Export agent function for use in routes
- Shared utilities go in
src/utils/
LLM Integration
All agents use the unified LLM library atsrc/llm/provider.ts:
- Anthropic (Claude)
- OpenAI (GPT)
- Google (Gemini)
- OpenRouter
Next Steps
Agents
Detailed agent implementations
Deep Research
Deep research workflow
State Management
State vs ConversationState
Setup Guide
Environment setup