File size: 3,664 Bytes
72de9a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d73bfc0
 
 
 
72de9a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d73bfc0
 
 
 
 
 
 
 
72de9a9
 
 
 
 
 
 
 
 
 
d73bfc0
72de9a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d73bfc0
 
 
 
 
 
 
 
72de9a9
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
Pydantic models for the API Debug Environment.

APIDebugAction: What the agent sends each step.
APIDebugObservation: What the environment returns each step.

All Action fields are Optional so the agent can submit only what it has.
For example, on an easy task the agent only needs error_type and affected_fields.
On medium, it needs fixed_request. On hard, it needs everything plus explanation.
"""

from typing import Dict, List, Optional

from openenv.core.env_server.types import Action, Observation
from pydantic import Field


class APIDebugAction(Action):
    """Agent's response at each step of the debugging episode."""

    error_type: Optional[str] = Field(
        default=None,
        description="Diagnosed error type, e.g. 'missing_required_field'"
    )
    error_types: Optional[List[str]] = Field(
        default=None,
        description="All diagnosed error types (for classify task with multiple errors)"
    )
    affected_fields: Optional[List[str]] = Field(
        default=None,
        description="List of field names affected by the error"
    )
    fixed_request: Optional[str] = Field(
        default=None,
        description="JSON string of the corrected request body"
    )
    fixed_headers: Optional[Dict[str, str]] = Field(
        default=None,
        description="Corrected HTTP headers if applicable"
    )
    explanation: Optional[str] = Field(
        default=None,
        description="Developer-facing explanation of the fix (hard task only)"
    )
    response_issues: Optional[List[str]] = Field(
        default=None,
        description="Issues found in the API response (response task only)"
    )
    expected_status_code: Optional[int] = Field(
        default=None,
        description="Correct HTTP status code for the response (response task only)"
    )


class APIDebugObservation(Observation):
    """Environment's response at each step.

    Inherits done, reward, and metadata from Observation base class.
    """

    task: str = Field(
        default="easy",
        description="Current task: easy, classify, medium, headers, hard, response"
    )
    api_name: str = Field(
        default="",
        description="Name of the API being debugged"
    )
    http_method: str = Field(
        default="POST",
        description="HTTP method of the broken request"
    )
    endpoint: str = Field(
        default="",
        description="API endpoint path"
    )
    broken_request: str = Field(
        default="",
        description="JSON string of the malformed request body"
    )
    broken_headers: Dict[str, str] = Field(
        default_factory=dict,
        description="HTTP headers sent with the broken request"
    )
    api_spec: str = Field(
        default="",
        description="JSON string of the API specification"
    )
    error_count: int = Field(
        default=1,
        description="Number of errors injected in this episode"
    )
    step_number: int = Field(
        default=0,
        description="Current step in this episode"
    )
    max_steps: int = Field(
        default=3,
        description="Maximum steps allowed for this task"
    )
    response_body: str = Field(
        default="",
        description="JSON string of the API response to validate (response task only)"
    )
    response_status_code: int = Field(
        default=0,
        description="HTTP status code of the response (response task only)"
    )
    feedback: str = Field(
        default="",
        description="Structured validation feedback from the last action"
    )
    message: str = Field(
        default="",
        description="Human-readable status message"
    )