Spaces:
Sleeping
Sleeping
| """ | |
| DataClerk OpenEnv β Pydantic models for actions, observations, and state. | |
| """ | |
| from __future__ import annotations | |
| from typing import Any, Dict, List, Optional | |
| from pydantic import BaseModel, Field | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| # Action | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| class SQLAction(BaseModel): | |
| """ | |
| The action an agent can take in the DataClerk environment. | |
| action_type choices | |
| ------------------- | |
| execute_sql β Run a SELECT SQL query against the database. | |
| describe_table β Get column info for a specific table. | |
| list_tables β List all available tables. | |
| submit_answer β Submit the final natural-language answer for grading. | |
| """ | |
| action_type: str = Field( | |
| description=( | |
| "One of: 'execute_sql', 'describe_table', 'list_tables', 'submit_answer'" | |
| ) | |
| ) | |
| sql_query: Optional[str] = Field( | |
| default=None, | |
| description="SQL SELECT query to execute (required for execute_sql).", | |
| ) | |
| table_name: Optional[str] = Field( | |
| default=None, | |
| description="Table name to describe (required for describe_table).", | |
| ) | |
| answer: Optional[str] = Field( | |
| default=None, | |
| description="Final answer text (required for submit_answer).", | |
| ) | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| # Observation | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| class QueryResult(BaseModel): | |
| """Structured result from an executed SQL query.""" | |
| columns: List[str] | |
| rows: List[List[Any]] | |
| row_count: int | |
| class SQLObservation(BaseModel): | |
| """ | |
| Everything the agent sees after each step. | |
| Fields | |
| ------ | |
| task_id β Identifier of the active task. | |
| task_description β Full natural-language description of the goal. | |
| task_hints β Optional hints for the current task. | |
| available_tables β Tables the agent may query. | |
| schema_summary β Dict of {table_name: ["col (TYPE)", β¦]}. | |
| last_action_type β The action_type that produced this observation. | |
| last_query β The SQL that was last executed (if any). | |
| last_query_result β Structured result of the last query (if any). | |
| last_query_error β Error message from the last query (if any). | |
| query_count β Total successful queries executed this episode. | |
| step β Current step number (1-indexed). | |
| max_steps β Maximum steps allowed for this task. | |
| status β "in_progress" | "submitted" | "timeout". | |
| """ | |
| task_id: str | |
| task_description: str | |
| task_hints: List[str] = [] | |
| available_tables: List[str] | |
| schema_summary: Dict[str, List[str]] | |
| last_action_type: Optional[str] = None | |
| last_query: Optional[str] = None | |
| last_query_result: Optional[QueryResult] = None | |
| last_query_error: Optional[str] = None | |
| query_count: int = 0 | |
| step: int | |
| max_steps: int | |
| status: str = "in_progress" | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| # State (returned by /state) | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| class EpisodeState(BaseModel): | |
| """Full internal state of a running episode (for /state endpoint).""" | |
| session_id: str | |
| task_id: str | |
| step: int | |
| max_steps: int | |
| done: bool | |
| total_reward: float | |
| submitted_answer: Optional[str] = None | |
| query_history: List[str] = [] | |
| query_count: int = 0 | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| # API request / response wrappers | |
| # βββββββββββββββββββββββββββββββββββββββββββββ | |
| class ResetRequest(BaseModel): | |
| task_id: Optional[str] = None | |
| class StepRequest(BaseModel): | |
| session_id: str | |
| action: SQLAction | |
| class StepResponse(BaseModel): | |
| observation: SQLObservation | |
| reward: float | |
| done: bool | |
| info: Dict[str, Any] | |
| class ResetResponse(BaseModel): | |
| session_id: str | |
| observation: SQLObservation | |
| done: bool = False | |
| info: Dict[str, Any] = {} | |