项目目标
每天早上自动抓取 GitHub 上最热的 AI/Agent 仓库和 AI 编程相关新闻,用 LLM 汇总成一份 Markdown 趋势日报。
这个项目适合已经读完 OpenAI Agents SDK 入门、想做一个不太玩具化又能当天跑通的完整项目的开发者。它把工具调用、Agent 编排和输出格式串在一起——做完了你就理解了 Agent 的核心闭环。
如果你想了解为什么 AI 编程是当前最热的 Agent 赛道,参见 AI 编程工具趋势 2026 和 框架更新追踪。
技术栈选择
| 组件 | 选择 | 理由 |
|---|---|---|
| Agent SDK | OpenAI Agents SDK (Python) | 轻量、官方维护、function_tool 装饰器上手快 |
| 数据源 | GitHub REST API + RSS | GitHub API 有稳定的搜索接口;RSS 抓新闻零成本 |
| LLM | gpt-4o-mini | 日报任务不需要最强模型,mini 版够用且便宜 |
| 部署 | Cloudflare Workers Cron Trigger | 免费、定时触发、无需维护服务器 |
不用 LangGraph 或 CrewAI 这类多 Agent 框架——这个项目只有一个 Agent + 两个工具,多 Agent 编框架是过度设计。
Step 1:项目骨架
创建项目目录和依赖:
mkdir ai-coding-trends-agent && cd ai-coding-trends-agent
requirements.txt:
openai-agents>=0.0.16
httpx>=0.27.0
feedparser>=6.0.10
python-dotenv>=1.0.0
安装依赖:
pip install -r requirements.txt
.env 文件(填入你自己的 key):
OPENAI_API_KEY=sk-your-key-here
GITHUB_TOKEN=ghp_your-token-here
目录结构:
ai-coding-trends-agent/
├── .env
├── requirements.txt
├── agent.py # Agent 定义和运行入口
├── tools.py # 数据抓取工具
└── reports/ # 生成的日报输出目录
Step 2:数据抓取工具
tools.py 封装两个数据源为独立函数,Agent 会通过 function_tool 调用它们:
import os
import httpx
import feedparser
GITHUB_API = "https://api.github.com/search/repositories"
# AI 编程相关 RSS 源(可按需增减)
RSS_FEEDS = [
"https://www.latent.space/feed",
"https://simonwillison.net/atom/everything/",
"https://hnrss.org/newest?q=AI+coding",
]
def fetch_github_trending() -> str:
"""Fetch trending AI/LLM repos created in the last 7 days, sorted by stars."""
headers = {"Accept": "application/vnd.github+json"}
token = os.environ.get("GITHUB_TOKEN")
if token:
headers["Authorization"] = f"Bearer {token}"
params = {
"q": "AI agent LLM coding created:>2026-06-09",
"sort": "stars",
"order": "desc",
"per_page": 10,
}
resp = httpx.get(GITHUB_API, params=params, headers=headers, timeout=30)
resp.raise_for_status()
items = resp.json().get("items", [])
if not items:
return "未找到热门仓库。"
lines = []
for item in items[:10]:
name = item["full_name"]
stars = item["stargazers_count"]
lang = item["language"] or "N/A"
desc = item["description"] or "无描述"
lines.append(f"- {name} (★{stars}, {lang}): {desc}")
return "\n".join(lines)
def fetch_ai_news() -> str:
"""Fetch recent AI coding news from RSS feeds."""
entries = []
for feed_url in RSS_FEEDS:
feed = feedparser.parse(feed_url)
for entry in feed.entries[:5]:
title = entry.get("title", "")
link = entry.get("link", "")
entries.append(f"- {title} ({link})")
if not entries:
return "未抓取到新闻。"
return "\n".join(entries[:15])
Step 3:Agent 定义与报告生成
agent.py 定义 Agent、注册工具、运行并输出 Markdown 日报:
import asyncio
import os
from datetime import datetime
from agents import Agent, Runner, function_tool
from dotenv import load_dotenv
from tools import fetch_github_trending, fetch_ai_news
load_dotenv()
@function_tool
def get_github_trending() -> str:
"""获取近 7 天最热门的 AI/Agent/LLM 仓库。"""
return fetch_github_trending()
@function_tool
def get_ai_coding_news() -> str:
"""获取最近的 AI 编程相关新闻。"""
return fetch_ai_news()
trends_agent = Agent(
name="AI Coding Trends Reporter",
instructions="""你是一个 AI 编程趋势分析师。使用工具获取数据后,生成一份 Markdown 日报:
## 今日热门仓库
列出 top 5 仓库,每个标注语言、星标数和一句话说明。
## 值得关注的动态
从新闻中选出 3-5 条最值得注意的,每条一句话总结。
## 趋势判断
用一两句话总结今天最值得注意的变化。
输出纯 Markdown,不要多余解释。""",
tools=[get_github_trending, get_ai_coding_news],
)
async def main():
result = await Runner.run(trends_agent, "生成今天的 AI 编程趋势日报")
today = datetime.now().strftime("%Y-%m-%d")
os.makedirs("reports", exist_ok=True)
output_path = f"reports/{today}-ai-coding-daily.md"
with open(output_path, "w", encoding="utf-8") as f:
f.write(f"# AI 编程趋势日报 · {today}\n\n")
f.write(result.final_output)
print(f"日报已保存到 {output_path}")
if __name__ == "__main__":
asyncio.run(main())
Step 4:本地测试与调试
运行 Agent:
python agent.py
预期输出:日报已保存到 reports/2026-06-16-ai-coding-daily.md
打开生成的文件检查格式是否正确。常见问题:
| 问题 | 原因 | 解决 |
|---|---|---|
Authentication failed |
GITHUB_TOKEN 未设置或过期 | 检查 .env 文件,GitHub API 不带 token 有速率限制(60 次/小时) |
RateLimitError |
OpenAI API 额度用尽 | 检查账户余额,或降低 per_page 减少输入 token |
| 报告内容空洞 | prompt 不够具体 | 调整 instructions,明确每段的格式和数量要求 |
| RSS 抓取为空 | 网络或 RSS 源不可达 | 检查 RSS_FEEDS 列表中的 URL 是否可访问 |
调试技巧:在 tools.py 的函数里加 print() 打印原始数据,确认工具返回了内容再让 Agent 处理。
Step 5:部署方向
本地跑通后,下一步是让它每天自动运行。最轻量的方案是 Cloudflare Workers Cron Trigger——免费、定时触发、无需维护服务器。
最小 wrangler.toml 配置:
name = "ai-coding-trends-agent"
main = "src/index.ts"
compatibility_date = "2026-06-01"
[triggers]
crons = ["0 1 * * *"] # 每天 UTC 01:00(北京时间 09:00)
Worker 入口接收 scheduled 事件,调用 Agent 逻辑。具体实现取决于你的运行时选择(Workers 原生 TypeScript 或 Workers + Python WASM)。
完整的部署方案对比(Serverless / 容器 / 本地定时任务 / 生产级)参见 Agent 部署实操指南。如果你用 TypeScript 开发,也可以参考 OpenAI Agents JS/TS 指南 将项目迁移到 Workers 原生运行时。
本文代码可直接复制为本地项目。后续如发布示例仓库会在这里补充链接。
扩展方向
| 方向 | 做法 | 适合场景 |
|---|---|---|
| 推送到通知渠道 | 日报生成后调飞书/Slack/邮件 webhook | 团队共享 |
| 去重 | 用 SQLite 存已推送的仓库 URL,跳过重复项 | 连续运行多天后避免重复 |
| 加数据库 | 把每日数据存入 D1/Postgres,支持历史趋势查询 | 长期追踪 |
| 做成网页 | 用 Astro/Next.js 渲染日报为静态页面 | 公开分享 |
| 多 Agent | 拆成"抓取 Agent"+"分析 Agent"+"写作 Agent" | 报告质量不够时 |
扩展时先确认核心闭环(抓取 → 汇总 → 输出)稳定,再逐步加功能。不要一开始就做多 Agent 架构。