diff --git a/.claude/hooks/TaskCompleted.sh b/.claude/hooks/TaskCompleted.sh index 13d04e5..c111558 100755 --- a/.claude/hooks/TaskCompleted.sh +++ b/.claude/hooks/TaskCompleted.sh @@ -85,6 +85,13 @@ case "${TEAMMATE}" in fi ;; + ollama-multi-model-writer) + if ! file_exists_matching "paper*.md" && ! file_exists_matching "manuscript*.md"; then + echo "FEEDBACK: Task '${TASK}' cannot be marked complete. The ollama-multi-model-writer teammate must produce a draft paper file (e.g. 'paper-topic-draft.md') before completing." >&2 + exit 2 + fi + ;; + # All other teammates — no file-based gate, allow completion *) exit 0 diff --git a/.claude/teams/research-team/config.json b/.claude/teams/research-team/config.json index 5c2f5d4..8d60e14 100644 --- a/.claude/teams/research-team/config.json +++ b/.claude/teams/research-team/config.json @@ -109,6 +109,15 @@ "reportsTo": "lead-researcher", "spawnPrompt": "You are the Research Paper Reviewer. Critically evaluate AI/ML research papers — assessing contributions, methodology, experimental validity, and limitations. Load your skill from skills/research-paper-review/SKILL.md. Surface key gaps, replication candidates, and quality signals to the lead-researcher teammate." }, + { + "name": "ollama-multi-model-writer", + "agentType": "teammate", + "layer": "task", + "skill": "aviskaar/open-org#ollama-multi-model-writer", + "skillPath": "skills/ollama-multi-model-writer/SKILL.md", + "reportsTo": "lead-researcher", + "spawnPrompt": "You are the Ollama Multi-Model Writer. Write research paper sections by routing to locally-running Ollama models: DeepSeek-R1 for methods and scientific reasoning, Phi-4-reasoning for abstract and introduction, GLM-4.7-Flash for synthesis and polishing. Load your skill from skills/ollama-multi-model-writer/SKILL.md. Verify Ollama and required models are available before starting. Produce a complete draft manuscript at paper-{topic}-draft.md and report all placeholder gaps to the lead-researcher teammate." + }, { "name": "auto-benchmark", "agentType": "teammate", diff --git a/skills/lead-researcher/SKILL.md b/skills/lead-researcher/SKILL.md index 97ebd4b..f245025 100644 --- a/skills/lead-researcher/SKILL.md +++ b/skills/lead-researcher/SKILL.md @@ -14,6 +14,7 @@ metadata: - research-paper-review - research-writing - ieee-paper-generator + - ollama-multi-model-writer --- # Lead Researcher @@ -216,6 +217,21 @@ Use when the target output is a submission to an IEEE conference or journal: **Carry forward:** Draft manuscript and list of outstanding gaps. +### 7c — Local Ollama Multi-Model Draft (`ollama-multi-model-writer`) + +Use when the user wants to run paper writing locally on GPU using Ollama models (no cloud APIs): + +1. **Verify prerequisites**: Confirm Ollama is running and the required models are available — `deepseek-r1:7b`, `phi4-reasoning`, `glm4:9b-chat-q4_K_M`. If any are missing, surface the pull commands to the user before proceeding. +2. **Pass full context**: Forward the Research Brief, finalized hypothesis, literature synthesis, experiment plan, and results summary to `ollama-multi-model-writer`. +3. **Model routing** (handled by sub-skill): + - DeepSeek-R1 → Methods, Results, Experimental Setup + - Phi-4-reasoning → Abstract, Introduction, Conclusions + - GLM-4.7-Flash → Full-paper synthesis and consistency pass +4. **Review the output**: Inspect the produced `paper-{topic}-draft.md` for `[PLACEHOLDER]` and `[RESULT NEEDED]` tags and surface them to the user as a numbered list of outstanding items. +5. **Optional handoff**: If the user wants IEEE formatting, pass the draft to `ieee-paper-generator` after the Ollama draft is complete. + +**Carry forward:** Draft manuscript at `paper-{topic}-draft.md`, outstanding items list, model attribution table. + --- ## Stage 8 — Final Review & Handoff @@ -271,6 +287,7 @@ Use these shortcuts when the user's intent is clear: | "Review this paper and help me extend it" | Stage 4 → 2 → 3 → 5 → 7 | Stage 6 unless user wants replication | | "Replicate this paper and beat it" | Stage 4 → 6 → 2 → 5 → 7 | — | | "I have results, write the paper" | Stage 7 directly | Stages 2–6 (reference prior work if available) | +| "Write it locally on my GPU with Ollama" | Stage 7c (`ollama-multi-model-writer`) | Stages 2–6 (pass context if available) | | "Design experiments for this hypothesis" | Stage 3 → 5 | Stages 2 (hypothesis given), 4, 6, 7 | --- @@ -285,6 +302,6 @@ Use these shortcuts when the user's intent is clear: | 4 | Paper review report with differentiation analysis (if activated) | | 5 | Experiment plan (markdown) | | 6 | `REPLICATION.md` with gap analysis table (if activated) | -| 7 | Draft manuscript (section-by-section or full IEEE format) | +| 7 | Draft manuscript (section-by-section, full IEEE format, or local Ollama multi-model draft) | | 8 | Handoff summary and open items list | | All | Research Log with stage-by-stage entries | diff --git a/skills/ollama-multi-model-writer/SKILL.md b/skills/ollama-multi-model-writer/SKILL.md new file mode 100644 index 0000000..9aada76 --- /dev/null +++ b/skills/ollama-multi-model-writer/SKILL.md @@ -0,0 +1,232 @@ +--- +name: ollama-multi-model-writer +description: Use this skill when writing or drafting research paper sections using local Ollama models on GPU. Routes each section to the optimal local model — DeepSeek-R1 for methods, results, and scientific reasoning; Phi-4-reasoning for abstract, introduction, and conclusions; GLM-4.7-Flash for full drafts and cross-section synthesis. Activate when the user wants a fully local, offline paper-writing workflow without cloud APIs. +license: Apache-2.0 +metadata: + author: aviskaar + version: "1.0" + tags: ollama, local-llm, research-paper, multi-model, deepseek, phi4, glm, writing, gpu + models: + - deepseek-r1:7b + - phi4-reasoning + - glm4:9b-chat-q4_K_M +--- + +# Ollama Multi-Model Research Writer + +Route each research paper section to the locally-running Ollama model best suited for that task, then synthesize outputs into a unified manuscript — all on your local GPU, no cloud APIs required. + +--- + +## Model Roles + +| Model | Tag | Primary Role | Best Sections | +|-------|-----|-------------|---------------| +| **DeepSeek-R1** | `deepseek-r1:7b` | Scientific reasoning & data analysis | Methods, Results, Experiment Design, Ablations | +| **Phi-4-reasoning** | `phi4-reasoning` | PhD-level structured writing | Abstract, Introduction, Conclusions, Related Work | +| **GLM-4.7-Flash** | `glm4:9b-chat-q4_K_M` | Fluent drafting & synthesis | Full-section drafts, cross-section polish, consistency pass | + +--- + +## Prerequisites + +Before starting, verify Ollama and the required models are available: + +```bash +# Check Ollama is running +ollama list + +# Pull any missing models +ollama pull deepseek-r1:7b +ollama pull phi4-reasoning +ollama pull glm4:9b-chat-q4_K_M +``` + +If Ollama is not installed or a model is missing, surface the error to the user and halt. Do not proceed with a partial model set. + +--- + +## Section Routing Table + +| Paper Section | Primary Model | Backup Model | +|--------------|---------------|--------------| +| Abstract | `phi4-reasoning` | `glm4:9b-chat-q4_K_M` | +| Introduction | `phi4-reasoning` | `glm4:9b-chat-q4_K_M` | +| Related Work | `phi4-reasoning` | `glm4:9b-chat-q4_K_M` | +| Methodology | `deepseek-r1:7b` | `glm4:9b-chat-q4_K_M` | +| Experimental Setup | `deepseek-r1:7b` | `glm4:9b-chat-q4_K_M` | +| Results & Discussion | `deepseek-r1:7b` | `glm4:9b-chat-q4_K_M` | +| Ablation Study | `deepseek-r1:7b` | `glm4:9b-chat-q4_K_M` | +| Conclusion | `phi4-reasoning` | `glm4:9b-chat-q4_K_M` | +| Full-paper synthesis | `glm4:9b-chat-q4_K_M` | — | + +Use the backup model if the primary model is not pulled or fails to respond. + +--- + +## Workflow + +### Phase 1 — Reasoning Pass (DeepSeek-R1) + +Run DeepSeek-R1 on the technical core of the paper. Save output as `{reasoning_output}`. + +```bash +# Step 1a: Extract key claims and structure from the research idea +./scripts/ollama-runner.sh deepseek-r1:7b \ + "Analyze this research idea. Extract: (1) the core technical claim, (2) the key methodological steps, (3) what experiments would validate it, (4) what metrics matter. Be precise and scientific. Research idea: {user_idea}" + +# Step 1b: Draft the Methods section +./scripts/ollama-runner.sh deepseek-r1:7b \ + "Write a detailed Methodology section for a research paper. Include: problem formulation with formal notation, the proposed approach step-by-step, the training objective or loss function if applicable, and complexity analysis. Use [PLACEHOLDER] for any unknown details. Context: {reasoning_output}" + +# Step 1c: Draft Results section (if experiment data is provided) +./scripts/ollama-runner.sh deepseek-r1:7b \ + "Write a Results and Discussion section. Present and interpret the following experiment results honestly. Quantify improvements with exact numbers. Identify failure cases. Results data: {results_data}" +``` + +--- + +### Phase 2 — Structure Pass (Phi-4-reasoning) + +Run Phi-4-reasoning to build the academic skeleton. Save output as `{structured_output}`. + +```bash +# Step 2a: Write the Abstract +./scripts/ollama-runner.sh phi4-reasoning \ + "Write a 200-word abstract using exactly this 5-part structure: (1) Motivation — why this problem matters, (2) Problem — the precise challenge, (3) Approach — the key method named explicitly, (4) Results — concrete findings with numbers or [RESULT NEEDED], (5) Significance — what this enables. No citations. Spell out all acronyms. Context: {reasoning_output}" + +# Step 2b: Write the Introduction +./scripts/ollama-runner.sh phi4-reasoning \ + "Write an Introduction section with: (1) a concrete opening hook, (2) precise problem statement, (3) limitations of prior work with citations, (4) a bulleted list of 3-5 verifiable contributions each starting with a verb (We propose, We demonstrate, We show), (5) one-sentence paper outline. Context: {reasoning_output}" + +# Step 2c: Write the Conclusion +./scripts/ollama-runner.sh phi4-reasoning \ + "Write a Conclusion section with: (1) a summary of the problem and approach in fresh language (do not repeat the abstract), (2) key takeaways for practitioners, (3) 2-3 concrete future work directions each one sentence. Do not introduce new claims or results. Context: {reasoning_output} {results_output}" +``` + +--- + +### Phase 3 — Synthesis & Polish Pass (GLM-4.7-Flash) + +Run GLM-4.7-Flash to unify all sections into a coherent manuscript. Save output as `{synthesis_output}`. + +```bash +# Step 3a: Synthesize all sections into one draft +./scripts/ollama-runner.sh glm4:9b-chat-q4_K_M \ + "You are editing a research paper. Unify these independently-written sections into a single coherent manuscript. Ensure: consistent terminology throughout, the abstract matches the conclusion, all contributions in the introduction appear in the results, no repetition between sections. Sections: REASONING: {reasoning_output} STRUCTURED: {structured_output}" + +# Step 3b: Cross-section consistency check +./scripts/ollama-runner.sh glm4:9b-chat-q4_K_M \ + "Review this research paper draft and flag: (1) terminology inconsistencies, (2) claims in the introduction not supported by the results, (3) abstract statements not matching the paper content, (4) any [PLACEHOLDER] or [RESULT NEEDED] tags. List each issue with the section name and line. Draft: {synthesis_output}" +``` + +--- + +## Running a Single Section + +When the user asks for one section only, skip the full pipeline: + +```bash +# Abstract only +./scripts/ollama-runner.sh phi4-reasoning \ + "$(cat templates/abstract-template.md)" \ + "Research context: {user_input}" + +# Methods only +./scripts/ollama-runner.sh deepseek-r1:7b \ + "$(cat templates/methods-template.md)" \ + "Research context: {user_input}" + +# Any section — quick draft +./scripts/ollama-runner.sh glm4:9b-chat-q4_K_M \ + "Draft the {section_name} section for a research paper. Academic tone, precise language. Research context: {user_input}" +``` + +--- + +## Integration with the Lead Researcher Pipeline + +When operating inside the `lead-researcher` pipeline as **Stage 7c**: + +**Trigger**: User says they want a local/GPU workflow, or Ollama is confirmed available. + +**Inputs received from prior stages:** + +| Input | Source Stage | +|-------|-------------| +| Research Brief | Stage 1 | +| Finalized hypothesis | Stage 2 | +| Literature synthesis & gap statement | Stage 3 | +| Experiment plan | Stage 5 | +| Results summary | User-provided or Stage 6 | + +**Actions:** +1. Confirm Ollama is running and all three models are available. +2. Run Phase 1 (DeepSeek-R1) with the hypothesis + experiment plan as context. +3. Run Phase 2 (Phi-4-reasoning) with the reasoning output. +4. Run Phase 3 (GLM-4.7-Flash) to synthesize all phases. +5. Write the manuscript to `paper-{topic}-draft.md`. +6. Report draft location and all `[PLACEHOLDER]` / `[RESULT NEEDED]` tags back to `lead-researcher`. + +Optionally hand off to `ieee-paper-generator` for IEEE formatting after the draft is complete. + +--- + +## Output Format + +Save the manuscript as `paper-{topic}-draft.md` using this structure: + +```markdown +# [Paper Title] + +## Abstract +[150-250 words, 5-part structure — generated by phi4-reasoning] + +## 1. Introduction +[Generated by phi4-reasoning] + +## 2. Related Work +[Generated by phi4-reasoning] + +## 3. Methodology +[Generated by deepseek-r1] + +## 4. Experimental Setup +[Generated by deepseek-r1] + +## 5. Results and Discussion +[Generated by deepseek-r1] + +## 6. Conclusion +[Generated by phi4-reasoning] + +## References +[Numbered in order of appearance — user must supply actual citations] + +--- +## Model Attribution +| Section | Model Used | +|---------|-----------| +| Abstract | phi4-reasoning | +| Introduction | phi4-reasoning | +| Methodology | deepseek-r1:7b | +| Results | deepseek-r1:7b | +| Conclusion | phi4-reasoning | +| Synthesis pass | glm4:9b-chat-q4_K_M | + +## Data Gaps +[List all [PLACEHOLDER] and [RESULT NEEDED] tags with section references] + +## Cross-Validation Flags +[List any inconsistencies detected in the Phase 3 consistency check] +``` + +--- + +## No Fabrication Policy + +- Never invent experimental results, benchmark scores, or ablation numbers. +- Never generate fake citations, paper titles, or author names. +- Mark all missing data with `[RESULT NEEDED: description]`. +- Mark all unknown details with `[PLACEHOLDER: description]`. +- All quantitative claims in the paper must come from the user's actual experiments. diff --git a/skills/ollama-multi-model-writer/scripts/ollama-runner.sh b/skills/ollama-multi-model-writer/scripts/ollama-runner.sh new file mode 100755 index 0000000..a3d31d9 --- /dev/null +++ b/skills/ollama-multi-model-writer/scripts/ollama-runner.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# ollama-runner.sh — Run a prompt through a local Ollama model +# +# Usage: +# ./ollama-runner.sh +# +# Examples: +# ./ollama-runner.sh deepseek-r1:7b "Analyze this research idea: ..." +# ./ollama-runner.sh phi4-reasoning "Write an abstract for: ..." +# ./ollama-runner.sh glm4:9b-chat-q4_K_M "Synthesize these sections: ..." + +set -euo pipefail + +MODEL="${1:?Error: model name required. Usage: ollama-runner.sh }" +PROMPT="${2:?Error: prompt required. Usage: ollama-runner.sh }" + +# Verify ollama is in PATH +if ! command -v ollama &>/dev/null; then + echo "Error: ollama is not installed or not in PATH." >&2 + echo "Install from: https://ollama.com/download" >&2 + exit 1 +fi + +# Verify the model is available locally +if ! ollama list 2>/dev/null | awk 'NR>1 {print $1}' | grep -qx "${MODEL}"; then + echo "Error: Model '${MODEL}' is not pulled locally." >&2 + echo "Pull it with: ollama pull ${MODEL}" >&2 + echo "" >&2 + echo "Available models:" >&2 + ollama list 2>/dev/null || echo "(could not list models)" >&2 + exit 1 +fi + +# Run the model and stream output +ollama run "${MODEL}" "${PROMPT}" diff --git a/skills/ollama-multi-model-writer/templates/abstract-template.md b/skills/ollama-multi-model-writer/templates/abstract-template.md new file mode 100644 index 0000000..e2ec7de --- /dev/null +++ b/skills/ollama-multi-model-writer/templates/abstract-template.md @@ -0,0 +1,21 @@ +# Abstract Prompt Template — phi4-reasoning + +Write an abstract of 150–250 words using exactly this 5-part structure: + +1. **Motivation** (1 sentence): Why does this problem matter in the real world or in the field? +2. **Problem** (1 sentence): What specific gap or challenge does this paper address? +3. **Approach** (1–2 sentences): What is the core method or technique? Name it explicitly — do not say "a novel approach." +4. **Results** (1–2 sentences): What are the key findings? Include concrete numbers and dataset names where available; write [RESULT NEEDED: metric/dataset] for anything missing. +5. **Significance** (1 sentence): What does this work enable, unblock, or unlock for future research or practice? + +Rules: +- Do not cite references in the abstract. +- Spell out all acronyms on first use. +- Use present tense for contributions ("we propose", "this paper introduces"). +- Use past tense for experimental observations ("we found", "our method achieved"). +- Do not use vague phrases like "state-of-the-art", "novel", or "significantly better" without quantification. +- Keep to 150–250 words exactly. + +--- + +Research context to use: diff --git a/skills/ollama-multi-model-writer/templates/methods-template.md b/skills/ollama-multi-model-writer/templates/methods-template.md new file mode 100644 index 0000000..0c7c3f7 --- /dev/null +++ b/skills/ollama-multi-model-writer/templates/methods-template.md @@ -0,0 +1,40 @@ +# Methods Section Prompt Template — deepseek-r1 + +Write a Methodology section for a research paper covering all applicable subsections below. + +--- + +### A. Problem Formulation +- Define all variables and notation in a table or inline. +- State the objective function or learning task formally. +- Specify inputs, outputs, and constraints. +- Example: "Let D = {(x_i, y_i)}_{i=1}^N denote the training set where..." + +### B. Proposed Approach +- Describe the core algorithm, architecture, or framework step by step. +- If an algorithm, present numbered pseudocode steps. +- If a model or pipeline, explain how data flows through each component. +- Explain the design rationale for each key component — why this choice over alternatives. + +### C. Training Objective (if applicable) +- State each loss term as a numbered equation: (1), (2), ... +- Explain the role of each term in plain language. +- List any hyperparameters introduced and their expected sensitivity. + +### D. Complexity Analysis +- Report time complexity (training and/or inference). +- Report space complexity. +- Compare against the strongest baseline. + +--- + +Rules: +- Use numbered equations for all formal mathematical statements. +- Define all symbols immediately when introduced. +- Be precise enough that an expert could reproduce the method from this section alone. +- Write [PLACEHOLDER: description] for any detail not yet decided or known. +- Do not fabricate numbers or performance claims — those belong in the Results section. + +--- + +Research context to use: