AI研究代理工具

基于LangChain的AI研究工具,聚合Web、ArXiv和配置的爬虫进行定向搜索,并可生成Markdown或HTML报告。

  • by evanyfyip
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 evanyfyip/ai-researcher-agent

使用说明

人工智能研究代理

用于基于LangChain的AI研究的MCP工具。它聚合了跨Web、ArXiv和配置的抓取器的脉冲和有针对性的搜索,并可以呈现Markdown或HTML报告。

示例报告

先决条件

  • Python 3.12+
  • uv 用于依赖关系管理(pip install uv)
  • 环境变量:
    • FOUNDRY_API_KEY
    • FOUNDRY_ENDPOINT
    • FOUNDRY_DEPLOYMENT
    • SERPAPI_API_KEY (用于网络搜索;可选但推荐)

安装/同步deps

uv sync

配置(config.yaml)

  • tools:主题和每个源的抓取器设置。
  • days_back:默认的近距窗口。
  • banners:源名称的可选映射→ 横幅图像URL/路径。如果未设置,格式化程序将查找 assets/banners/<source>.jpg.
  • llm:型号+温度。

跑步

  • MCP服务器: uv run python -m src.main
  • 脉搏报告: make pulse → 将HTML、Markdown和JSON写入 output/generated_at_YYYYMMDD_HHMMSS/ (太平洋时间)。横幅被复制到相对路径的子文件夹中。
  • 从保存的JSON重新生成: make regen SUBDIR=generated_at_YYYYMMDD_HHMMSS

HTML与Markdown输出

  • output_format="markdown" (默认):带有摘要和源代码部分的Markdown字符串。
  • output_format="html":带有横幅、可折叠源卡、每个源摘要和帖子列表的样式化HTML。保存到文件以在浏览器中查看(示例):
from src.agent import ResearcherAgent
html = ResearcherAgent().pulse_search(output_format="html")
with open("pulse_report.html", "w") as f:
    f.write(html)

自定义横幅

  • 标题横幅: assets/banners/header.jpg
  • 概述横幅: assets/banners/overview.jpg
  • 源横幅:将图片放置在 assets/banners/ 命名 <source>.jpg (例如。, arxiv.jpg, web_search.jpg,或scraper键名),或在下设置显式URL/路径 banners 在 config.yaml 由源名称键入。

添加或更新源

  1. 对于新的刮刀,请在下面添加一个条目 tools.webscrapers 在 config.yaml 带有选择器和基本URL。
  2. 对于新主题,请扩展 topics 现有工具的阵列。
  3. 重新启动MCP服务器或重新运行pulse命令以获取更改。

测试

make tests

定向搜索(程序化)

from src.agent import ResearcherAgent
agent = ResearcherAgent()
result = agent.targeted_search("my query", tools=["arxiv", "web_search"])
print(result)

MCP使用

将您的MCP兼容客户端(例如Claude Desktop)指向正在运行的服务器。工具:

  • pulse_research()
  • targeted_research(query, tools=None) (工具是逗号分隔的字符串)

项目布局

ai-researcher-agent/
├─ src/
│  ├─ agent.py            # Core agent logic, LLM summarization, orchestration
│  ├─ html_formatter.py   # HTML page rendering (banners, collapsible cards, styling)
│  ├─ pulse.py            # CLI for generating/regenerating reports (HTML/MD/JSON)
│  ├─ main.py             # MCP server entrypoint
│  └─ tools/
│     ├─ base_tool.py     # Common tool interface/helpers
│     ├─ web_search.py    # Web search integration (SerpAPI)
│     ├─ arxiv_tool.py    # ArXiv search
│     └─ webscraper_tool.py # Generic HTML/RSS scraping
├─ assets/
│  └─ banners/            # Header/overview/source banner images
├─ output/
│  └─ generated_at_*      # Generated report folders (HTML, MD, JSON, copied assets)
├─ tests/
│  └─ test_html_formatter.py # Formatter tests
├─ config.yaml            # Topics, scraper configs, banners, LLM settings
├─ Makefile               # `make pulse`, `make regen`, `make tests`
└─ README.md

架构与流程

[User / CLI / MCP client]
        |
        v
   src/pulse.py  (CLI)
      - generates live data via src.agent
      - or regenerates from saved JSON
        |
        v
   src/agent.py
      - loads config.yaml (topics, tools, banners)
      - calls tools for data (web_search, arxiv, scrapers)
      - per-source LLM summaries
      - overview summary (cross-source)
        |
        v
   src/html_formatter.py
      - renders HTML (banners, collapsible cards)
      - shared styling for inline code, lists, headers
        |
        v
   output/generated_at_*/ (HTML, Markdown, JSON, assets)

MCP path:
[MCP client] -> src/main.py (FastMCP) -> src.agent (pulse_research, targeted_research)

Tools:
- src/tools/web_search.py (SerpAPI)
- src/tools/arxiv_tool.py
- src/tools/webscraper_tool.py (HTML/RSS scraping)

许可证

Apache 2.0