Skip to content

tsingxuanhan/agent4science

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Agent4Science

Multi-Agent Framework for Scientific Research Automation

License: MIT Python 3.9+

Overview

Agent4Science is a production-ready multi-agent framework designed for scientific research automation. It provides a role-based agent system where specialized agents collaborate to handle complex research tasks.

Key Concepts

Agent Roles

Agent Role Description
Miner Literature Explorer Deep research and paper discovery
Assayer Knowledge Validator Cross-verification and fact-checking
Caster Code Engineer Script and code generation
Artisan Domain Expert Field-specific Q&A and explanations

Agent Collaboration

graph LR
    U[User Request] --> M[Miner]
    M --> A[Assayer]
    A --> C[Caster]
    C --> T[Artisan]
    T --> R[Result]
    
    M -.->|handoff| C
    A -.->|handoff| T
Loading

Handoff Mechanism

Agents can transfer tasks to specialized agents using the handoff system:

from agents import MinerAgent, CasterAgent

miner = MinerAgent()
handoff = miner.delegate_to(CasterAgent, "Generate analysis code")
result = handoff.execute()

Architecture

Core Components

┌─────────────────────────────────────────────────────────┐
│                    Orchestrator                         │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐  │
│  │  Miner  │  │ Assayer │  │ Caster  │  │ Artisan │  │
│  └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘  │
│       │            │            │            │        │
│       └────────────┴────────────┴────────────┘        │
│                          │                               │
│              ┌───────────┴───────────┐                  │
│              │    Handoff Manager    │                  │
│              └───────────────────────┘                  │
│                          │                               │
│  ┌───────────────────────┼───────────────────────┐     │
│  │     Checkpoint Manager (SQLite/Memory)       │     │
│  └───────────────────────────────────────────────┘     │
└─────────────────────────────────────────────────────────┘

Observability Layer

  • Tracing: End-to-end request tracing with span management
  • Metrics: Token usage tracking per agent
  • Logging: Structured logging with context propagation

Installation

git clone https://github.com/tsingxuanhan/agent4science.git
cd agent4science
pip install -r requirements.txt

Quick Start

Initialize Agents

from agents import MinerAgent, AssayerAgent, CasterAgent, ArtisanAgent

# Create specialized agents
miner = MinerAgent(model="pro")
assayer = AssayerAgent(model="flash")
caster = CasterAgent(model="pro")
artisan = ArtisanAgent(model="flash")

Research Workflow

# Step 1: Literature search
papers = miner.search_papers("low carbon cement nano modification")

# Step 2: Validate findings
verified = assayer.verify_entries(papers)

# Step 3: Generate analysis code
code = caster.generate_code(
    task="Statistical analysis of compressive strength data",
    language="python"
)

# Step 4: Get domain explanation
explanation = artisan.explain_concept("LC3 ternary blend synergy")

Orchestrated Workflow

from orchestrator import TaskOrchestrator, ExecutionMode

orchestrator = TaskOrchestrator("research_pipeline")

# Add tasks with dependencies
orchestrator.add_task("search", miner.search, depends_on=[])
orchestrator.add_task("validate", assayer.verify, depends_on=["search"])
orchestrator.add_task("generate", caster.generate, depends_on=["validate"])

# Execute
results = orchestrator.execute(mode=ExecutionMode.SEQUENTIAL)

Configuration

# config.py
MODELS = {
    "pro": "deepseek-v4-pro",      # Complex reasoning
    "flash": "deepseek-v4-flash"   # Lightweight tasks
}

DEFAULT_PARAMS = {
    "pro": {"temperature": 1.0, "max_tokens": 4096},
    "flash": {"temperature": 1.0, "max_tokens": 2048}
}

Comparison with Other Frameworks

Feature Agent4Science LangChain CrewAI AutoGen
Role-based Agents ✅ Native ⚠️ Partial ✅ Native ⚠️ Partial
Handoff System ✅ Built-in ⚠️ Limited
Checkpoint/Resume ✅ SQLite/Memory ⚠️ LangSmith
Scientific Focus ✅ Domain-aware ⚠️ General ⚠️ General ⚠️ General
Lightweight ✅ Single-file core ❌ Heavy ⚠️ Medium ⚠️ Medium

Use Cases

  1. Literature Review Automation - Batch paper discovery and summarization
  2. Code Generation for Experiments - Auto-generate analysis scripts
  3. Knowledge Validation - Cross-check research findings
  4. Domain-specific Q&A - Expert-level explanations

Project Structure

agent4science/
├── base_agent.py        # Core agent base class
├── checkpoint.py         # Persistence layer
├── handoff.py           # Task transfer system
├── memory.py             # Conversation memory
├── observability.py      # Tracing & metrics
├── orchestrator.py       # Workflow orchestration
├── config.py             # Configuration
├── agents/               # Specialized agents
│   ├── miner.py          # Literature explorer
│   ├── assayer.py        # Knowledge validator
│   ├── caster.py         # Code generator
│   └── artisan.py        # Domain expert
└── knowledge/            # Domain knowledge base

Contributing

Contributions are welcome! Please ensure:

  • New agents follow the BaseAgent interface
  • Add tests for new functionality
  • Update documentation accordingly

License

MIT License - See LICENSE for details.

About

Multi-agent framework for scientific research automation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors