2025-06-27 09:38:55 +02:00

97 lines
2.8 KiB
Markdown

# Simple ReAct Agent for Log Analysis
This directory contains a simple ReAct (Reasoning and Acting) agent implementation for log analysis and system administration tasks.
## Overview
The simple ReAct agent follows a straightforward pattern:
1. **Receives** user input
2. **Reasons** about what tools to use
3. **Acts** by executing tools when needed
4. **Responds** with the final result
## Features
- **Single Agent**: One agent handles all tasks
- **Shell Access**: Execute system commands safely
- **Log Analysis**: Specialized log analysis capabilities
- **Interactive Chat**: Stream responses with tool usage visibility
- **Conversation History**: Maintains context across interactions
## Architecture
```
User Input → ReAct Agent → Tools (Shell + Log Analyzer) → Response
```
## Files
- `main.py`: Main application with ReAct agent implementation
- `custom_tools/`: Directory containing custom tools (poem generation tool)
## Tools Available
1. **Shell Tool**: Execute system commands
- System monitoring (`top`, `ps`, `df`, etc.)
- File operations
- Network diagnostics
2. **Poem Tool**: Generate beautiful poems with different themes:
- `nature`: Poems about nature and the environment
- `tech`: Poems about technology and programming
- `motivational`: Inspirational and motivational poems
- `friendship`: Poems about friendship and relationships
- `random`: Randomly selects from any available poem type
## Usage
```bash
cd simple-react-agent
python main.py
```
### Example Interactions
```
User: Analyze the Apache logs for error patterns
Agent: 🔧 Using tool: analyze_log_file
Args: {'file_path': 'Apache/Apache_2k.log', 'analysis_type': 'error_patterns'}
📋 Tool result: Found 15 error patterns in Apache logs...
User: Check disk usage on the system
Agent: 🔧 Using tool: shell
Args: {'command': 'df -h'}
📋 Tool result: Filesystem usage information...
```
## Pros and Cons
### ✅ Pros
- **Simple to understand**: Single agent, clear flow
- **Easy to debug**: Linear execution path
- **Quick setup**: Minimal configuration required
- **Resource efficient**: Lower computational overhead
- **Good for**: Simple tasks, learning, rapid prototyping
### ❌ Cons
- **Limited specialization**: One agent handles everything
- **No parallel processing**: Sequential tool execution
- **Scaling challenges**: Complex tasks may overwhelm single agent
- **Less sophisticated**: No coordination between specialized experts
## When to Use
Choose the simple ReAct agent when:
- You need a straightforward log analysis tool
- Your use cases are relatively simple
- You want to understand LangGraph basics
- Resource usage is a concern
- You prefer simplicity over sophistication
## Requirements
```bash
pip install langchain-openai langgraph langchain-community
export OPENAI_API_KEY="your-api-key"
```