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:
- Receives user input
- Reasons about what tools to use
- Acts by executing tools when needed
- 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 implementationlog_analyzer.py
: Specialized tool for analyzing log filesloghub/
: Symbolic link to log files directory
Tools Available
-
Shell Tool: Execute system commands
- System monitoring (
top
,ps
,df
, etc.) - File operations
- Network diagnostics
- System monitoring (
-
Log Analyzer Tool: Analyze log files with different modes:
error_patterns
: Find and categorize error messagesfrequency
: Analyze frequency of different log patternstimeline
: Show chronological patterns of eventssummary
: Provide an overall summary of the log file
Usage
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
pip install langchain-openai langgraph langchain-community
export OPENAI_API_KEY="your-api-key"