221 lines
7.4 KiB
Markdown
221 lines
7.4 KiB
Markdown
# LangGraph Sysadmin AI Agents
|
||
|
||
This repository demonstrates two different approaches to building AI-powered system administration agents using LangGraph:
|
||
|
||
## <20> Two Approaches Available
|
||
|
||
### 1. Simple ReAct Agent (`simple-react-agent/`)
|
||
A straightforward [single-agent approach](https://langchain-ai.github.io/langgraph/agents/agents/#1-install-dependencies) using the ReAct (Reasoning and Acting) pattern for both local and remote system administration.
|
||
|
||
**Best for:**
|
||
- Learning LangGraph fundamentals
|
||
- System administration tasks (local and remote)
|
||
- Resource-constrained environments
|
||
- Quick prototyping
|
||
|
||
### 2. Multi-Agent Supervisor (`multi-agent-supervisor/`)
|
||
A sophisticated system with [multiple agents coordinated by a supervisor](https://langchain-ai.github.io/langgraph/agents/multi-agent/#supervisor) for comprehensive local and remote system management.
|
||
|
||
**Best for:**
|
||
- Complex system administration tasks
|
||
- Comprehensive multi-server system analysis
|
||
- Production environments
|
||
- When you need domain expertise
|
||
|
||
## 🤔 Which Approach Should You Choose?
|
||
|
||
| Factor | Simple ReAct | Multi-Agent Supervisor |
|
||
|--------|-------------|----------------------|
|
||
| **Complexity** | Low | High |
|
||
| **Setup Time** | Quick | More involved |
|
||
| **Resource Usage** | Light | Heavy |
|
||
| **Specialization** | General purpose | Domain experts |
|
||
| **Parallel Processing** | No | Yes |
|
||
| **Risk Assessment** | Basic | Advanced |
|
||
| **Debugging** | Easy | More complex |
|
||
| **Extensibility** | Limited | Highly extensible |
|
||
|
||
## 📊 Feature Comparison
|
||
|
||
### Simple ReAct Agent
|
||
```
|
||
✅ Single agent handles all tasks
|
||
✅ Easy to understand and debug
|
||
✅ Low resource usage
|
||
✅ Quick setup
|
||
✅ Interactive chat with streaming
|
||
❌ No specialization
|
||
❌ Sequential processing only
|
||
❌ Limited scaling for complex tasks
|
||
```
|
||
|
||
### Multi-Agent Supervisor
|
||
```
|
||
✅ Specialized domain experts
|
||
✅ Parallel processing
|
||
✅ Intelligent task delegation
|
||
✅ Risk assessment and severity scoring
|
||
✅ Comprehensive analysis
|
||
✅ Highly extensible
|
||
❌ More complex setup
|
||
❌ Higher resource usage
|
||
❌ Coordination overhead
|
||
```
|
||
|
||
## 🛠 Setup
|
||
|
||
Both approaches require the same base dependencies:
|
||
|
||
```bash
|
||
# Install dependencies
|
||
pip install langchain-openai langgraph langchain-community
|
||
|
||
# For multi-agent supervisor, also install:
|
||
pip install langgraph-supervisor
|
||
|
||
# Set your OpenAI API key
|
||
export OPENAI_API_KEY="your-api-key-here"
|
||
```
|
||
|
||
## 📁 Directory Structure
|
||
|
||
```
|
||
├── simple-react-agent/ # Single ReAct agent approach
|
||
│ ├── main.py # Main application
|
||
│ ├── custom_tools/ # Custom tools for the agent
|
||
│ └── README.md # Detailed documentation
|
||
│
|
||
├── multi-agent-supervisor/ # Multi-agent supervisor approach
|
||
│ ├── main-multi-agent.py # Multi-agent implementation
|
||
│ ├── agents/ # Specialized agent implementations
|
||
│ ├── custom_tools/ # Custom tools for agents
|
||
│ └── README.md # Detailed documentation
|
||
│
|
||
└── README.md # This file
|
||
```
|
||
|
||
## 🚀 Quick Start
|
||
|
||
### Try the Simple ReAct Agent
|
||
```bash
|
||
cd simple-react-agent
|
||
python main.py
|
||
```
|
||
|
||
### Try the Multi-Agent Supervisor
|
||
```bash
|
||
cd multi-agent-supervisor
|
||
python main-multi-agent.py
|
||
```
|
||
|
||
## 💡 Example Use Cases
|
||
|
||
### Simple ReAct Agent Examples
|
||
```
|
||
"Write me a motivational poem"
|
||
"Generate a tech poem about programming"
|
||
"Check disk usage on the system"
|
||
"Connect to my remote server and check CPU usage"
|
||
"List files in the current directory"
|
||
"SSH to my server and check if nginx is running"
|
||
"Show system information"
|
||
```
|
||
|
||
### Multi-Agent Supervisor Examples
|
||
```
|
||
"Perform a comprehensive system health check"
|
||
"Analyze system performance on my remote servers"
|
||
"Check for security vulnerabilities and suggest hardening"
|
||
"Monitor system resources and alert on issues"
|
||
"Compare performance between local and remote systems"
|
||
```
|
||
|
||
## 🔍 Decision Guide
|
||
|
||
**Choose Simple ReAct Agent if:**
|
||
- You're new to LangGraph
|
||
- You need basic system administration tasks (local or remote)
|
||
- You have limited computational resources
|
||
- You prefer simplicity and transparency
|
||
- You're building a proof of concept
|
||
|
||
**Choose Multi-Agent Supervisor if:**
|
||
- You need comprehensive system analysis across multiple servers
|
||
- You're working with multiple services and environments
|
||
- You want parallel processing
|
||
- You need risk assessment capabilities
|
||
- You're building a production system
|
||
- You want to leverage specialized expertise for complex remote operations
|
||
|
||
## 📚 Learning Path
|
||
|
||
1. **Start with Simple ReAct** to understand LangGraph basics
|
||
2. **Examine the code** to see how agents and tools work
|
||
3. **Try both approaches** with the same queries
|
||
4. **Compare the results** and execution patterns
|
||
5. **Choose your approach** based on your specific needs
|
||
|
||
## 🤝 Contributing
|
||
|
||
Feel free to:
|
||
- Add new specialized agents to the multi-agent system
|
||
- Enhance the system administration capabilities
|
||
- Add new tools for system management
|
||
- Improve error handling and reliability
|
||
- Add tests and documentation
|
||
|
||
## 📝 License
|
||
|
||
This project is for educational and demonstration purposes. Modify and use as needed for your projects.
|
||
|
||
---
|
||
|
||
**Happy system administration with AI! 🤖🔧**
|
||
|
||
## 📁 Project Structure
|
||
|
||
```
|
||
langgraph-pard0x/
|
||
├── simple-react-agent/ # Single ReAct agent approach
|
||
│ ├── main.py # Main application
|
||
│ ├── custom_tools/ # Custom tools for the agent
|
||
│ └── README.md # Detailed documentation
|
||
├── multi-agent-supervisor/ # Multi-agent supervisor approach
|
||
│ ├── main-multi-agent.py # Multi-agent implementation
|
||
│ ├── agents/ # Specialized agent implementations
|
||
│ ├── custom_tools/ # Custom tools for agents
|
||
│ └── README.md # Detailed documentation
|
||
├── pyproject.toml # Project dependencies
|
||
└── README.md # This file
|
||
```
|
||
|
||
## ⚠️ Safety Note
|
||
|
||
This agent has both local shell access and remote SSH access for system administration purposes. Use with caution and only in safe environments. The agents are designed to help with system diagnostics and administration, not to make unauthorized system modifications.
|
||
|
||
## Troubleshooting
|
||
|
||
### "Please set your OPENAI_API_KEY environment variable"
|
||
- Make sure you've set your OpenAI API key using one of the methods above
|
||
- Verify your API key is valid and active
|
||
|
||
### "Error initializing chatbot"
|
||
- Check your internet connection
|
||
- Verify your OpenAI API key has sufficient credits
|
||
- Make sure all dependencies are installed correctly
|
||
|
||
## 🤔 Open Questions
|
||
|
||
This project raises several interesting technical and architectural questions worth exploring:
|
||
|
||
### Conversation History Management
|
||
- **Should we pass [all the conversation history](https://www.reddit.com/r/LangChain/comments/1f3nqud/sending_the_entire_conversation_on_each_call_to/) to the LLM or not?**
|
||
|
||
|
||
### ReAct vs. Custom StateGraph
|
||
- **When to use LangGraph's [ReAct primitive](https://langchain-ai.github.io/langgraph/agents/overview/) vs. a custom StateGrap?**
|
||
- see [react_vs_custom.md](react_vs_custom.md) for a detailed comparison
|
||
|
||
### Tool Architecture Decisions
|
||
- **When to use LangChain [prebuilt tools and custom tools](https://langchain-ai.github.io/langgraph/agents/tools/#prebuilt-tools) vs. [MCP (Model Context Protocol) integrations](https://langchain-ai.github.io/langgraph/agents/mcp/)?**
|