使用说明
HN文摘社
一个由Google ADK和Gemini构建的人工智能代理,使用自定义MCP服务器获取实时黑客新闻故事,并将其格式化为简洁的摘要。
它做什么
- 实时从Hacker News获取五大热门新闻
- 使用模型上下文协议(MCP)连接到Hacker News Firebase API
- 返回一个干净的要点摘要,包括标题、一句话的见解、分数、作者和评论数
- 如果没有新闻请求,则以友好的问候回应
建筑学
两个顺序代理在管道中运行:
- HN费彻 --使用MCP工具调用
get_top_story_ids然后get_story_details对于前5个故事中的每一个 - 摘要撰稿人 --读取原始故事数据,并使用Gemini将其格式化为可读摘要
MCP服务器
自定义Python MCP服务器(hn_mcp_server.py)通过stdio传输公开了两个工具:
get_top_story_ids--从HN获取当前头条新闻IDget_story_details--获取给定故事ID的完整详细信息
技术栈
- 谷歌ADK --代理编排
- Gemini 2.5 Flash——通过顶点AI进行AI推理
- 模型上下文协议(MCP) --工具连接标准
- 黑客新闻Firebase API-免费,无需授权
- Google Cloud Run——无服务器部署
- Docker——容器化
现场演示
- Web用户界面:
https://hn-agent-894940280760.us-central1.run.app/dev-ui/ - API终点:
https://hn-agent-894940280760.us-central1.run.app/run
项目结构
hn-agent/
├── hn_agent/
│ ├── __init__.py
│ └── agent.py # Two LlmAgents + SequentialAgent + MCPToolset
├── hn_mcp_server.py # Custom Python MCP server
├── Dockerfile
├── entrypoint.sh
└── requirements.txt
在本地运行
先决条件
- Python 3.11+
- 码头工人
- 启用了Vertex AI的Google Cloud帐户
步骤
# Clone the repo
git clone https://github.com/YOUR_USERNAME/news-agent.git
cd news-agent
# Authenticate with Google Cloud
gcloud auth application-default login
# Build and run
docker build -t hn-agent .
docker run --rm \
-p 8080:8080 \
-e GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID \
-e GOOGLE_CLOUD_LOCATION=us-central1 \
-v ~/.config/gcloud:/root/.config/gcloud \
hn-agent
打开 http://localhost:8080/dev-ui/ 在您的浏览器中。
部署到云运行
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/hn-agent .
gcloud run deploy hn-agent \
--image=gcr.io/YOUR_PROJECT_ID/hn-agent \
--region=us-central1 \
--allow-unauthenticated \
--port=8080 \
--memory=1Gi \
--timeout=120
查询示例
- “今天黑客新闻上人们在谈论什么?”
- “立即向我展示顶级科技故事”
- “HN的趋势是什么?”