Skip to content

Add CAJAL scientific paper agent template - #14641

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
sxxtony:feat/cajal-scientific-agent-template
Jul 1, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
sxxtony:feat/cajal-scientific-agent-template

Conversation

@sxxtony

@sxxtony sxxtony commented May 7, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #14571.

Adds CAJAL as a first-class local scientific-writing option in RAGFlow:

  • registers agnuxo/cajal-4b-p2pclaw as a known Ollama chat model with a 32K context setting
  • adds a built-in “CAJAL scientific paper agent” template under the existing agent template catalog
  • preconfigures the agent for grounded scientific writing: retrieval first, citation traceability, LaTeX-ready output, and explicit limitations when evidence is missing
  • adds unit coverage to ensure the template normalizes through RAGFlow’s production template loader, keeps graph form data in sync, and exposes the Ollama model option

Behavior/evidence gathered for the requested model:

  • Hugging Face model metadata for Agnuxo/CAJAL-4B-P2PCLAW reports pipeline_tag=text-generation and tags including gguf, llama.cpp, vllm, scientific-research, papers, academic-writing, latex, and license:apache-2.0.
  • The model card documents CAJAL as a 4B scientific paper generation model with 32K context, local inference, LaTeX/citation specialization, and CPU-only support around 5 tok/s on Ryzen 7 5800X.
  • Local CPU generation could not be completed on this machine because the advertised Ollama model name is not currently resolvable from Ollama’s registry: both https://registry.ollama.ai/v2/agnuxo/cajal-4b-p2pclaw/manifests/latest and https://registry.ollama.ai/v2/library/agnuxo/cajal-4b-p2pclaw/manifests/latest returned 404 Not Found; the Hugging Face repo tree currently exposes an 8.4 GB model.safetensors but no GGUF artifact in main. The template therefore targets the documented Ollama model name for users who have the local CAJAL deployment/model file available.

Verification run locally:

python3 -m pytest test/test_cajal_template_unit.py -q
# 3 passed in 0.34s

python3 - <<'PY'
import json, glob
for f in sorted(glob.glob('agent/templates/*.json') + ['conf/llm_factories.json']):
    with open(f, encoding='utf-8') as fp: json.load(fp)
print('json_ok')
PY
# json_ok

python3 -m ruff check test/test_cajal_template_unit.py
# All checks passed!

git diff --check

uv run pytest test/testcases/test_web_api/test_agent_app/test_cajal_template_unit.py -q was also attempted first, but dependency setup failed before test collection while building ormsgpack==1.5.0 from uv with a package metadata parse error. Clearing uv’s ormsgpack cache and retrying reproduced the same build failure, so the focused unit test was run with the system Python environment instead.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. 🧪 test Pull requests that update test cases. labels May 7, 2026
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 713f16ae-9a9c-494b-a8ff-c88ac8ceef86

📥 Commits

Reviewing files that changed from the base of the PR and between 796e505 and 4b8e4de.

📒 Files selected for processing (1)
  • conf/llm_factories.json
💤 Files with no reviewable changes (1)
  • conf/llm_factories.json

📝 Walkthrough

Walkthrough

Adds a CAJAL scientific paper agent template with Begin → Agent → Message graph wiring, retrieval-grounded generation settings, Ollama model registration, and unit tests covering template, graph, and factory consistency.

Changes

CAJAL Scientific Paper Agent

Layer / File(s) Summary
Template identity and metadata
agent/templates/cajal_scientific_paper_agent.json
Adds template top-level id, localized title/description, and canvas type configuration.
Agent component and Retrieval tool configuration
agent/templates/cajal_scientific_paper_agent.json
Defines Agent:NewPumasLick with agnuxo/cajal-4b-p2pclaw@Ollama, generation defaults, sys_prompt and output contract, and a Retrieval tool for evidence grounding.
Graph wiring, context, and serialized state
agent/templates/cajal_scientific_paper_agent.json
Adds the Begin prologue, connects Begin → Agent → Message, defines global execution context defaults, serializes node forms and edges, and initializes execution state arrays.
Ollama factory LLM entry
conf/llm_factories.json
Updates Ollama factory rank and replaces the empty llm list with the CAJAL chat model entry and its metadata.
Test helpers and template validation
test/test_cajal_template_unit.py
Adds helpers to load template_utils and the CAJAL template, then tests template identity, agent parameters, retrieval grounding, graph field synchronization, and Ollama factory registration.

Sequence Diagram(s)

