File size: 1,254 Bytes
6ec7f56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Task registry. Adding a task = implement the Task protocol, register here."""

from __future__ import annotations

from typing import Any, Protocol

from .tasks.causal_gate import CausalGate
from .tasks.checkout_form import CheckoutForm
from .tasks.email_triage import EmailTriage
from .tasks.flash_offer import FlashOffer
from .tasks.settings_panel import SettingsPanel


class Task(Protocol):
    id: str
    title: str
    template: str

    def generate(self, seed: int) -> dict[str, Any]:
        """Build a fresh, fully seed-determined episode state."""

    def instruction(self, state: dict[str, Any]) -> str:
        """Natural-language goal handed to the agent out-of-band."""

    def view(self, state: dict[str, Any]) -> dict[str, Any]:
        """Template context for rendering the task page."""

    def handle_action(self, state: dict[str, Any], payload: dict[str, Any]) -> dict[str, Any]:
        """Mutate state in response to a UI action. Return {'ok': bool, ...}."""

    def verify(self, state: dict[str, Any]) -> dict[str, bool]:
        """Named subgoals; episode succeeds iff all are true."""


_ALL = [EmailTriage(), SettingsPanel(), CheckoutForm(), CausalGate(), FlashOffer()]
TASKS: dict[str, Task] = {t.id: t for t in _ALL}