A multi-agent Python system that uses LangChain's tool calling pattern to automatically update dependencies with intelligent testing and rollback capabilities. It analyzes repositories, updates dependencies, tests the changes, rolls back breaking updates, and creates Pull Requests or Issues automatically.
- π€ Fully Automated Updates: End-to-end automation from analysis to PR creation
- π§ͺ Intelligent Testing: Automatically runs build/test commands to verify updates
- π Smart Rollback: Identifies breaking changes and rolls back only problematic major updates
- β Auto PR Creation: Creates GitHub Pull Requests with successful updates
- π΄ Auto Issue Creation: Creates GitHub Issues when updates can't be applied safely
- π Multi-Agent Architecture: Orchestrator pattern with specialized sub-agents
- π§ AI-Powered Analysis: Uses Claude to analyze errors and identify problematic dependencies
Detects and updates dependencies for:
- JavaScript/Node.js (npm, yarn, pnpm)
- Python (pip, pipenv, poetry)
- Rust (cargo)
- Ruby (bundler)
- Java (Maven, Gradle)
- PHP (Composer)
- Go (go modules)
- Automatic Build Detection: Detects how to build, test, and verify your project
- Error Analysis: AI-powered parsing of error messages to identify culprits
- Iterative Rollback: Tries to salvage as many updates as possible
- Version Categorization: Categorizes updates as major/minor/patch
- Comprehensive Reporting: Detailed PR descriptions with what was updated and why
This project implements a multi-agent system following the LangChain Tool Calling pattern:
auto_update_dependencies.py (Main Orchestrator)
βββ dependency_analyzer.py (Analysis Agent)
β βββ Tools: clone, detect, check outdated
βββ smart_dependency_updater.py (Smart Update Agent)
β βββ Tools: detect build, test, write files, git ops
β βββ Sub-tools: apply updates, rollback, parse errors
βββ dependency_operations.py (Helper Tools)
βββ Tools: categorize, version lookup, error analysis
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INPUT: Repository URL β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 1: ANALYZE REPOSITORY β
β β’ Clone repository β
β β’ Detect package manager β
β β’ Find outdated dependencies β
β β’ Categorize: major/minor/patch β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 2: APPLY ALL UPDATES β
β β’ Update ALL dependencies to latest β
β β’ Including major version updates β
β β’ Write updated dependency files β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 3: TEST UPDATES β
β β’ Run install command β
β β’ Run build command β
β β’ Run test command β
β β’ Capture all output β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βββββββββββ΄ββββββββββ
β β
Tests Pass? Tests Fail?
β β
βΌ βΌ
ββββββββββββββββββ ββββββββββββββββββββββββββββββ
β CREATE PR β β ANALYZE ERROR β
β β β β’ Use AI to parse errors β
β β’ Git branch β β β’ Identify problematic pkg β
β β’ Commit β βββββββββββββ¬βββββββββββββββββ
β β’ Push β β
β β’ gh pr create β βΌ
ββββββββββ¬ββββββββ ββββββββββββββββββββββββββββββ
β β ROLLBACK MAJOR UPDATE β
β β β’ Find latest in major ver β
β β β’ Update dependency file β
β β β’ Write file β
β βββββββββββββ¬βββββββββββββββββ
β β
β βΌ
β ββββββββββββββββββββββββββββββ
β β TEST AGAIN (Max 3x) β
β βββββ¬βββββββββββββββββββ¬ββββββ
β β β
β Now Pass? Still Fail?
β β β
β ββββββββ ββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββ ββββββββββββββββββββββββββββ
β SUCCESS! β β CREATE ISSUE β
β PR Created β β β’ Document what failed β
β β β β’ Include error logs β
β Output: β β β’ Tag: dependencies β
β β’ PR URL β β β
β β’ Summary β β Output: β
β β’ Rollbacks β β β’ Issue URL β
ββββββββββββββββββ β β’ Failure details β
ββββββββββββββββββββββββββββ
Main coordinator (auto_update_dependencies.py) that manages the complete workflow:
- Receives repository URL or name
- Checks prerequisites (Docker, GitHub token)
- Orchestrates analysis and update agents
- Manages end-to-end automated updates with PR/Issue creation
Functions:
analyze_repository()- Invokes the analyzer agentsmart_update_and_test()- Invokes the smart updater agent- Docker and GitHub token validation
Specialized in finding outdated dependencies (dependency_analyzer.py):
- Clones repositories
- Detects package managers
- Identifies outdated packages
- Returns structured analysis reports
Tools:
clone_repository- Clones git repos to temp directoriesdetect_package_manager- Identifies package managers and config filesread_dependency_file- Reads dependency configuration filescheck_npm_outdated- Checks outdated npm packagescheck_pip_outdated- Checks outdated Python packages (via PyPI API)cleanup_repository- Removes temporary files
Specialized in updating with intelligent testing and rollback (smart_dependency_updater.py):
- Applies dependency updates
- Runs build and test commands
- Automatically rolls back breaking changes
- Creates GitHub PRs on success
- Creates GitHub Issues on failure
Tools:
detect_build_command- Auto-detects build/test commandsapply_updates- Updates dependency filestest_updates- Runs build/test commandsrollback_major_update- Rolls back problematic updatescreate_github_pr- Creates PRs using MCPcreate_github_issue- Creates issues using MCPparse_error_for_dependency- AI-powered error analysis
Utility functions for dependency manipulation (dependency_operations.py):
- Applies updates to various dependency file formats
- Rolls back specific package updates
- Categorizes updates (major/minor/patch)
- Finds latest versions within major releases
Functions:
apply_all_updates()- Applies all updates to dependency filesrollback_major_update()- Rolls back specific package versionsparse_error_for_dependency()- AI analysis of build errorscategorize_updates()- Categorizes updates by typeget_latest_version_for_major()- Finds latest version in major release
- Python 3.8 or higher
- Git
- Node.js and npm (for checking npm packages)
- pip (for checking Python packages)
- Other package managers as needed (cargo, go, etc.)
- Clone this repository:
git clone https://github.com/codeWithUtkarsh/AiAgentToolCalling.git
cd AiAgentToolCalling- Install Python dependencies:
pip install -r requirements.txt- Set up your Anthropic API key:
export ANTHROPIC_API_KEY='your-api-key-here'Or create a .env file (copy from .env.example):
cp .env.example .env
# Edit .env and add your API keyThe system uses GitHub MCP (Model Context Protocol) to create Pull Requests and Issues automatically.
-
Container Runtime (Docker, OrbStack, Podman, etc.)
- macOS: Install OrbStack (recommended) or Docker Desktop
- Windows/Linux: Install Docker Desktop
-
GitHub Personal Access Token
- Create at: https://github.com/settings/tokens
- Required scopes:
repo,workflow
1. Install Container Runtime (if not already installed)
macOS (choose one):
# Option 1: OrbStack (recommended - lightweight and fast)
brew install orbstack
# Option 2: Docker Desktop
# Download from https://www.docker.com/products/docker-desktop2. Fix PATH for macOS/OrbStack Users
If you're on macOS and encounter "docker: command not found" errors in Python:
# Add to your shell configuration
echo 'export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcFor bash users:
echo 'export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile3. Set GitHub Token
export GITHUB_PERSONAL_ACCESS_TOKEN='your_github_token_here'To make it permanent:
# For zsh (macOS default)
echo 'export GITHUB_PERSONAL_ACCESS_TOKEN="your_token"' >> ~/.zshrc
source ~/.zshrc
# For bash
echo 'export GITHUB_PERSONAL_ACCESS_TOKEN="your_token"' >> ~/.bash_profile
source ~/.bash_profile4. Verify Setup
Test your GitHub MCP setup:
python diagnose_github_mcp.pyExpected output:
β
Container runtime: PASS
β
GitHub token: PASS
β
MCP connection: PASS
β
MCP tool call: PASS
If any tests fail, the diagnostic tool will show specific instructions to fix the issue.
The system automatically detects and works with:
- Docker Desktop - Official Docker
- OrbStack - Lightweight Docker alternative for macOS
- Podman Desktop - Daemonless container engine
- Rancher Desktop - Kubernetes + containers
No configuration needed - it auto-detects which one you have installed!
The fully automated system that updates dependencies, tests them, and creates PRs:
python auto_update_dependencies.py <repository>Examples:
# Using full URL
python auto_update_dependencies.py https://github.com/expressjs/express
# Using owner/repo format
python auto_update_dependencies.py expressjs/expressWhat it does:
- π Clones and analyzes your repository
- π Updates all dependencies to latest (including major versions)
- π§ͺ Runs build and test commands
- π If tests fail: identifies problematic packages and rolls back major updates
- β Creates a Pull Request if successful
- π΄ Creates an Issue if updates can't be applied safely
Prerequisites:
- Docker installed and running:
docker --version - GitHub Personal Access Token set:
export GITHUB_PERSONAL_ACCESS_TOKEN='your_token' - Git push access to the repository
- Package manager tools installed (npm, pip, cargo, etc.)
Repository: myapp (Node.js project)
π Analysis found 10 outdated packages:
- express: 4.17.0 β 5.0.0 (MAJOR)
- lodash: 4.17.20 β 4.17.21 (PATCH)
- react: 17.0.0 β 18.2.0 (MAJOR)
- axios: 0.21.0 β 1.6.0 (MAJOR)
... 6 more
π Applying all updates...
β
Updated package.json
π§ͺ Testing updates...
β npm test failed
π Analyzing error...
Identified: React 18 breaking change in test utilities
π Rolling back React 18 β 17...
Finding latest React 17.x: 17.0.2
β
Rolled back to react@17.0.2
π§ͺ Testing again...
β
npm install - success
β
npm run build - success
β
npm test - success
β
Creating Pull Request...
Branch: deps/auto-update-20250126
PR: https://github.com/owner/myapp/pull/123
RESULT:
β
Successfully updated 10 dependencies!
- Applied 9 updates to latest versions
- Rolled back React 18.2.0 β 17.0.2 (breaking changes)
- All tests passing
π PR Summary:
- express 4.17.0 β 5.0.0 β
- lodash 4.17.20 β 4.17.21 β
- react 17.0.0 β 17.0.2 (rolled back from 18.2.0)
- axios 0.21.0 β 1.6.0 β
- ... 6 more β
Repository: legacy-app (Python project)
π Analysis found 5 outdated packages:
- django: 2.2 β 4.2 (MAJOR)
- requests: 2.25.0 β 2.31.0 (MINOR)
... 3 more
π Applying all updates...
β
Updated requirements.txt
π§ͺ Testing updates...
β pytest failed
π Analyzing error...
Identified: Django 4.x breaking changes in models
π Rolling back Django 4.2 β 2.2...
Finding latest Django 2.x: 2.2.28
β
Rolled back to Django 2.2.28
π§ͺ Testing again...
β pytest still failing
π Analyzing error...
Identified: Compatibility issues with Python version
π΄ Cannot apply updates safely
π Creating Issue...
Issue: https://github.com/owner/legacy-app/issues/45
RESULT:
β Updates could not be applied safely
Issue created with details:
- Attempted updates to 5 packages
- Django major update causes breaking changes
- Python version compatibility issues detected
- Manual review and migration needed
================================================================================
π€ Dependency Update Agent
================================================================================
π¦ Repository: expressjs/express
π URL: https://github.com/expressjs/express
π Running dependency analyzer on https://github.com/expressjs/express...
> Entering new AgentExecutor chain...
Cloning repository...
Repository cloned successfully
Detecting package managers...
Found: npm (package.json)
Checking outdated packages...
Found 8 outdated npm packages
================================================================================
β
FINAL REPORT
================================================================================
# π Dependency Updates for expressjs/express
## π¦ Updated Dependencies
### β οΈ Major Updates
- π΄ **body-parser**: `1.19.0` β `2.0.0` (MAJOR - may have breaking changes)
### Minor Updates
- π‘ **cookie**: `0.4.1` β `0.5.0` (minor)
- π‘ **debug**: `2.6.9` β `2.7.0` (minor)
### Patch Updates
- π’ **accepts**: `1.3.7` β `1.3.8` (patch)
- π’ **etag**: `1.8.1` β `1.8.2` (patch)
## π§ͺ Testing Instructions
Please run the following commands to verify the updates:
```bash
# Install dependencies
npm install
# Run tests
npm test
# Run build
npm run build
# Check for issues
npm run lint
β οΈ This PR includes MAJOR version updates- Review changelogs for breaking changes
- Run the full test suite before merging
- Check for deprecation warnings
- Verify build succeeds
- Review any peer dependency warnings
π Total dependencies updated: 8 π€ This PR was generated by the Dependency Update Agent
## π Workflow
The orchestrator agent follows this workflow:
1. **Analyze Dependencies**
- Clone the repository
- Detect package managers
- Identify outdated dependencies
- Generate analysis report
2. **Update Dependency Files**
- Read current dependency files
- Update version numbers
- Preserve file formatting
- Determine testing strategy
3. **Create PR Description**
- Categorize updates (major/minor/patch)
- Add testing instructions
- Include warnings for breaking changes
- Provide checklist
4. **Report Results**
- Summary of updates
- PR description ready to use
- Next steps for the user
## π οΈ Extending the System
### Adding New Package Manager Support
1. **Update `dependency_analyzer.py`:**
Add detection in `detect_package_manager` tool:
```python
if os.path.exists(os.path.join(repo_path, "your-config-file")):
package_managers["your-pm"] = {
"files": ["your-config-file"],
"lock_files": []
}
Create a checking tool:
@tool
def check_yourpm_outdated(repo_path: str) -> str:
"""Check for outdated packages in your package manager."""
# Implementation here
pass- Update
dependency_operations.py:
Add update logic:
def apply_yourpm_updates(file_path: str, updates: list) -> bool:
"""Update your package manager config file."""
# Implementation here
pass- Update
smart_dependency_updater.py:
Add testing strategy in detect_build_command tool:
# Add detection for your package manager
if package_manager == "your-pm":
return {
"install": "your-pm install",
"build": "your-pm build",
"test": "your-pm test"
}User Input (repo URL)
β
Auto Update Orchestrator (auto_update_dependencies.py)
β
ββ Check Prerequisites (Docker, GitHub Token)
β
βββ Dependency Analyzer Agent
β βββ clone_repository
β βββ detect_package_manager
β βββ check_npm_outdated / check_pip_outdated
β βββ cleanup_repository
β β
β Returns: Analysis Report (outdated packages)
β
βββ Smart Dependency Updater Agent
β βββ detect_build_command (auto-detect test commands)
β βββ apply_updates (update dependency files)
β βββ test_updates (run build/test)
β ββ If tests fail:
β β βββ parse_error_for_dependency (AI error analysis)
β β βββ rollback_major_update (rollback problematic package)
β β βββ test_updates (retry, max 3 attempts)
β ββ If tests pass:
β β βββ create_github_pr (via Docker MCP)
β ββ If tests still fail after rollbacks:
β β βββ create_github_issue (via Docker MCP)
β β
β Returns: PR URL or Issue URL
β
Returns to User: Success (PR created) or Failure (Issue created)
The system currently uses Anthropic's Claude, but you can switch to OpenAI:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4-turbo-preview", temperature=0)Update all three agent files and set your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'The system includes smart caching to improve performance and reduce API calls:
- Repository Caching: Cloned repositories are cached locally to avoid re-cloning
- Analysis Caching: Dependency analysis results are cached
- Outdated Package Caching: Results from package registry checks are cached
- TTL-Based Expiration: Cache expires after a configurable time period
Set cache expiry time in hours via environment variable:
# Set in .env file or export
CACHE_EXPIRY_HOURS=24 # Default: 24 hoursCache is stored at: ~/.cache/ai-dependency-updater/
# View cache statistics
python repository_cache.py stats
# Clean up expired cache entries
python repository_cache.py cleanup
# Clear all cache
python repository_cache.py clear- β‘ Faster repeated analyses - No need to re-clone repositories
- π° Reduced API calls - Cached package registry lookups
- π Works offline - Can analyze previously cached repositories
- π Smart invalidation - Automatic expiration based on TTL
- Some package managers require additional tools (e.g.,
cargo-outdatedfor Rust) - Large repositories may take time to clone and analyze (first time only, then cached)
- Some checks require the package manager to be installed locally
- Network connectivity required for cloning and checking updates (unless using cache)
- Requires container runtime (Docker/OrbStack/Podman) for GitHub MCP integration
- Automatically creates PRs on success and Issues when updates fail
python auto_update_dependencies.py facebook/reactpython auto_update_dependencies.py https://github.com/pallets/flaskpython dependency_analyzer.py https://github.com/rust-lang/cargoContributions are welcome! Areas for improvement:
- Add more package manager support
- Implement actual GitHub PR creation
- Add support for monorepos
- Improve version parsing and semver handling
- Add caching for faster repeated analyses
- Create a web interface
Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
- LangChain Tool Calling Blog Post
- LangChain Documentation
- LangChain Agents
- Anthropic Claude API
- Multi-Agent Systems
Make sure all dependencies are installed:
pip install -r requirements.txtEnsure your Anthropic API key is set:
export ANTHROPIC_API_KEY='your-key-here'Install the required package managers:
- npm: Install Node.js from https://nodejs.org/
- pip: Included with Python 3
- Check your internet connection
- Ensure you have git installed
- Verify the repository URL is correct and public
Built with β€οΈ using LangChain and Claude