sequenceDiagram
  participant Begin as Begin
  participant Agent as Agent:NewPumasLick
  participant Retrieval as Retrieval
  participant Message as Message:OrangeYearsShine
  Begin->>Agent: provide prologue and query
  Agent->>Retrieval: request evidence
  Retrieval->>Agent: return retrieved documents
  Agent->>Message: forward content
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hoppity-hop, the papers grow,
With CAJAL light and grounded flow.
The bunny writes with LaTeX flair,
Evidence tucked in every pair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding the CAJAL scientific paper agent template.
Description check ✅ Passed The description is detailed and relevant, but it does not follow the template's exact 'Summary' heading structure.
Linked Issues check ✅ Passed The template, model registration, and tests match the CAJAL integration goals for local grounded scientific writing with retrieval and LaTeX output.
Out of Scope Changes check ✅ Passed The changes stay within the CAJAL integration scope: template addition, Ollama model registration, and unit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agent/templates/cajal_scientific_paper_agent.json`:
- Around line 163-168: Remove the dangling graph edge and node referencing the
unused tool: delete the edge object with id
"xy-edge__Agent:NewPumasLicktool-Tool:AllBirdsNail" and any corresponding node
entries named "Tool:AllBirdsNail" from the JSON so the Agent
"Agent:NewPumasLick" does not reference a non-existent tool; also search for and
remove any other occurrences of "Tool:AllBirdsNail" or identical edge ids
elsewhere in the file and ensure no edges point to a tool that isn't defined in
the CAJAL retrieval tool configuration.
- Line 35: The template pins the LLM by the literal llm_id
"agnuxo/cajal-4b-p2pclaw@Ollama" which is not publicly available and causes
failures; update the agent template to either (A) add a clear note in the
template description that this model must be pre-pulled from Ollama before use
(documenting the prerequisite), or (B) implement a runtime fallback: detect
availability of the specified llm_id and if unreachable, switch to a publicly
available fallback llm_id (e.g., a known public Ollama or other provider model)
and log a clear warning; apply the chosen change to all occurrences of the
llm_id in the template (the four entries using "agnuxo/cajal-4b-p2pclaw@Ollama")
so the behavior is consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03c8ee4e-27f2-4b17-bc23-4af3ff6f0475

📥 Commits

Reviewing files that changed from the base of the PR and between bb10b83 and 99ee037.

📒 Files selected for processing (3)
  • agent/templates/cajal_scientific_paper_agent.json
  • conf/llm_factories.json
  • test/test_cajal_template_unit.py

"exception_method": null,
"frequencyPenaltyEnabled": false,
"frequency_penalty": 0.5,
"llm_id": "agnuxo/cajal-4b-p2pclaw@Ollama",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Checking public Ollama manifest endpoint for the configured model..."
curl -sS -o /tmp/cajal_manifest.json -w "HTTP %{http_code}\n" \
  https://registry.ollama.ai/v2/agnuxo/cajal-4b-p2pclaw/manifests/latest || true

echo "Checking Hugging Face repo file list for GGUF artifacts..."
curl -sS https://huggingface.co/api/models/Agnuxo/CAJAL-4B-P2PCLAW \
  | jq -r '.siblings[]?.rfilename' \
  | grep -Ei '\.gguf$' || true

Repository: infiniflow/ragflow

Length of output: 199


🏁 Script executed:

find . -name "cajal_scientific_paper_agent.json" -type f

Repository: infiniflow/ragflow

Length of output: 114


🏁 Script executed:

cat -n agent/templates/cajal_scientific_paper_agent.json | head -100

Repository: infiniflow/ragflow

Length of output: 6251


🏁 Script executed:

# Check if there are fallback mechanisms or model availability checks in the codebase
rg -i "agnuxo|cajal.*model|fallback.*model|llm.*resolve" --type json --type py --type ts --type js -A 3 -B 3

Repository: infiniflow/ragflow

Length of output: 50376


🏁 Script executed:

sed -n '230,260p' agent/templates/cajal_scientific_paper_agent.json

Repository: infiniflow/ragflow

Length of output: 3131


🏁 Script executed:

cat -n conf/llm_factories.json | grep -A 5 -B 5 "cajal"

Repository: infiniflow/ragflow

Length of output: 558


🏁 Script executed:

# Search for model resolution and fallback logic
rg -i "resolve.*model|pull.*model|fallback|default.*model" --type py -A 3 -B 3 | head -100

Repository: infiniflow/ragflow

Length of output: 6625


🏁 Script executed:

# Check lines 234 and 256 directly
sed -n '234p;256p' agent/templates/cajal_scientific_paper_agent.json

Repository: infiniflow/ragflow

Length of output: 2049


🏁 Script executed:

# Look for how llm_id is resolved at runtime - search for model resolution logic
rg "llm_id" --type py -A 5 -B 5 | head -150

Repository: infiniflow/ragflow

Length of output: 16054


🏁 Script executed:

# Check if there's error handling or validation for missing models
rg -i "model.*not.*found|llm.*unavailable|cannot.*resolve|pull.*model" --type py -A 3 -B 3 | head -80

Repository: infiniflow/ragflow

Length of output: 6638


🏁 Script executed:

# Check if there's any documentation about model availability/requirements for templates
find . -name "*.md" -o -name "*.txt" | xargs grep -l -i "template.*model\|agent.*requirement\|ollama.*pull\|model.*prerequisite" 2>/dev/null | head -5

Repository: infiniflow/ragflow

Length of output: 128


🏁 Script executed:

# Verify what happens when a template is instantiated - check agent/template loading logic
rg "load.*template|template.*agent" --type py -A 5 -B 2 | head -100

Repository: infiniflow/ragflow

Length of output: 4802


🏁 Script executed:

# Check documentation about template requirements and model setup
cat docs/guides/models/llm_api_key_setup.md | grep -A 10 -B 10 -i "template\|ollama\|local" | head -80

Repository: infiniflow/ragflow

Length of output: 2443


🏁 Script executed:

# Look for any documentation about the CAJAL model specifically
find . -type f \( -name "*.md" -o -name "*.json" -o -name "*.txt" \) | xargs grep -l "CAJAL\|cajal\|agnuxo" 2>/dev/null | head -10

Repository: infiniflow/ragflow

Length of output: 140


🏁 Script executed:

# Check the deploy_local_llm documentation for guidance on local model setup
find . -name "deploy_local_llm*" -o -name "*local*llm*" | head -10

Repository: infiniflow/ragflow

Length of output: 104


🏁 Script executed:

# Examine if there's any README or guidance about the CAJAL template
cat docs/release_notes.md | grep -A 5 -B 5 -i "cajal\|scientific" | head -60

Repository: infiniflow/ragflow

Length of output: 44


🏁 Script executed:

# Look for how agents handle missing/unavailable models at runtime
rg "Error.*model|unavailable.*model|cannot.*find.*model" --type py -A 3 -B 1 | head -80

Repository: infiniflow/ragflow

Length of output: 5468


🏁 Script executed:

# Check if there's any documentation about prerequisites or setup for the CAJAL template
cat docs/guides/models/deploy_local_llm.mdx | head -100

Repository: infiniflow/ragflow

Length of output: 4776


🏁 Script executed:

# Verify all occurrences of the model reference to understand scope
rg "agnuxo/cajal-4b-p2pclaw" --type json --type py

Repository: infiniflow/ragflow

Length of output: 4552


🏁 Script executed:

# Check the template description field to see if it mentions the prerequisite
sed -n '1,20p' agent/templates/cajal_scientific_paper_agent.json

Repository: infiniflow/ragflow

Length of output: 1003


🏁 Script executed:

# Check if there's any README or setup guide specific to CAJAL template
find . -type f -name "*cajal*" -o -name "*CAJAL*" 2>/dev/null

Repository: infiniflow/ragflow

Length of output: 149


Add documentation or provide a fallback for the CAJAL model dependency.

This template pins to agnuxo/cajal-4b-p2pclaw@Ollama, which is not publicly available (HTTP 404 from registry) and requires users to manually pull the model via Ollama first. The template description says "preconfigured" but omits this prerequisite, making "Recommended" templates fail on first run for unprepared users. Either document the requirement in the template description or add a fallback model with availability detection.

All 4 occurrences (lines 35, 57, 234, 256) use the same model; fixes should be applied consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@agent/templates/cajal_scientific_paper_agent.json` at line 35, The template
pins the LLM by the literal llm_id "agnuxo/cajal-4b-p2pclaw@Ollama" which is not
publicly available and causes failures; update the agent template to either (A)
add a clear note in the template description that this model must be pre-pulled
from Ollama before use (documenting the prerequisite), or (B) implement a
runtime fallback: detect availability of the specified llm_id and if
unreachable, switch to a publicly available fallback llm_id (e.g., a known
public Ollama or other provider model) and log a clear warning; apply the chosen
change to all occurrences of the llm_id in the template (the four entries using
"agnuxo/cajal-4b-p2pclaw@Ollama") so the behavior is consistent.

