LangChain Agent Skills 使用案例:GitHub 仓库分析
案例概述
本案例将展示如何创建和使用一个名为 github-analysis 的 Agent Skill,使 LangChain 深度代理能够分析 GitHub 仓库,包括获取仓库信息、问题统计和提交历史。这个技能将帮助用户快速获取 GitHub 仓库的关键指标,无需手动查询。
技能目录结构
首先,我们需要创建一个技能目录结构:
skills/ └── github-analysis/
├── SKILL.md
└── github_analysis.py
SKILL.md 文件内容
--- name: github-analysis description: Use this skill to analyze GitHub repositories, including fetching repository information, issue statistics, and commit history. ---
# GitHub Repository Analysis Skill
## Overview
This skill enables the agent to analyze GitHub repositories by fetching repository information, issue statistics, and commit history. It uses the GitHub API to retrieve relevant data and provides insights for the user.
## Instructions
### 1. Set Up GitHub API Token
Before using this skill, ensure the agent has access to a GitHub API token. The token should be stored in an environment variable `GITHUB_TOKEN`.
### 2. Fetch Repository Information
Use the `fetch_github_repo` tool to get basic repository information:
- Repository name
- Owner
- Description
- Stars
- Forks
- Watchers
- Language
- License
Example: fetch_github_repo(owner="langchain-ai", repo="langchain")
### 3. Analyze Issue Statistics
Use the `analyze_issues` tool issue statistics:
Total issues
issues
Closed issues
Average
Most active contributors
Example: analyze_issues(owner"langchain-ai", repo"langchain")
### History
Use the `get_commit_history` tool retrieve history:
Total commits
Recent commits
authors
Changes
Example: get_commit_history(owner"langchain-ai", repo"langchain", branch"main")
### Provide Comprehensive Analysis
After fetching the necessary data, provide a comprehensive analysis the repository, highlighting key metrics trends.
## Example Usage
: "Can you analyze the LangChain repository on GitHub?"
Agent:
Uses `fetch_github_repo` basic repository info
Uses `analyze_issues` issue statistics
Uses `get_commit_history` history
Combines the data provide a comprehensive analysis
Response: "The LangChain repository (langchain-ai/langchain) has 25,000 stars and 5,000 forks. It has a total of 12,000 issues, with 3,000 open and 9,000 closed. The average time to close an issue is 14 days. The main contributors are @gchhablani, @michael-007, and @joseph-lee. The commit history shows 15,000 commits on the main branch, with the most recent 10 commits focusing on improving the LangGraph integration."


