Spaces:
Sleeping
Sleeping
| """ | |
| Prompt Templates — System and user prompts for the DevOps RL agent. | |
| """ | |
| from __future__ import annotations | |
| SYSTEM_PROMPT = """You are a Linux DevOps engineer. You receive an error log and command history from a broken environment. | |
| Your job: output ONE shell command that moves toward fixing the issue. | |
| Rules: | |
| - Output ONLY the command, no explanation, no markdown, no backticks | |
| - Never use destructive commands (rm -rf /, dd, mkfs) | |
| - If you've already tried a command and it failed, try a different approach | |
| - Think step by step internally, but output only the command""" | |
| USER_PROMPT_TEMPLATE = """Error type: {error_type} | |
| Current error log: | |
| {error_log} | |
| Commands tried so far: | |
| {command_history} | |
| Next command:""" | |
| def format_prompt( | |
| error_log: str, | |
| error_type: str, | |
| command_history: list[str], | |
| ) -> str: | |
| """Format the full prompt for the agent. | |
| Args: | |
| error_log: Current terminal error output. | |
| error_type: Classified error type from fingerprinting. | |
| command_history: List of previously issued commands. | |
| Returns: | |
| Formatted prompt string. | |
| """ | |
| history_str = "\n".join(f" {i+1}. {cmd}" for i, cmd in enumerate(command_history)) | |
| if not history_str: | |
| history_str = " (none yet)" | |
| return USER_PROMPT_TEMPLATE.format( | |
| error_type=error_type, | |
| error_log=error_log[:1500], | |
| command_history=history_str, | |
| ) | |
| def format_chat_messages( | |
| error_log: str, | |
| error_type: str, | |
| command_history: list[str], | |
| ) -> list[dict[str, str]]: | |
| """Format as chat messages for instruct models. | |
| Args: | |
| error_log: Current terminal error output. | |
| error_type: Classified error type from fingerprinting. | |
| command_history: List of previously issued commands. | |
| Returns: | |
| List of message dicts with 'role' and 'content'. | |
| """ | |
| user_content = format_prompt(error_log, error_type, command_history) | |
| return [ | |
| {"role": "system", "content": SYSTEM_PROMPT}, | |
| {"role": "user", "content": user_content}, | |
| ] | |