From 533bac97fd8b4982ecfef88f2f5c075a4160a174 Mon Sep 17 00:00:00 2001 From: Gaetan Hurel Date: Fri, 27 Jun 2025 09:54:53 +0200 Subject: [PATCH] improve mono agent prompt --- simple-react-agent/main.py | 137 +++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 35 deletions(-) diff --git a/simple-react-agent/main.py b/simple-react-agent/main.py index e83b3b7..e882fca 100644 --- a/simple-react-agent/main.py +++ b/simple-react-agent/main.py @@ -7,7 +7,7 @@ from custom_tools.poem_tool import print_poem def create_agent(): - """Create and return a ReAct agent with shell and poem capabilities.""" + """Create and return a ReAct agent specialized for system administration and debugging.""" # Initialize the chat model (using OpenAI GPT-4) # Make sure you have set your OPENAI_API_KEY environment variable @@ -18,27 +18,82 @@ def create_agent(): tools = [shell_tool, print_poem] - # Create a ReAct agent with simplified system prompt - system_prompt = """You are a helpful assistant with access to shell commands and poem generation capabilities. + # Create a ReAct agent with system administration debugging focus + system_prompt = """You are an expert system administrator debugging agent with deep knowledge of Linux, macOS, BSD, and Windows systems. + + ## PRIMARY MISSION + Help sysadmins diagnose, troubleshoot, and resolve system issues efficiently. You have access to shell commands and can execute diagnostic procedures to identify and fix problems. + + ## CORE CAPABILITIES + 1. **System Analysis**: Execute shell commands to gather system information and diagnostics + 2. **OS Detection**: Automatically detect the operating system and adapt commands accordingly + 3. **Issue Diagnosis**: Analyze symptoms and systematically investigate root causes + 4. **Problem Resolution**: Provide solutions and execute fixes when safe to do so + 5. **Easter Egg**: Generate poems when users need a morale boost (use print_poem tool) + + ## OPERATING SYSTEM AWARENESS + - **First interaction**: Always detect the OS using appropriate commands (uname, systeminfo, etc.) + - **Command adaptation**: Use OS-specific commands and syntax + - **Cross-platform knowledge**: Understand differences between Linux/Unix, macOS, BSD, and Windows + - **Session memory**: Remember the detected OS throughout the conversation + + ## SAFETY PROTOCOLS + 1. **Read-only first**: Always start with non-destructive diagnostic commands + 2. **Explain before executing**: Describe what each command does and why it's needed + 3. **Confirmation for risky commands**: Ask for explicit permission before running potentially harmful commands + 4. **Dangerous command examples**: rm, mkfs, dd, shutdown, reboot, chmod 777, deleting system files + 5. **Safe command examples**: ps, top, df, free, netstat, ss, journalctl, tail, cat, ls + + ## DIAGNOSTIC WORKFLOWS + ### Performance Issues + 1. Check system resources (CPU, memory, disk, network) + 2. Identify resource-hungry processes + 3. Analyze system load and bottlenecks + 4. Check for hardware issues - You can: - 1. Execute shell commands using the shell tool to interact with the system - 2. Generate and print beautiful poems using the print_poem tool + ### Service Issues + 1. Check service status and logs + 2. Verify dependencies and prerequisites + 3. Test connectivity and permissions + 4. Analyze configuration files - The poem tool can create different types of poems: - - "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 + ### Network Issues + 1. Test basic connectivity (ping, traceroute) + 2. Check DNS resolution + 3. Verify network interfaces and routing + 4. Analyze firewall rules and port accessibility - When helping users: - - Be friendly and helpful - - Use appropriate tools based on the user's request - - Always be cautious with shell commands and explain what they do - - For system monitoring commands like 'top', 'ps', etc., use appropriate flags to avoid hanging - - When users ask for poems or want to brighten their day, use the poem tool - """ + ### System Stability + 1. Check system logs for errors + 2. Verify disk space and filesystem health + 3. Monitor system temperature and hardware status + 4. Check for memory leaks or corruption + + ## RESPONSE METHODOLOGY + 1. **Listen carefully**: Understand the user's problem description + 2. **Probe systematically**: Ask clarifying questions if needed + 3. **Detect environment**: Identify OS and system characteristics + 4. **Execute diagnostics**: Run appropriate commands with explanations + 5. **Interpret results**: Analyze command outputs and explain findings + 6. **Provide solutions**: Suggest fixes and implement them safely + 7. **Follow up**: Verify fixes worked and suggest preventive measures + + ## COMMUNICATION STYLE + - Be professional but friendly + - Explain technical concepts clearly + - Always explain what commands do before running them + - Provide context for why specific diagnostics are needed + - Offer multiple solutions when possible + - Be patient with follow-up questions + + ## COMMAND EXECUTION GUIDELINES + - Use appropriate flags to avoid hanging (e.g., 'top -n 1', 'ps aux') + - Pipe long outputs through 'head' or 'tail' when appropriate + - Use 'timeout' command for potentially long-running diagnostics + - Always explain the output interpretation + - Suggest next steps based on findings + + Remember: Your primary goal is to help solve system problems efficiently and safely. The poem tool is just a nice bonus for when users need encouragement during stressful debugging sessions!""" # Create the ReAct agent @@ -76,23 +131,28 @@ def main(): print("You can set it by running: export OPENAI_API_KEY='your-api-key-here'") return - print("šŸ¤– LangGraph Simple Demo Agent") + print("šŸ”§ SysAdmin Debugging Agent - Powered by LangGraph") print("Type 'quit', 'exit', or 'q' to exit the chat.") print("Type 'help' or 'h' for help and examples.") print("Type 'clear' or 'reset' to clear conversation history.") print("āš ļø WARNING: This agent has shell access - use with caution!") - print("šŸŽ­ Available capabilities:") - print(" - Generate beautiful poems for any occasion") - print(" - Execute shell commands for system tasks") - print(" - Help with general assistance") - print("-" * 60) + print("šŸ› ļø System Administration Capabilities:") + print(" - Diagnose performance issues (CPU, memory, disk, network)") + print(" - Troubleshoot service and daemon problems") + print(" - Analyze system logs and error messages") + print(" - Network connectivity diagnostics") + print(" - Cross-platform support (Linux, macOS, BSD, Windows)") + print(" - šŸŽ­ Easter egg: Generate motivational poems when you need a break!") + print("-" * 70) # Create the agent try: agent = create_agent() - print("āœ… Simple Demo Agent initialized successfully!") - print("šŸ’” Try asking: 'Write me a nature poem'") - print("šŸ’” Or: 'Show me the current directory'") + print("āœ… SysAdmin Debugging Agent initialized successfully!") + print("šŸ’” Try asking: 'My system is running slow, can you help?'") + print("šŸ’” Or: 'Check if my web server is running properly'") + print("šŸ’” Or: 'Analyze recent system errors'") + print("šŸ’” Need a break? Ask: 'Write me a motivational poem'") except Exception as e: print(f"āŒ Error initializing agent: {e}") @@ -108,17 +168,24 @@ def main(): print("šŸ‘‹ Goodbye!") break elif user_input.lower() in ["help", "h"]: - print("\nšŸ†˜ Help:") + print("\nšŸ†˜ Help - SysAdmin Debugging Agent:") print("Commands:") print(" - quit/exit/q: Exit the agent") print(" - help/h: Show this help") print(" - clear/reset: Clear conversation history") - print("\nExample queries:") - print(" - 'Write me a motivational poem'") - print(" - 'Generate a tech poem'") - print(" - 'Show me a random poem'") - print(" - 'List files in current directory'") - print(" - 'Check disk usage on the system'") + print("\nSystem Debugging Examples:") + print(" - 'My server is running slow, help me diagnose the issue'") + print(" - 'Check why my Apache/Nginx service won't start'") + print(" - 'Analyze high CPU usage on this system'") + print(" - 'Troubleshoot network connectivity problems'") + print(" - 'Check disk space and filesystem health'") + print(" - 'Review recent system errors in logs'") + print("\nEaster Egg:") + print(" - 'Write me a motivational poem' (for when debugging gets tough!)") + print("\nSafety Notes:") + print(" - Agent will ask permission before running potentially harmful commands") + print(" - All commands are explained before execution") + print(" - Diagnostic commands are prioritized over destructive ones") continue elif user_input.lower() in ["clear", "reset"]: conversation_history = []