improve mono agent prompt

This commit is contained in:
Gaetan Hurel 2025-06-27 09:54:53 +02:00
parent 2029b8d462
commit 533bac97fd
No known key found for this signature in database

View File

@ -7,7 +7,7 @@ from custom_tools.poem_tool import print_poem
def create_agent(): 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) # 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
@ -18,27 +18,82 @@ def create_agent():
tools = [shell_tool, print_poem] tools = [shell_tool, print_poem]
# Create a ReAct agent with simplified system prompt # Create a ReAct agent with system administration debugging focus
system_prompt = """You are a helpful assistant with access to shell commands and poem generation capabilities. system_prompt = """You are an expert system administrator debugging agent with deep knowledge of Linux, macOS, BSD, and Windows systems.
You can: ## PRIMARY MISSION
1. Execute shell commands using the shell tool to interact with the system 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.
2. Generate and print beautiful poems using the print_poem tool
The poem tool can create different types of poems: ## CORE CAPABILITIES
- "nature": Poems about nature and the environment 1. **System Analysis**: Execute shell commands to gather system information and diagnostics
- "tech": Poems about technology and programming 2. **OS Detection**: Automatically detect the operating system and adapt commands accordingly
- "motivational": Inspirational and motivational poems 3. **Issue Diagnosis**: Analyze symptoms and systematically investigate root causes
- "friendship": Poems about friendship and relationships 4. **Problem Resolution**: Provide solutions and execute fixes when safe to do so
- "random": Randomly selects from any available poem type 5. **Easter Egg**: Generate poems when users need a morale boost (use print_poem tool)
When helping users: ## OPERATING SYSTEM AWARENESS
- Be friendly and helpful - **First interaction**: Always detect the OS using appropriate commands (uname, systeminfo, etc.)
- Use appropriate tools based on the user's request - **Command adaptation**: Use OS-specific commands and syntax
- Always be cautious with shell commands and explain what they do - **Cross-platform knowledge**: Understand differences between Linux/Unix, macOS, BSD, and Windows
- For system monitoring commands like 'top', 'ps', etc., use appropriate flags to avoid hanging - **Session memory**: Remember the detected OS throughout the conversation
- When users ask for poems or want to brighten their day, use the poem tool
""" ## 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
### Service Issues
1. Check service status and logs
2. Verify dependencies and prerequisites
3. Test connectivity and permissions
4. Analyze configuration files
### 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
### 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 # 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'") print("You can set it by running: export OPENAI_API_KEY='your-api-key-here'")
return 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 'quit', 'exit', or 'q' to exit the chat.")
print("Type 'help' or 'h' for help and examples.") print("Type 'help' or 'h' for help and examples.")
print("Type 'clear' or 'reset' to clear conversation history.") print("Type 'clear' or 'reset' to clear conversation history.")
print("⚠️ WARNING: This agent has shell access - use with caution!") print("⚠️ WARNING: This agent has shell access - use with caution!")
print("🎭 Available capabilities:") print("🛠️ System Administration Capabilities:")
print(" - Generate beautiful poems for any occasion") print(" - Diagnose performance issues (CPU, memory, disk, network)")
print(" - Execute shell commands for system tasks") print(" - Troubleshoot service and daemon problems")
print(" - Help with general assistance") print(" - Analyze system logs and error messages")
print("-" * 60) 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 # Create the agent
try: try:
agent = create_agent() agent = create_agent()
print("✅ Simple Demo Agent initialized successfully!") print("✅ SysAdmin Debugging Agent initialized successfully!")
print("💡 Try asking: 'Write me a nature poem'") print("💡 Try asking: 'My system is running slow, can you help?'")
print("💡 Or: 'Show me the current directory'") 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: except Exception as e:
print(f"❌ Error initializing agent: {e}") print(f"❌ Error initializing agent: {e}")
@ -108,17 +168,24 @@ def main():
print("👋 Goodbye!") print("👋 Goodbye!")
break break
elif user_input.lower() in ["help", "h"]: elif user_input.lower() in ["help", "h"]:
print("\n🆘 Help:") print("\n🆘 Help - SysAdmin Debugging Agent:")
print("Commands:") print("Commands:")
print(" - quit/exit/q: Exit the agent") print(" - quit/exit/q: Exit the agent")
print(" - help/h: Show this help") print(" - help/h: Show this help")
print(" - clear/reset: Clear conversation history") print(" - clear/reset: Clear conversation history")
print("\nExample queries:") print("\nSystem Debugging Examples:")
print(" - 'Write me a motivational poem'") print(" - 'My server is running slow, help me diagnose the issue'")
print(" - 'Generate a tech poem'") print(" - 'Check why my Apache/Nginx service won't start'")
print(" - 'Show me a random poem'") print(" - 'Analyze high CPU usage on this system'")
print(" - 'List files in current directory'") print(" - 'Troubleshoot network connectivity problems'")
print(" - 'Check disk usage on the system'") 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 continue
elif user_input.lower() in ["clear", "reset"]: elif user_input.lower() in ["clear", "reset"]:
conversation_history = [] conversation_history = []