Spaces:
Sleeping
Sleeping
File size: 5,782 Bytes
83ecd75 | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | # 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 DevOps Pipeline Environment.
CI/CD deployment pipeline where an AI agent manages microservice deployments.
"""
from __future__ import annotations
from enum import Enum
from typing import Dict, List, Optional
from openenv.core.env_server.types import Action, Observation
from pydantic import BaseModel, Field
# --- Enums -------------------------------------------------------------------
class ActionType(str, Enum):
VIEW_PIPELINE = "view_pipeline"
VIEW_LOGS = "view_logs"
VIEW_CONFIG = "view_config"
EDIT_CONFIG = "edit_config"
RUN_MIGRATION = "run_migration"
DEPLOY = "deploy"
ROLLBACK = "rollback"
APPROVE = "approve"
ABORT = "abort"
class ServiceHealth(str, Enum):
HEALTHY = "healthy"
DEGRADED = "degraded"
DOWN = "down"
UNKNOWN = "unknown"
class PipelineStage(str, Enum):
IDLE = "idle"
BUILD = "build"
TEST = "test"
STAGING = "staging"
APPROVAL = "approval"
DEPLOYING = "deploying"
DEPLOYED = "deployed"
ROLLED_BACK = "rolled_back"
FAILED = "failed"
class MigrationType(str, Enum):
SCHEMA = "schema"
DATA = "data"
ROLLBACK_MIGRATION = "rollback_migration"
# --- Sub-models (plain BaseModel) --------------------------------------------
class ConfigEdit(BaseModel):
key: str = Field(description="Dot-notation config path, e.g. 'database.pool_size'")
value: str = Field(description="New value as string.")
class ServiceStatus(BaseModel):
name: str
health: ServiceHealth
current_version: str
cpu_percent: float = Field(description="CPU usage 0-100")
memory_percent: float = Field(description="Memory usage 0-100")
error_rate: float = Field(description="Errors per second")
request_latency_ms: float = Field(description="p95 latency in milliseconds")
active_connections: int
last_deploy_timestamp: str = Field(description="ISO 8601 timestamp")
recovery_status: str = Field(default="stable", description="Recovery state: 'stable' or 'stabilizing (N steps remaining)'")
class PipelineStatus(BaseModel):
stage: PipelineStage
triggered_by: str
started_at: str = Field(description="ISO 8601 timestamp")
commit_sha: str
build_logs_snippet: Optional[str] = Field(
default=None,
description="Last N lines of build output.",
)
test_pass_count: Optional[int] = None
test_fail_count: Optional[int] = None
approval_required: bool = False
blocked_reason: Optional[str] = None
class MigrationStatus(BaseModel):
pending_migrations: List[str]
last_applied: Optional[str] = None
migration_errors: Optional[List[str]] = None
class AlertInfo(BaseModel):
severity: str = Field(description="One of: critical, warning, info")
message: str
service_name: str
timestamp: str
# --- Action (extends OpenEnv Action) ----------------------------------------
class PipelineAction(Action):
"""Action for the DevOps Pipeline environment."""
action_type: ActionType
service_name: Optional[str] = Field(
default=None,
description="Target service. Required for view_logs, view_config, edit_config, deploy, rollback.",
)
target_version: Optional[str] = Field(
default=None,
description="Version tag to deploy. Required for deploy.",
)
config_edits: Optional[List[ConfigEdit]] = Field(
default=None,
description="List of config changes. Required for edit_config.",
)
migration_type: Optional[MigrationType] = Field(
default=None,
description="Type of migration. Required for run_migration.",
)
migration_name: Optional[str] = Field(
default=None,
description="Migration identifier. Required for run_migration.",
)
reason: Optional[str] = Field(
default=None,
description="Justification for approve/abort/rollback.",
)
# --- Observation (extends OpenEnv Observation) --------------------------------
class PipelineObservation(Observation):
"""Everything the agent sees after each step."""
task_description: str = Field(
default="",
description="Natural language description of what the agent must accomplish.",
)
goal: str = Field(
default="",
description="Specific success criteria for the current task.",
)
step_number: int = 0
max_steps: int = 15
services: List[ServiceStatus] = Field(default_factory=list)
pipeline: Optional[PipelineStatus] = None
migrations: Optional[MigrationStatus] = None
active_alerts: List[AlertInfo] = Field(default_factory=list)
available_actions: List[str] = Field(
default_factory=list,
description="List of valid action_type values in current state.",
)
last_action_result: Optional[str] = Field(
default=None,
description="Human-readable outcome of the previous action.",
)
last_action_error: Optional[str] = Field(
default=None,
description="Error message if previous action failed, else null.",
)
config_snapshot: Optional[Dict[str, str]] = Field(
default=None,
description="Current config key-value pairs when viewing/editing config.",
)
summary: Optional[str] = Field(
default=None,
description="Quick status summary highlighting degraded/down services.",
)
|