2025-06-26 14:52:20 +02:00

2.8 KiB

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
  • log_analyzer.py: Specialized tool for analyzing log files
  • loghub/: Symbolic link to log files directory

Tools Available

  1. Shell Tool: Execute system commands

    • System monitoring (top, ps, df, etc.)
    • File operations
    • Network diagnostics
  2. Log Analyzer Tool: Analyze log files with different modes:

    • error_patterns: Find and categorize error messages
    • frequency: Analyze frequency of different log patterns
    • timeline: Show chronological patterns of events
    • summary: 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"