2025-06-29 15:15:27 +02:00

3.6 KiB

Simple ReAct Agent for System Administration

This directory contains a simple ReAct (Reasoning and Acting) agent implementation for system administration, log analysis, and remote server management 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 (locally or remotely)
  4. Responds with the final result

Features

  • Single Agent: One agent handles all tasks
  • Local Shell Access: Execute system commands on the local machine
  • Remote SSH Access: Execute commands on remote servers via persistent SSH connections
  • System Administration: Comprehensive system diagnostics and management
  • 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 + SSH + Tools) → 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 on the local machine

    • System monitoring (top, ps, df, etc.)
    • File operations
    • Network diagnostics
  2. SSH Tool: Execute commands on remote servers

    • Persistent SSH connections
    • Remote system administration
    • Cross-platform remote diagnostics
    • Secure remote command execution
  3. 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

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...

User: Connect to my remote server and check CPU usage
Agent: 🔧 Using tool: configured_ssh_tool
       Args: {'command': 'top -bn1 | head -20'}
       📋 Tool result: Remote server CPU and process 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 system administration tool
  • You want both local and remote server management capabilities
  • Your use cases are relatively simple
  • You want to understand LangGraph basics
  • Resource usage is a concern
  • You prefer simplicity over sophisticated multi-agent coordination

Requirements

pip install langchain-openai langgraph langchain-community
export OPENAI_API_KEY="your-api-key"