Scientific Writer

Generate LaTeX-formatted academic papers with the CAJAL-4B model — single agent or multi-agent workflow

Generate LaTeX-formatted academic papers using specialized AI models designed for scientific writing.

Diagram

📝 Research Topic

🧪 Scientific Writer Agent

📄 LaTeX Section

📚 APA Citation

📑 Final Paper

Quick Start

  1. Setup

    Install PraisonAI and set up HuggingFace access:

    bash
    pip install "praisonaiagents[llm]"
    export HUGGINGFACE_API_KEY="your-key"   # for CAJAL-4B via litellm
    # Optional fallback: export OPENAI_API_KEY="your-key"
  2. Simple Scientific Writing

    Create a specialized scientific writer agent:

    python
    from praisonaiagents import Agent, tool
    
    
    @tool
    def format_latex_section(title: str, content: str) -> str:
        """Wrap prose in a LaTeX \\section{} block."""
        return f"\\section{{{title}}}\n{content}\n"
    
    
    @tool
    def format_citation(authors: str, year: int, title: str, venue: str) -> str:
        """Render an APA citation."""
        return f"{authors} ({year}). {title}. *{venue}*."
    
    
    agent = Agent(
        name="Scientific Writer",
        instructions="You are a specialised scientific paper writer. Use LaTeX formatting and APA citations.",
        llm="huggingface/Agnuxo/CAJAL-4B-P2PCLAW",
        tools=[format_latex_section, format_citation],
    )
    
    agent.start(
        "Write a short paper (Abstract + Introduction + Conclusion) on "
        "'Climate change effects on coral reef biodiversity'."
    )

How It Works

Diagram
Scientific WriterMethodology DesignerLiterature ReviewerUserScientific WriterMethodology DesignerLiterature ReviewerUserTopicLiterature review (APA)Methods (LaTeX)Complete LaTeX paper

The scientific writing system uses specialized agents for different parts of academic paper creation:

StagePurposeOutput
Literature ReviewSurvey existing researchAPA-formatted citations
Methodology DesignCreate research approachLaTeX methods section
Paper WritingAssemble final documentComplete LaTeX paper

Multi-Agent Workflow

Use multiple specialized agents for comprehensive paper generation:

python
from praisonaiagents import Agent, AgentTeam, Task, tool


@tool
def format_latex_section(title: str, content: str) -> str:
    """Wrap prose in a LaTeX \\section{} block."""
    return f"\\section{{{title}}}\n{content}\n"


@tool
def format_citation(authors: str, year: int, title: str, venue: str) -> str:
    """Render an APA citation."""
    return f"{authors} ({year}). {title}. *{venue}*."


literature_reviewer = Agent(
    name="Literature Reviewer",
    instructions="Survey academic literature. Produce 5–8 APA citations.",
    tools=[format_citation],
)

methodology_designer = Agent(
    name="Methodology Designer",
    instructions="Design a reproducible research methodology.",
    tools=[format_latex_section],
)

scientific_writer = Agent(
    name="Scientific Writer",
    instructions="Assemble the final paper. Use LaTeX + APA.",
    llm="huggingface/Agnuxo/CAJAL-4B-P2PCLAW",
    tools=[format_latex_section, format_citation],
)

topic = "Transformer architectures for protein folding prediction"

t1 = Task(name="review_literature", description=f"Review literature on: {topic}",
          agent=literature_reviewer, expected_output="APA literature review.")
t2 = Task(name="design_methodology", description=f"Design methodology for: {topic}",
          agent=methodology_designer, expected_output="LaTeX methods section.")
t3 = Task(name="write_paper",
          description=f"Combine review + methodology into a full paper on: {topic}.",
          agent=scientific_writer, expected_output="Complete LaTeX paper.")

team = AgentTeam(
    agents=[literature_reviewer, methodology_designer, scientific_writer],
    tasks=[t1, t2, t3],
)
print(team.start())

YAML Configuration

agents.yaml

yaml
framework: praisonai
topic: "Climate change effects on coral reef biodiversity"

roles:
  literature_reviewer:
    role: "Literature Reviewer"
    goal: "Survey recent academic work on {topic} and produce an APA review."
    backstory: "Expert in academic literature surveying and citation hygiene."
    llm: "gpt-4o-mini"
    tasks:
      review_literature:
        description: "Produce a concise literature review with 5-8 APA citations."
        expected_output: "APA-formatted literature review."

  methodology_designer:
    role: "Methodology Designer"
    goal: "Design a reproducible research methodology for {topic}."
    backstory: "Specialises in rigorous experimental design."
    llm: "gpt-4o-mini"
    tasks:
      design_methodology:
        description: "Write a reproducible methods section in LaTeX."
        expected_output: "LaTeX methods section."

  scientific_writer:
    role: "Scientific Writer"
    goal: "Assemble the final LaTeX paper on {topic}."
    backstory: >-
      Specialised in LaTeX-formatted academic papers, fine-tuned on
      scientific literature (CAJAL-4B checkpoint).
    llm: "huggingface/Agnuxo/CAJAL-4B-P2PCLAW"
    tasks:
      write_paper:
        description: >-
          Combine the literature review and methodology into a full
          scientific paper on {topic}. Use LaTeX formatting.
        expected_output: "Complete LaTeX paper."

Run Command

bash
praisonai agents run --file agents.yaml

Which Option to Choose?

Diagram

No, just one section

Yes

Python code

YAML config

Need full paper
with literature + methods?

Single Agent
scientific_writer.py

Prefer code
or config file?

Multi-Agent
multi_agent_paper.py

YAML workflow
agents.yaml


Configuration Options

ToolPurposeInputs
format_latex_sectionWrap prose in \section{}title: str, content: str
format_citationBuild APA citation lineauthors: str, year: int, title: str, venue: str

Model Options

ModelBest ForSetup
huggingface/Agnuxo/CAJAL-4B-P2PCLAWLaTeX-fluent academic writingRequires HuggingFace API key
gpt-4o-miniGeneral-purpose fallbackRequires OpenAI API key
Local modelsPrivacy/cost controlRun your own inference server

Best Practices

Choose the Right Model

Use CAJAL-4B for LaTeX-fluent output when HuggingFace access is available. Fall back to gpt-4o-mini for general-purpose writing when needed.

Extend with More Tools

Add more @tool functions like format_equation, format_table, or format_figure_caption to enhance the writer’s capabilities.

Split Long Papers

For lengthy papers, create separate tasks for each section (Introduction, Methods, Results, Discussion) to maintain focus and quality.

Handle API Access

Set up both HuggingFace and OpenAI API keys for maximum flexibility. Consider local inference servers for high-volume usage.


Related