File size: 3,467 Bytes
5f45585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129

from pydantic import BaseModel, Field
from typing import Any, Dict, List, Optional


class Action(BaseModel):
    """Action that the agent can take in the environment."""
    operation: str = Field(
        ...,
        description=(
            "Operation to perform. One of: "
            "remove_duplicates, fill_missing, fix_dtype, "
            "remove_outliers, rename_columns, validate_schema, finish"
        )
    )
    parameters: Dict[str, Any] = Field(
        default_factory=dict,
        description="Parameters for the operation"
    )

    class Config:
        json_schema_extra = {
            "example": {
                "operation": "fill_missing",
                "parameters": {
                    "column": "age",
                    "strategy": "mean"
                }
            }
        }


class Observation(BaseModel):
    """What the agent sees at each step."""
    task_id: str = Field(..., description="Current task identifier")
    step: int = Field(..., description="Current step number")
    dataset_info: Dict[str, Any] = Field(
        ...,
        description="Info about current dataset state"
    )
    columns: List[str] = Field(
        ...,
        description="Column names in dataset"
    )
    shape: List[int] = Field(
        ...,
        description="[rows, columns] of dataset"
    )
    missing_values: Dict[str, int] = Field(
        ...,
        description="Count of missing values per column"
    )
    dtypes: Dict[str, str] = Field(
        ...,
        description="Data types of each column"
    )
    duplicate_count: int = Field(
        ...,
        description="Number of duplicate rows"
    )
    sample_rows: List[Dict[str, Any]] = Field(
        ...,
        description="First 3 rows of dataset as preview"
    )
    available_operations: List[str] = Field(
        ...,
        description="List of valid operations agent can use"
    )
    task_description: str = Field(
        ...,
        description="Natural language description of what agent must do"
    )
    message: str = Field(
        default="",
        description="Feedback message from last action"
    )


class Reward(BaseModel):
    """Reward signal returned after each step."""
    total: float = Field(
        ...,
        description="Total reward this step (0.0 to 1.0)"
    )
    duplicate_score: float = Field(
        default=0.0,
        description="Score for duplicate removal"
    )
    missing_score: float = Field(
        default=0.0,
        description="Score for handling missing values"
    )
    dtype_score: float = Field(
        default=0.0,
        description="Score for fixing data types"
    )
    outlier_score: float = Field(
        default=0.0,
        description="Score for outlier removal"
    )
    schema_score: float = Field(
        default=0.0,
        description="Score for schema validation"
    )
    penalty: float = Field(
        default=0.0,
        description="Penalty for bad actions"
    )


class StepResult(BaseModel):
    """Full result returned by step()."""
    observation: Observation
    reward: Reward
    done: bool = Field(..., description="Whether episode is complete")
    info: Dict[str, Any] = Field(
        default_factory=dict,
        description="Extra info for debugging"
    )


class TaskInfo(BaseModel):
    """Metadata about a task."""
    task_id: str
    difficulty: str
    description: str
    max_steps: int
    operations_allowed: List[str]