CoolFace
Apppublic

StarTripper/ticket_ordering

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
models.py92 linesDownload Raw Back to root
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8Data models for the Ticket Ordering Environment.9 10The ticket_ordering environment is an environment that presents an environment for optimally ordering11tickets (e.g. Jira tickets, Github issues) according to an arbitrary (but clearly specified) criteria.12"""13 14 15from pydantic import BaseModel, Field16from openenv.core.env_server import State, Observation, Action17 18 19class ThreadComment(BaseModel):20    user: str = Field(min_length=1, max_length=16, description="Username of user commenting on the thread")21    content: str = Field(min_length=1, max_length=1024, description="Content of the user's comment on the thread.")22 23class TicketHeuristic(BaseModel):24    priority: float = Field(default=0.0, description="Relative priority of the ticket. Priority is only meaningful relative to other tickets.")25    summary: str = Field(default="", max_length=32, description="Summary of the ticket. Useful for agents to store context for tricky tickets.")26    times_assigned: int = Field(default=0, description="Times the heuristic has been assigned. Loose metric of 'certainty' (more assignments ~= more certain)")27 28class Ticket(BaseModel):29    id: int = Field(description="ID of the ticket, random / meaningless unique identifier.")30    thread: list[ThreadComment] = Field(description="Thread of comments on the ticket.")31 32    heuristic: TicketHeuristic = Field(description="Heuristic of the ticket.")33 34 35 36 37class TicketOrderingConfig(BaseModel):38    max_steps: int = Field(default=50, description="Maximum number of steps in an episode.")39    max_reference_tickets: int = Field(default=5, description="Maximum number of references an agent can request on a step.")40    max_heurestics: int = Field(default=10, description="Maximum number of heuristics in an observation on a step.")41 42class TicketOrderingState(State):43    """State for the Ticket Ordering environment."""44    ordering_criteria: str = Field(max_length=32, description="Criteria by which tickets are to be ordered.")45    optimally_ordered_ticket_ids: list[int] = Field(description="IDs of the optimal ticket at each position / index.")46    tickets: list[Ticket] = Field(min_length=2, max_length=128, description="Tickets to be ordered by the agent.")47    optimality: float = Field(ge=0.0, le=1.0, description="How close the tickets are to being optimal, can be thought of as a percentage.")48 49 50class TicketOrderingObservation(Observation):51    """Observation from the Ticket Ordering environment."""52    ordering_criteria: str = Field(53        max_length=32,54        description="Criteria by which tickets should be ordered."55    )56    reference_tickets: list[Ticket] = Field(57        description="Subset of tickets provided as references to help evaluate and compare the current candidate ticket."58    )59    candidate_ticket: Ticket = Field(60        description="The ticket currently being evaluated and assigned a heuristic by the agent."61    )62    ticket_heuristics: dict[int, TicketHeuristic] = Field(63        description="Known heuristics for previously evaluated tickets, keyed by ticket ID, used for relative comparison."64    )65    total_tickets: int = Field(66        default=0,67        description="Total number of tickets in the environment that need to be ordered."68    )69    completed_iterations: int = Field(70        default=0,71        description="Number of ordering steps completed so far in the current episode."72    )73 74 75class TicketOrderingAction(Action):76    """Action for the Ticket Ordering environment."""77    candidate_priority: float = Field(78        description="Assigned priority score for the candidate ticket, relative to other tickets."79    )80    candidate_summary: str = Field(81        description="Short summary describing the candidate ticket, capturing key context for future comparisons."82    )83    next_reference_ids: list[int] = Field(84        description="IDs of tickets to request as references in the next step, used to guide further comparisons."85    )86    next_candidate_id: int = Field(87        description="ID of the next ticket to evaluate as the candidate in the following step."88    )89    end_ordering: bool = Field(90        description="Whether the agent thinks it has finished ordering all tickets and wants to terminate the episode."91    )92