File size: 2,104 Bytes
0c216ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5583f9
 
 
 
 
 
 
 
0c216ef
 
f5583f9
 
 
0c216ef
 
 
f5583f9
0c216ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
DataQA Environment Models
-------------------------
Action/Observation/State types for the Data Quality Assurance environment.

The agent receives a dataset with planted quality issues and must identify them.
Grading is based on F1 score (precision × recall) of correctly identified issues.
"""

from __future__ import annotations

from typing import List, Optional

from openenv.core.env_server.interfaces import Action, Observation, State


class DataQAAction(Action):
    """
    Agent submits identified issues AND optional proposed fixes.

    Two-phase action space:
      Phase 1 (Identify): List issues in format "row:<N>,col:<name>,issue:<type>"
      Phase 2 (Fix):      List fixes in format "row:<N>,col:<name>,fix:<proposed_value>"

    The agent can submit both in the same step or across multiple steps.
    Combined reward = 0.6 * identify_score + 0.4 * fix_score

    Supported issue types:
        missing_value, wrong_type, duplicate_row, out_of_range,
        format_violation, inconsistent_value, statistical_outlier,
        referential_integrity
    """

    issues: List[str]
    fixes: List[str] = []
    # Include task_id so step() can reconstruct context in stateless HTTP mode
    task_id: str = "easy"


class DataQAObservation(Observation):
    """
    What the agent sees: a dataset, its schema/rules, and feedback.
    """

    # The dataset as CSV text
    dataset_csv: str = ""

    # Schema description (column names, expected types, constraints)
    schema_description: str = ""

    # Validation rules in plain text
    validation_rules: str = ""

    # Task description
    task_description: str = ""

    # Feedback from previous step (empty on reset)
    feedback: str = ""

    # Current task ID
    task_id: str = ""

    # Number of planted issues (hint for the agent)
    num_issues_hint: int = 0

    # Max allowed steps for this task
    max_steps: int = 3


class DataQAState(State):
    """Tracks episode progress."""

    task_id: str = ""
    current_step: int = 0
    max_steps: int = 3
    best_score: float = 0.0
    total_planted_issues: int = 0