Skip to content

About

AI-powered LaTeX citation assistant for VS Code Copilot. Auto-add academic citations with anti-hallucination — all references from real-time Semantic Scholar queries. Zero dependencies, cross-platform, any workspace. Based on KyuDan1/citeAgent.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

CiteAgent for VS Code Copilot

AI-powered citation assistant for VS Code Copilot — Add academic citations to your LaTeX or Word documents through conversational interaction. All citations are sourced from real-time Semantic Scholar queries, eliminating AI hallucinations.

基于 VS Code Copilot 的学术引用助手 — 通过对话交互为你的 LaTeX 或 Word 文档自动添加学术引用,所有引用均来自 Semantic Scholar 实时查询,杜绝 AI 幻觉。

English | 中文

Based on KyuDan1/citeAgent. Credits to Kyudan Jung (정규단) for the original concept.

本项目改造自 KyuDan1/citeAgent,感谢原作者 Kyudan Jung (정규단) 的创意和工作。


与原版的对比

原版 citeAgent 本改造版
LLM 需要 Gemini / Upstage API Key(付费) VS Code Copilot 自身(无需额外 key)
编辑方式 Selenium 操控浏览器 ACE 编辑器 VS Code 原生文件读写
同步 Overleaf 必须在浏览器中打开 Overleaf Overleaf Workshop 扩展自动同步
使用方式 命令行 python main.py Chat 对话式 @CiteAgent
适用平台 主要支持 macOS (Safari AppleScript) 全平台 (Windows / macOS / Linux)
依赖 openai, google-generativeai, selenium 等 零依赖 — 纯 Python stdlib
使用范围 仅在项目目录内 任何 VS Code 工作区
交互方式 命令行单次处理 对话式,可指定段落/章节/全文
文件格式 仅 LaTeX (.tex) LaTeX (.tex) + Word (.docx),支持 APA 7th、IEEE等格式输出

核心特性

防幻觉机制(核心)

这是本工具最重要的设计原则。每一条引用都必须来自 Semantic Scholar API 的实时查询结果:

你的论文 (.tex)
    ↓
Copilot 分析 "哪里需要引用"(LLM 判断,无需真实数据)
    ↓
Copilot 生成搜索关键词(最多 3 个词)
    ↓
scholar.py 查询 Semantic Scholar API ← 唯一论文数据来源
    ↓
Copilot 从返回结果中选择最佳论文(仅能选,不能编造)
    ↓
使用 scholar.py 返回的 bibtex_key 和 bibtex_entry(原样使用)
    ↓
编辑 .tex 插入 \cite{},编辑 .bib 追加条目

5 条硬性约束:

  1. 每个 \cite{} 的 key 必须来自 scholar.py 返回的 JSON
  2. BibTeX 条目必须逐字复制 scholar.py 返回的 bibtex_entry
  3. 必须先搜索、再引用,不能跳过搜索步骤
  4. 搜不到就跳过,不能用 LLM 自己"记忆"的论文凑数
  5. 搜到的论文标题必须与概念相关,不能张冠李戴

论文覆盖范围

Semantic Scholar 索引论文的元数据(标题、作者、年份、引用数、DOI),涵盖几乎所有学术期刊和会议:

来源 覆盖
Nature / Science / Cell ✅
IEEE / ACM / ACL / NeurIPS / ICML / CVPR ✅
Elsevier / Springer / Wiley ✅
arXiv 预印本 ✅

无论论文是否开源,只要发表了就能搜到并生成正确的 BibTeX。

支持 Word 文档(.docx)

CiteAgent 不仅支持 LaTeX,还可以为 Word 文档生成 APA 7th 格式的引用:

  • 分析文本内容,识别需要引用的概念
  • 通过 scholar.py 搜索真实论文
  • 在文中插入 (Author, Year) 格式的行内引用
  • 使用 docx_helper.py 生成带有可点击 DOI 超链接的 References 页
  • 支持 APA 7th 格式:悬挂缩进、斜体期刊名、双倍行距

需额外安装 python-docx:pip install python-docx

