File size: 3,882 Bytes
e7729e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""
Data models for the Smart Farm Irrigation Environment.

This environment simulates a real-world crop irrigation management task
where an AI agent decides how much to water crops based on:
- Weather conditions (temperature, rainfall) from Weather API
- Soil moisture (from sensor if available, else calculated)
- Crop health (selected by user)
- Crop stage and day number (auto-managed by code)
"""

from enum import Enum
from typing import Optional
from openenv.core.env_server.types import Action, Observation
from pydantic import Field

class CropHealthStatus(str, Enum):
    """
    User selects current crop health.
    Like a dropdown β€” only these 4 options allowed.
    """
    POOR="poor"
    FAIR="fair"
    GOOD="good"
    EXCELLENT="excellent"

class WaterAmount(str, Enum):
    """
    AI selects how much to water the crop.
    This is the ACTION the AI takes every day.
    """
    NONE="none"
    LOW="low"
    MEDIUM="medium"
    HIGH="high"

class CropStage(str, Enum):
    """
    Crop growth stage β€” automatically set by code based on day number.
    User never touches this. Code manages it.
    Day 1-10  β†’ Seedling
    Day 11-20 β†’ Growing
    Day 21-30 β†’ Mature
    """
    SEEDLING = "seedling"
    GROWING="growing"
    MATURE="mature"

class FarmObservation(Observation):
    """
    Everything the AI can observe about the farm at any given moment.
    
    Sources:
    - temperature, rainfall     β†’ fetched from Weather API
    - soil_moisture             β†’ from sensor (optional) or calculated
    - crop_health               β†’ selected by user (dropdown)
    - day_number, crop_stage    β†’ auto-managed by code
    """

    #FROM WEATHER API
    temperature: float = Field(
        ...,
        description="Current temperature in Celsius (from Weather API)",
        ge=0.0, #min
        le=60.0 #max
    )

    rainfall: float = Field(
        ...,
        description="Rainfall today in mm (from Weather API)",
        ge=0.0, #min
        le=500.0 #max
    )

    #FROM SENSOR OR CALCULATED
    soil_moisture: Optional[float] = Field(
        default=None,
        description=(
            "Soil moisture percentage (0-100). "
            "Provide this if you have a sensor. "
            "If None, code will calculate it automatically "
            "based on rainfall and temperature."
        ),
        ge=0.0,
        le=100.0
    )

    #USER SELECTS
    crop_health: CropHealthStatus = Field(
        ...,
        description="Current crop health selected by user (poor/fair/good/excellent)"
    )

    #AUTO MANAGED BY CODE
    day_number: int = Field(
        default=1,
        description="Current day of simulation (1-30). Auto-incremented by code.",
        ge=1,
        le=30
    )

    crop_stage: CropStage = Field(
        default=CropStage.SEEDLING,
        description="Current crop growth stage. Auto-set by code based on day_number."
    )

class FarmAction(Action):
    """
    The only decision the AI makes every day:
    How much water should I give the crop today?
    """

    water_amount: WaterAmount = Field(
        ...,
        description=(
            "How much to water the crop today. "
            "none=0mm, low=10mm, medium=25mm, high=50mm"
        )
    )

class FarmReward:
    """
    Score given to AI after each action.
    Tells the AI how well it did.
    """

    value: float = Field(
        ...,
        description="Reward score between 0.0 (worst) and 1.0 (best)",
        ge=-1.0,   # can go negative for very bad actions
        le=1.0
    )

    reason: str = Field(
        ...,
        description="Human-readable explanation of why this score was given"
    )