File size: 4,924 Bytes
8f447ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
models.py β€” All Pydantic typed models for the Business Sim OpenEnv environment.
Satisfies OpenEnv spec: typed models for action_space and observation_space.
"""
from __future__ import annotations
from pydantic import BaseModel, Field
from typing import Optional
from enum import Enum


class TechStack(str, Enum):
    cheap    = "cheap"
    standard = "standard"
    premium  = "premium"


class MarketPhase(str, Enum):
    boom      = "boom"
    stable    = "stable"
    recession = "recession"


class Domain(str, Enum):
    ai     = "ai"
    web    = "web"
    mobile = "mobile"
    data   = "data"
    devops = "devops"


class Project(BaseModel):
    """A client project the CEO can accept."""
    id:                 str
    name:               str
    domain:             Domain

    # Factor 1 β€” Profit Potential
    base_profit:        float
    profit_variance:    float          # 0.0–1.0

    # Factor 2 β€” Risk Level
    base_risk:          float          # 0.0–1.0
    hidden_risk:        float          # 0.0–1.0  (uncertainty / unknown scope)

    # Factor 3 β€” Team Capability
    skill_required:     float          # 0.0–1.0

    # Factor 4 β€” Deadline Pressure (encoded as duration + tightness)
    duration_quarters:  int
    deadline_tight:     bool

    # Factor 5 β€” Market Demand sensitivity
    demand_sensitivity: float

    # Factor 6 β€” Reputation Impact
    reputation_gain:    float
    reputation_loss:    float

    # Resource cost (tooling, infra, licenses)
    resource_cost:      float


class TeamState(BaseModel):
    """Snapshot of the company's engineering team."""
    size:         int
    skill:        float   # 0.0–1.0  average skill level
    burnout:      float   # 0.0–1.0  employee load / fatigue
    domain_focus: Domain  # strongest domain


# ── Action Space (what the CEO decides each quarter) ──────────────────────────

class CEOAction(BaseModel):
    """
    ACTION SPACE β€” OpenEnv spec requires a typed action model.
    All fields have safe defaults so a no-op action is always valid.
    """
    accept_project_id: Optional[str]  = Field(
        default=None,
        description="8-char project ID from available_projects, or null to skip"
    )
    hire_count:        int            = Field(
        default=0, ge=0, le=5,
        description="Number of developers to hire this quarter"
    )
    fire_count:        int            = Field(
        default=0, ge=0, le=3,
        description="Number of developers to let go"
    )
    training_budget:   float          = Field(
        default=0.0, ge=0.0, le=50_000.0,
        description="Budget allocated to team skill training"
    )
    tech_stack:        TechStack      = Field(
        default=TechStack.standard,
        description="Technology stack choice affects quality, speed, cost"
    )
    reduce_workload:   bool           = Field(
        default=False,
        description="Pay $5k to rest team and reduce burnout by 0.25"
    )


# ── Observation Space (what the CEO sees each quarter) ────────────────────────

class CompanyObservation(BaseModel):
    """
    OBSERVATION SPACE β€” OpenEnv spec requires a typed observation model.
    Exposes all 6 key factors so the agent can make informed decisions.
    """
    # Identity
    session_id:          str
    quarter:             int
    max_quarters:        int
    goal:                str

    # Factor 1 β€” Finances
    budget:              float
    resource_pool:       float         # man-hours proxy

    # Factor 3 + Resource β€” Team state
    team:                TeamState

    # Factor 6 β€” Reputation
    reputation:          float         # 0.0–1.0

    # Factor 5 β€” Market
    market_phase:        MarketPhase
    domain_demand:       dict          # {"ai": 1.3, "web": 0.9, ...}

    # Factor 2 β€” Available projects (all 6 factors visible per project)
    available_projects:  list[Project]
    active_risks:        list[str]

    # Step feedback (mirrors BrowserGym pattern)
    last_action_result:  Optional[str] = None
    last_action_error:   Optional[str] = None


# ── Step / State return types ─────────────────────────────────────────────────

class StepResult(BaseModel):
    observation: CompanyObservation
    reward:      float
    done:        bool
    info:        dict


class FullState(BaseModel):
    """Returned by GET /state β€” includes internal state for counterfactual analysis."""
    observation:          CompanyObservation
    internal:             dict
    episode_history:      list[dict]
    counterfactual_hint:  Optional[str] = None


class TaskInfo(BaseModel):
    id:           str
    difficulty:   str
    max_quarters: int
    description:  str