This commit is contained in:
Gaetan Hurel 2025-06-30 16:55:41 +02:00
parent 228003bedc
commit 7e340a6649
No known key found for this signature in database

View File

@ -5,7 +5,7 @@ from langchain.chat_models import init_chat_model
from langchain_community.tools.shell.tool import ShellTool from langchain_community.tools.shell.tool import ShellTool
from langgraph.prebuilt import create_react_agent from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage from langchain_core.messages import HumanMessage
from custom_tools import print_poem, configured_remote_server from custom_tools import configured_remote_server
# Suppress the shell tool warning since we're using it intentionally for sysadmin tasks # Suppress the shell tool warning since we're using it intentionally for sysadmin tasks
warnings.filterwarnings("ignore", message="The shell tool has no safeguards by default. Use at your own risk.") warnings.filterwarnings("ignore", message="The shell tool has no safeguards by default. Use at your own risk.")
@ -17,11 +17,11 @@ def create_agent():
# Initialize the chat model (using OpenAI GPT-4) # Initialize the chat model (using OpenAI GPT-4)
# Make sure you have set your OPENAI_API_KEY environment variable # Make sure you have set your OPENAI_API_KEY environment variable
llm = init_chat_model("openai:gpt-4o-mini") llm = init_chat_model("openai:gpt-4.1")
# Define the tools available to the agent # Define the tools available to the agent
shell_tool = ShellTool() shell_tool = ShellTool()
tools = [shell_tool, configured_remote_server, print_poem] tools = [shell_tool, configured_remote_server]
# Create a ReAct agent with system administration debugging focus # Create a ReAct agent with system administration debugging focus
@ -36,12 +36,10 @@ def create_agent():
3. **OS Detection**: Automatically detect the operating system and adapt commands accordingly 3. **OS Detection**: Automatically detect the operating system and adapt commands accordingly
4. **Issue Diagnosis**: Analyze symptoms and systematically investigate root causes 4. **Issue Diagnosis**: Analyze symptoms and systematically investigate root causes
5. **Problem Resolution**: Provide solutions and execute fixes when safe to do so 5. **Problem Resolution**: Provide solutions and execute fixes when safe to do so
6. **Easter Egg**: Generate poems when users need a morale boost (use print_poem tool)
## AVAILABLE TOOLS ## AVAILABLE TOOLS
- **terminal**: Execute commands on the local machine - **terminal**: Execute commands on the local machine
- **configured_remote_server**: Execute commands on the pre-configured remote server - **configured_remote_server**: Execute commands on the pre-configured remote server
- **print_poem**: Generate motivational poems for debugging sessions
## OPERATING SYSTEM AWARENESS ## OPERATING SYSTEM AWARENESS
- **First interaction**: Always detect the OS using appropriate commands (uname, systeminfo, etc.) - **First interaction**: Always detect the OS using appropriate commands (uname, systeminfo, etc.)
@ -103,9 +101,7 @@ def create_agent():
- Pipe long outputs through 'head' or 'tail' when appropriate - Pipe long outputs through 'head' or 'tail' when appropriate
- Use 'timeout' command for potentially long-running diagnostics - Use 'timeout' command for potentially long-running diagnostics
- Always explain the output interpretation - Always explain the output interpretation
- Suggest next steps based on findings - 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 # Create the ReAct agent
@ -156,7 +152,6 @@ def main():
print(" - Analyze system logs and error messages") print(" - Analyze system logs and error messages")
print(" - Network connectivity diagnostics") print(" - Network connectivity diagnostics")
print(" - Cross-platform support (Linux, macOS, BSD, Windows)") print(" - Cross-platform support (Linux, macOS, BSD, Windows)")
print(" - 🎭 Easter egg: Generate motivational poems when you need a break!")
print("-" * 70) print("-" * 70)
# Create the agent # Create the agent
@ -167,7 +162,6 @@ def main():
print("💡 Or: 'Check if my web server is running properly'") print("💡 Or: 'Check if my web server is running properly'")
print("💡 Or: 'Connect to my remote server and check disk space'") print("💡 Or: 'Connect to my remote server and check disk space'")
print("💡 Or: 'Analyze recent system errors'") print("💡 Or: 'Analyze recent system errors'")
print("💡 Need a break? Ask: 'Write me a motivational poem'")
except Exception as e: except Exception as e:
print(f"❌ Error initializing agent: {e}") print(f"❌ Error initializing agent: {e}")
@ -197,8 +191,6 @@ def main():
print(" - 'Troubleshoot network connectivity problems'") print(" - 'Troubleshoot network connectivity problems'")
print(" - 'Check disk space and filesystem health'") print(" - 'Check disk space and filesystem health'")
print(" - 'Review recent system errors in logs'") 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("\nSafety Notes:")
print(" - Agent will ask permission before running potentially harmful commands") print(" - Agent will ask permission before running potentially harmful commands")
print(" - All commands are explained before execution") print(" - All commands are explained before execution")