Per CodeRabbit review on PR infiniflow#14641: the CAJAL agent graph wired a
'Tool:AllBirdsNail' node and the edge connecting it to
Agent:NewPumasLick, but the node was never part of the actual
retrieval tool configuration. Carrying an orphan node/edge through
the template would surface as a confusing placeholder in the agent
editor and risks data drift if anyone tries to reattach it.

Removes:
- the xy-edge__Agent:NewPumasLicktool-Tool:AllBirdsNailend edge
- the Tool:AllBirdsNail node block

Leaves the rest of the graph intact.
@sxxtony

sxxtony commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit's dangling-tool review in 85efdb92.

Removed the orphan Tool:AllBirdsNail references that were carried over from an editor session but never wired into the actual retrieval tool configuration:

  • the xy-edge__Agent:NewPumasLicktool-Tool:AllBirdsNailend edge
  • the Tool:AllBirdsNail tool node block

Confirmed by grep -c "AllBirdsNail" agent/templates/cajal_scientific_paper_agent.json returning 0, and the JSON re-parses cleanly. The rest of the graph (Agent + retrieval edges + button edges) is unchanged.

On CodeRabbit's other comment (model-availability probe at line 35): the probes are inconclusive without a live RAGFlow runtime to evaluate model resolution, and the agent template references the model name as a plain string for downstream resolution. Leaving as-is unless a maintainer wants me to expand on the model-handling section.

