47 lines
No EOL
1.2 KiB
Python
47 lines
No EOL
1.2 KiB
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
|
|
|
|
|
|
@dataclass
|
|
class ExploreAgent(Agent):
|
|
"""Very small stateful agent that decides which command to run next."""
|
|
|
|
default_command: str = "untersuche boden"
|
|
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 |