Spaces:
Sleeping
Sleeping
File size: 2,180 Bytes
ef84164 | 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 | from pydantic import BaseModel, Field
from typing import List, Optional, Literal
# --- Nested Models for cleaner structure ---
class CertificateRequest(BaseModel):
request_id: str
student_name: str
course_name: str
final_score: float = Field(description="Score out of 100. Must be >= 70 to pass.")
wallet_address: str = Field(description="Must start with '0x' and be exactly 42 characters long.")
class ActionDecision(BaseModel):
request_id: str
decision: Literal["mint", "reject"] = Field(description="Whether to mint the certificate or reject the request.")
reason: str = Field(description="Short explanation of why it was minted or rejected.")
# ---------------------------------------------------------
# OBSERVATION SPACE (What the agent sees)
# ---------------------------------------------------------
class BlockchainObservation(BaseModel):
pending_requests: List[CertificateRequest] = Field(
description="List of student certificate requests awaiting processing."
)
gas_balance: float = Field(
description="Remaining gas balance in the admin wallet to pay for minting."
)
current_step: int = Field(
description="The current step in the episode."
)
last_error: Optional[str] = Field(
default=None,
description="Error message if the previous action was invalid."
)
# ---------------------------------------------------------
# ACTION SPACE (What the agent can do)
# ---------------------------------------------------------
class BlockchainAction(BaseModel):
decisions: List[ActionDecision] = Field(
description="The agent's decisions for the pending requests."
)
# ---------------------------------------------------------
# REWARD SPACE (How the agent is scored)
# ---------------------------------------------------------
class BlockchainReward(BaseModel):
score: float = Field(
ge=0.0, le=1.0,
description="Normalized score between 0.0 and 1.0 based on correct mints and rejections."
)
feedback: str = Field(
description="Feedback detailing gas wasted, incorrect mints, or missed valid certificates."
) |