File size: 955 Bytes
4455094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from inference import safe_parse_action


def test_safe_parse_action_uses_valid_example_for_placeholder_service() -> None:
    action = safe_parse_action(
        '{"action_type":"isolate_service","target_service":"service"}',
        allowed_actions=["isolate_service(service)", "restart_service(service)"],
        valid_action_example={"action_type": "isolate_service", "target_service": "auth_service"},
    )

    assert action.action_type == "isolate_service"
    assert action.target_service == "auth_service"


def test_safe_parse_action_salvages_followup_agent_from_example() -> None:
    action = safe_parse_action(
        "please request_followup(agent)",
        allowed_actions=["request_followup(agent)"],
        valid_action_example={"action_type": "request_followup", "target_agent": "security"},
    )

    assert action.action_type == "request_followup"
    assert action.target_agent == "security"