mistle/agent.py

32 lines
852 B
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Optional
class Agent(ABC):
"""Interface for autonomous Telnet actors."""
@abstractmethod
def observe(self, output: str) -> None:
"""Receive the latest text emitted by the server."""
@abstractmethod
def decide(self) -> Optional[str]:
"""Return the next command to send, or ``None`` to stay idle."""
@dataclass
class SimpleAgent(Agent):
"""Very small stateful agent that decides which command to run next."""
default_command: str = "schau"
last_output: str = field(default="", init=False)
def observe(self, output: str) -> None:
if output:
self.last_output = output
def decide(self) -> Optional[str]:
return self.default_command