Akshaya Kumar
Add real project files
50bf486
Raw History Blame Contribute Delete
3.15 kB
"""
Pydantic models for the SQL Debug Environment.
These extend the openenv-core base types so the framework knows
how to serialize/deserialize our action and observation payloads.
Action → SQLAction (just a query string)
Observation → SQLObservation (all the feedback the agent sees)
State → SQLState (episode tracking for checkpoints)
"""
from __future__ import annotations
from typing import Any, Optional
from openenv.core.env_server import Action, Observation, State
from pydantic import Field
class SQLAction(Action):
"""What the agent sends us — just a SQL query."""
query: str = Field(
...,
description="SQL query to run against the database.",
examples=[
"SELECT name, salary FROM employees WHERE department = 'Engineering' ORDER BY salary DESC"
],
)
class SQLObservation(Observation):
"""Everything the agent sees after a reset() or step().
Inherits done, reward, and metadata from the base Observation class.
"""
task_id: str = Field(
...,
description="Which task we're on (fix_syntax, fix_join, optimize_query).",
)
broken_query: str = Field(
...,
description="The original broken query that needs fixing.",
)
schema_description: str = Field(
...,
description="Human-readable schema description for the relevant tables.",
)
error_message: Optional[str] = Field(
None,
description="SQL error from the last query, if it failed.",
)
result_preview: Optional[list[dict[str, Any]]] = Field(
None,
description="First 10 rows of the last query's output (when it ran successfully).",
)
expected_row_count: int = Field(
...,
description="How many rows the correct query returns.",
)
current_row_count: Optional[int] = Field(
None,
description="How many rows the agent's last query returned.",
)
step_number: int = Field(
0,
description="Current step in the episode (0 = haven't submitted anything yet).",
)
max_steps: int = Field(
8,
description="Max steps before the episode auto-terminates.",
)
hint: Optional[str] = Field(
None,
description="Hint given at certain steps to nudge the agent in the right direction.",
)
class SQLState(State):
"""Episode-level state — mostly for debugging and checkpointing.
Inherits episode_id and step_count from the base State class.
"""
task_id: str = Field(default="", description="Which task is active.")
max_steps: int = Field(default=8, description="Step limit for the episode.")
last_reward: float = Field(default=0.0, description="Most recent step's reward.")
cumulative_max_reward: float = Field(
default=0.0, description="Best reward seen so far this episode."
)
done: bool = Field(default=False, description="Whether the episode is over.")
history: list[dict[str, Any]] = Field(
default_factory=list,
description="Log of (query, reward) pairs from this episode.",
)