其他特性

  • 零依赖安装:scholar.py 仅使用 Python 标准库(urllib + json),任何 Python 3.6+ 环境即可运行
  • 全平台支持:Windows / macOS / Linux
  • 对话式交互:可以处理整篇文档、指定章节、或粘贴的文本片段
  • 智能引用放置:在概念首次出现处插入引用,而非仅在句末
  • 自动匹配引用风格:检测文档已有的 \cite/\citep/\citet/\citeA 风格并保持一致,支持 natbib、biblatex、apacite 和 IEEE
  • HTTP 200 来源核查:生成政策表、定义表、Excel/Word 报告或链接审计时,逐条验证来源链接可访问,并用关键词和证据片段确认来源支撑具体 claim
  • 配合 Overleaf Workshop:编辑后文件自动同步到 Overleaf

安装

前提条件

自动安装(推荐)

Windows (PowerShell)

git clone https://github.com/Di0105/CiteAgent-Copilot.git
cd CiteAgent-Copilot
.\install.ps1

macOS / Linux (Bash)

git clone https://github.com/Di0105/CiteAgent-Copilot.git
cd CiteAgent-Copilot
chmod +x install.sh
./install.sh

手动安装

  1. 将 scholar.py 复制到你喜欢的位置(例如 ~/.agents/scripts/cite-agent/scholar.py)

  2. 编辑 cite-agent.agent.md,找到 Step 3 中的 scholar.py 路径,替换为你的实际路径:

    python "/your/path/to/scholar.py" search "QUERY" --limit 5 --min-citations 10
    
  3. 将修改后的 cite-agent.agent.md 复制到 VS Code 用户 prompts 目录:

    • Windows: %APPDATA%\Code\User\prompts\
    • macOS: ~/Library/Application Support/Code/User/prompts/
    • Linux: ~/.config/Code/User/prompts/
  4. 重启 VS Code

验证安装

python /path/to/scholar.py search "BERT" --limit 3

如果输出 JSON 数组(包含论文信息),说明安装成功。

(可选)Semantic Scholar API Key

无 key 也能正常使用,但有速率限制(每分钟约 100 次请求)。如需提高限额:

  1. 在 Semantic Scholar API 免费申请 API Key
  2. 设置环境变量:
    • Windows: [System.Environment]::SetEnvironmentVariable("SEMANTIC_SCHOLAR_API_KEY", "your-key", "User")
    • macOS/Linux: 在 ~/.bashrc 或 ~/.zshrc 中添加 export SEMANTIC_SCHOLAR_API_KEY="your-key"

使用方法

基本用法

  1. 在 VS Code 中打开你的 LaTeX 项目
  2. 打开 Copilot Chat(Ctrl+Shift+I 或侧边栏)
  3. 在 Agent 选择器中选择 CiteAgent
  4. 发送请求

示例对话

处理整个文件

@CiteAgent 帮我给 paper.tex 添加引用

处理指定章节

@CiteAgent 只给 Introduction 部分添加引用

粘贴文本片段

@CiteAgent 帮我给这段文字添加引用:

Self-supervised learning has revolutionized speech processing.
The Transformer architecture has become the backbone of modern speech models.
WavLM achieves state-of-the-art performance on the SUPERB benchmark.

处理 Word 文档

@CiteAgent 帮我给这段文字添加 APA 7th 引用,输出为 Word 文档

CiteAgent 会:

  1. 分析文本,识别需要引用的概念
  2. 用 scholar.py 搜索论文
  3. 生成带行内引用 (Author, Year) 的文本
  4. 用 docx_helper.py 创建 APA 7th 格式的 .docx,References 页的 DOI 均为可点击超链接

指定搜索要求

@CiteAgent 帮我给 methods.tex 添加引用,优先选择高引用论文(> 100 引用)

工作流程示例

以下是 CiteAgent 处理一篇论文的完整流程:

输入 (paper.tex):

Self-supervised learning has revolutionized speech processing.
WavLM is a large-scale pre-training model designed for speech.
We use t-SNE for dimensionality reduction.

CiteAgent 自动执行:

  1. 读取 paper.tex
  2. 识别需要引用的概念:WavLM、t-SNE、self-supervised learning
  3. 运行搜索:
    python scholar.py search "WavLM"
    python scholar.py search "t-SNE"
    python scholar.py search "self-supervised speech"
    
  4. 从 Semantic Scholar 返回结果中选择最佳论文
  5. 编辑文件

输出 (paper.tex):

Self-supervised learning has revolutionized speech processing~\cite{baevski2020wav2vec}.
WavLM~\cite{chen2021wavlm} is a large-scale pre-training model designed for speech.
We use t-SNE~\cite{maaten2008visualizing} for dimensionality reduction.

