Build an AI Agent That Reviews Your Dependencies
Learn to build a practical AI agent that audits your project dependencies for security, license, and maintenance issues using OpenAI and GitHub Actions.
Before you start
You have a Node.js project with a package.json file and a growing list of dependencies. You want to know which ones have known vulnerabilities, which are outdated, and which have licenses you need to worry about. Instead of manually checking each one, you can build an AI agent that reviews your dependencies and reports back with actionable insights.
This tutorial walks you through creating a dependency review agent using OpenAI's function calling and GitHub Actions. You will end up with a workflow that runs on every pull request and posts a comment summarizing risks and suggestions.
You need Node.js 18 or later, an OpenAI API key, and a GitHub repository. The agent will use the npm audit and license-checker tools to gather data, then send it to GPT-4o-mini for analysis.
node --version
npm --version
# confirm you have Node 18+ and npm 9+- Node.js 18+ installed locally
- An OpenAI API key with access to GPT-4o-mini
- A GitHub repository with a package.json file
- Basic familiarity with JavaScript and GitHub Actions
Step 1: Set up the project scaffold
Create a new directory and initialize a Node.js project. You will install the necessary packages: openai for API access, license-checker for license reporting, and dotenv for environment variables.
The agent will be a script that runs in a GitHub Action, but you will develop it locally first. Make sure to keep your API key in a .env file that is not committed to version control.
mkdir dependency-review-agent
cd dependency-review-agent
npm init -y
npm install openai dotenv license-checker
npm install --save-dev @types/node typescriptStep 2: Write the dependency collection script
The first part of the agent is collecting data. You will run npm audit --json to get vulnerability information and license-checker --json to get license details. Both commands output JSON, which you can parse and combine.
Create a file called collect.js that runs these commands and writes the combined data to a temporary file. This script will be called by the main agent script.
// collect.js
const { execSync } = require('child_process');
const fs = require('fs');
const audit = JSON.parse(execSync('npm audit --json').toString());
const licenses = JSON.parse(execSync('npx license-checker --json').toString());
const data = {
audit,
licenses
};
fs.writeFileSync('deps.json', JSON.stringify(data, null, 2));
console.log('Dependency data collected and saved to deps.json');Step 3: Define the AI agent loop
The core of the agent is a loop that sends the collected data to OpenAI and asks for a structured review. You will use function calling to get a JSON response with sections for vulnerabilities, outdated packages, license risks, and recommendations.
The agent will have a system prompt that instructs GPT to act as a senior dependency reviewer. The function schema ensures the output is consistent and machine-readable.
// agent.js
const OpenAI = require('openai');
const fs = require('fs');
require('dotenv').config();
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const depsData = fs.readFileSync('deps.json', 'utf8');
const tools = [
{
type: 'function',
function: {
name: 'submit_review',
description: 'Submit the final dependency review report',
parameters: {
type: 'object',
properties: {
summary: { type: 'string', description: 'Overall summary of the dependency health' },
vulnerabilities: { type: 'array', items: { type: 'string' }, description: 'List of known vulnerabilities' },
outdated: { type: 'array', items: { type: 'string' }, description: 'List of outdated packages' },
license_risks: { type: 'array', items: { type: 'string' }, description: 'List of license concerns' },
recommendations: { type: 'array', items: { type: 'string' }, description: 'Actionable recommendations' }
},
required: ['summary', 'vulnerabilities', 'outdated', 'license_risks', 'recommendations']
}
}
}
];
async function run() {
const messages = [
{
role: 'system',
content: 'You are a senior dependency reviewer. Analyze the provided npm audit and license data. Focus on critical vulnerabilities, outdated packages, and license compatibility. Provide clear, actionable recommendations.'
},
{
role: 'user',
content: `Here is the dependency data:\n\n${depsData}`
}
];
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages,
tools,
tool_choice: { type: 'function', function: { name: 'submit_review' } }
});
const toolCall = response.choices[0].message.tool_calls[0];
const review = JSON.parse(toolCall.function.arguments);
console.log(JSON.stringify(review, null, 2));
}
run().catch(console.error);Step 4: Run the agent locally
Test the agent locally by running the collection script and then the agent script. You should see a JSON review printed to the console.
Make sure your .env file has your OPENAI_API_KEY set. If you get a rate limit error, wait a moment and retry.
echo 'OPENAI_API_KEY=your-key-here' > .env
node collect.js
node agent.jsStep 5: Integrate with GitHub Actions
Now you want the agent to run automatically on every pull request. Create a GitHub Actions workflow that checks out the code, sets up Node, installs dependencies, runs the agent, and posts a comment with the review.
The workflow will use the actions/github-script action to create a comment on the pull request. The review JSON will be formatted into a markdown table.
name: Dependency Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- name: Collect dependency data
run: node collect.js
- name: Run AI agent
id: agent
run: |
REVIEW=$(node agent.js)
echo "review=$REVIEW" >> $GITHUB_OUTPUT
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Post comment
uses: actions/github-script@v7
with:
script: |
const review = JSON.parse(process.env.REVIEW);
const body = `## Dependency Review\n\n**Summary:** ${review.summary}\n\n### Vulnerabilities\n${review.vulnerabilities.map(v => '- ' + v).join('\n') || 'None'}\n\n### Outdated\n${review.outdated.map(o => '- ' + o).join('\n') || 'None'}\n\n### License Risks\n${review.license_risks.map(l => '- ' + l).join('\n') || 'None'}\n\n### Recommendations\n${review.recommendations.map(r => '- ' + r).join('\n') || 'None'}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
env:
REVIEW: ${{ steps.agent.outputs.review }}Verify it worked
Push the workflow file to your repository and open a pull request. The workflow should trigger, and you should see a comment from the bot within a minute or two.
Check the Actions tab for any failures. If the comment does not appear, look at the logs for the 'Post comment' step.
- Open a pull request in your repository and confirm the 'Dependency Review' workflow runs.
- Verify the bot comment appears with sections for vulnerabilities, outdated, license risks, and recommendations.
- Check the workflow logs for errors if the comment is missing.
Troubleshooting
Common issues include missing API keys, rate limits, and JSON parsing errors. Here are fixes for the most frequent problems.
If npm audit fails because of a lockfile mismatch, run npm install before collecting data. If license-checker fails, ensure you have a package-lock.json file.
- Error: 'OPENAI_API_KEY is not set' - Add the secret to your GitHub repository settings.
- Error: 'rate limit exceeded' - Wait a few seconds and retry, or use a different model.
- Error: 'Unexpected token' - Make sure deps.json exists and is valid JSON.
- Error: 'npm audit found vulnerabilities' - This is expected; the agent will report them.
Recommended setup
For a production setup, I recommend adding a severity filter so the agent only flags high and critical vulnerabilities. You can also schedule the agent to run weekly on the default branch to catch new issues even without a pull request.
Here is a starter configuration that combines both ideas. It uses a cron trigger and filters the audit data before sending it to the model.
name: Weekly Dependency Audit
on:
schedule:
- cron: '0 9 * * 1' # every Monday at 9am UTC
workflow_dispatch:
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- name: Collect and filter data
run: |
node collect.js
node filter.js
- name: Run AI agent
run: node agent.js
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}FAQ
Answers to the questions that come up most often on this topic.
- Q: Can I use this with Python dependencies? A: Yes, adapt the collection script to use pip-audit and pip-licenses.
- Q: How much does it cost to run? A: GPT-4o-mini is very cheap; each review costs less than a cent for typical projects.
- Q: Can I get alerts on Slack? A: Yes, add a step to send a message to a Slack webhook after the agent runs.
- Q: What if I have thousands of dependencies? A: You may hit token limits. Summarize the data or use a smaller model.
Try it on code.live
You can test your JSON output from the agent with the JSON Formatter on code.live to make it readable. For YAML workflow files, use the YAML Formatter to validate syntax.
Key takeaways
- Apply one concrete change from this post before collecting more reading.
- Prefer browser-side tools when the work involves secrets, tokens, or PII.
- Document the why next to the how so the next reviewer inherits context.
FAQ
- Who is this guide on ai-agent for?
- Working developers who need a practical take on build an ai agent that reviews your dependencies — not a marketing overview. Skim the sections, apply one tip, then come back when you hit an edge case.
- Do I need an account to use the related tools?
- No. code.live tools run in your browser with no signup. Nothing you paste is uploaded to a server for the client-side utilities linked from this post.
- How often is this article updated?
- This post was published November 12, 2026. Fundamentals stay stable; check linked tool pages and official docs when version-specific behavior matters.