Comment thread conf/llm_factories.json
"status": "1",
"rank": "830",
"llm": []
"llm": [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciations!
But this should not be added. Other users does not have this model.

@yuzhichang
yuzhichang self-requested a review June 28, 2026 00:49
@yuzhichang

yuzhichang commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

This PR currently has merge conflicts with main and cannot be auto-synced.

Please run locally:

git fetch origin main
git rebase origin/main
# or
git merge origin/main

After resolving the conflicts, push to the current head branch and CI will re-run the review checks.

Triggered by reviewer yuzhichang (request-for-action)

…1-7fio4

Resolved conflict in conf/llm_factories.json: kept the PR-side
change that adds the agnuxo/cajal-4b-p2pclaw Ollama chat model
entry (with 32K context, scientific writing tags) and its rank=830
ordering, since the two sides were mutually exclusive for that
single Ollama factory entry (main had rank=988 with an empty llm
list, the PR replaced both with rank=830 + the populated list).
@yuzhichang yuzhichang added the ci Continue Integration label Jun 30, 2026
@yuzhichang

Copy link
Copy Markdown
Member

CI ran end-to-end after the conflict-resolved merge to feat/cajal-scientific-agent-template (796e50559). The ragflow_preflight check passed, but both ragflow_tests_elasticsearch and ragflow_tests_infinity failed at the very first downstream step (Build ragflow:nightly) with:

ERROR  error during build:
[inspector-babel] Identifier 'React' has already been declared. (6:7)
file: /ragflow/web/src/components/ui/modal/modal.tsx:6:7

This is a pre-existing bug on main and is not caused by this PR. The PR only touches:

  • agent/templates/cajal_scientific_paper_agent.json (new)
  • conf/llm_factories.json (only the Ollama factory entry)
  • test/test_cajal_template_unit.py (new)

web/src/components/ui/modal/modal.tsx has a duplicate React import:

// src/components/ui/modal.tsx
import React from 'react';                                       // line 2 — duplicate
import { cn } from '@/lib/utils';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import { AlertCircle, CheckCircle, Info, Loader, X } from 'lucide-react';
import React, { FC, ReactNode, useCallback, useEffect, useMemo } from 'react';  // line 5

git log -L traces the duplicate to commit dc8b6d767 "fix(agent): inject uploaded attachments into LLM context (#15215) (#15220)" on main, which added the bare import React from 'react'; on line 2 without removing the existing named import on line 5. At the merge base (b8b741555) the file has no duplicate, so this also blocks any other PR that tries to rebuild the ragflow:nightly image.

Per web/CLAUDE.md's shared-UI lock, I'm leaving src/components/ui/ alone from this PR. Recommend either fixing the duplicate in that commit (or in a quick follow-up PR) and rebasing, then re-running CI. Once Build ragflow:nightly is green on main, this PR's own test (3 cases in test/test_cajal_template_unit.py) is small and should pass quickly.

PR-side verification I did locally after the merge commit (these all passed):

  • python3 -c "json.load(open('conf/llm_factories.json'))" — JSON parses; no conflict markers.
  • python3 -m pytest test/test_cajal_template_unit.py -v -W "ignore::pytest.PytestConfigWarning" — 3 passed (test_cajal_template_exposes_local_ollama_model_and_agent_categories, test_cajal_template_keeps_retrieval_grounding_and_graph_form_in_sync, test_cajal_is_registered_as_a_known_ollama_chat_model).

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3633d08) to head (4b8e4de).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14641   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yuzhichang
yuzhichang merged commit 06b07bb into infiniflow:main Jul 1, 2026
3 checks passed
yuzhichang pushed a commit that referenced this pull request Jul 2, 2026
### Summary

Port the following PRs to GO in this PR

#14210
#14641
#15220
#15228
#15384
#15754
#16413
#16483
#16419
#16361   
#16050
@coderabbitai coderabbitai Bot mentioned this pull request Jul 16, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants