File size: 2,053 Bytes
27cdb3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
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},
    ]