同时追加到 references.bib:

@article{chen2021wavlm,
  title={WavLM: Large-Scale Self-Supervised Pre-Training for Full Stack Speech Processing},
  author={Sanyuan Chen and Chengyi Wang and ...},
  year={2021},
  doi={10.1109/JSTSP.2022.3188113},
}

@article{maaten2008visualizing,
  title={Visualizing Data using t-SNE},
  author={Laurens van der Maaten and Geoffrey Hinton},
  year={2008},
}

配合 Overleaf Workshop 使用

  1. 安装 Overleaf Workshop 扩展
  2. 登录 Overleaf 并打开项目
  3. 正常使用 @CiteAgent — 编辑后的文件会自动同步到 Overleaf

项目结构

CiteAgent-Copilot/
├── README.md                  # 本文档
├── LICENSE                    # MIT License
├── scholar.py                 # Semantic Scholar 搜索脚本(零依赖)
├── docx_helper.py             # Word 文档辅助工具(需 python-docx)
├── cite-agent.agent.md        # VS Code Copilot Agent 定义(模板)
├── install.ps1                # Windows 安装脚本
├── install.sh                 # macOS/Linux 安装脚本
└── examples/
    ├── paper.tex              # 示例 LaTeX 文件(未引用)
    └── references.bib         # 空的 BibTeX 文件

致谢

License

MIT License — 详见 LICENSE 文件


English Version

CiteAgent for VS Code Copilot

AI-powered citation assistant for VS Code Copilot — Add academic citations to your LaTeX or Word documents through conversational interaction. All citations are sourced from real-time Semantic Scholar queries, eliminating AI hallucinations.

Based on KyuDan1/citeAgent. Credits to Kyudan Jung for the original concept.

Key Advantages over Original

Original citeAgent This Version
LLM Requires Gemini / Upstage API Key Uses VS Code Copilot (no extra key)
Editing Selenium browser automation Native VS Code file editing
Overleaf Sync Must open Overleaf in browser Overleaf Workshop extension auto-syncs
Usage CLI python main.py Chat-based @CiteAgent
Platform Primarily macOS (Safari AppleScript) Cross-platform (Windows/macOS/Linux)
Dependencies openai, selenium, etc. Zero dependencies (Python stdlib only)
Scope Project-local only Any VS Code workspace
File Formats LaTeX (.tex) only LaTeX (.tex) + Word (.docx) with APA 7th、IEEE output

Anti-Hallucination Mechanism (Core Feature)

Every citation MUST come from Semantic Scholar API real-time query results. The agent is strictly forbidden from fabricating papers from its training data.

HTTP 200 Source Verification

For structured outputs that depend on external links, such as policy tables, official-source summaries, definition tables, Excel workbooks, Word reports, or citation/link audits, CiteAgent verifies each source URL before relying on it. A source must return HTTP 200 and contain claim-specific evidence; otherwise the claim is revised, downgraded to a general clause, or omitted. Verification logs can include fetch status, matched keywords, missing patterns, and compact evidence snippets.

Installation

git clone https://github.com/Di0105/CiteAgent-Copilot.git
cd CiteAgent-Copilot

# Windows
.\install.ps1

# macOS / Linux
chmod +x install.sh && ./install.sh

Usage

Open Copilot Chat in VS Code → select CiteAgent → send your request:

@CiteAgent Add citations to my paper.tex
@CiteAgent Only cite the Introduction section
@CiteAgent Add citations to this text: [paste LaTeX]
@CiteAgent Add APA 7th citations and generate a Word document

Word Document Support (.docx)

CiteAgent also supports Word documents with APA 7th formatting:

  • In-text citations in (Author, Year) format
  • References page with hanging indent, italicised journal names, and clickable DOI hyperlinks
  • Requires pip install python-docx for the docx_helper.py utility

Requirements

  • VS Code with GitHub Copilot & Copilot Chat extensions
  • Python 3.6+
  • (Optional) python-docx for Word document generation
  • (Optional) Overleaf Workshop extension for Overleaf sync

About

AI-powered LaTeX citation assistant for VS Code Copilot. Auto-add academic citations with anti-hallucination — all references from real-time Semantic Scholar queries. Zero dependencies, cross-platform, any workspace. Based on KyuDan1/citeAgent.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages