|
| 1 | +# Agents Module |
| 2 | + |
| 3 | +This module provides a variety of agent classes for use in reinforcement learning and maze navigation environments. Agents can be used as-is or extended for custom behaviors. Many agents have both standard and memory-augmented variants that leverage episodic and semantic memory for improved performance. |
| 4 | + |
| 5 | +## Agent Types |
| 6 | + |
| 7 | +### 1. `Agent` (Abstract Base Class) |
| 8 | +Defines the interface for all agents. To implement a custom agent, inherit from this class and implement the required methods. |
| 9 | + |
| 10 | +**API:** |
| 11 | +```python |
| 12 | +class Agent(ABC): |
| 13 | + def __init__(self, agent_id: str, action_space, **kwargs): ... |
| 14 | + @abstractmethod |
| 15 | + def act(self, observation: MazeObservation, epsilon: float = 0.1) -> int: ... |
| 16 | + @abstractmethod |
| 17 | + def set_demo_path(self, path: list[int]) -> None: ... |
| 18 | +``` |
| 19 | + |
| 20 | +### 2. `RandomAgent` |
| 21 | +Selects actions randomly from the action space. Useful as a baseline. |
| 22 | + |
| 23 | +### 3. `MemoryRandomAgent` |
| 24 | +A random agent that also stores and retrieves state/action information from a memory system, biasing action selection toward previously successful actions. |
| 25 | + |
| 26 | +### 4. `AlgoAgent` |
| 27 | +A planning agent that uses search algorithms (BFS/DFS or custom) to plan a path to the target. Good for deterministic environments. |
| 28 | + |
| 29 | +### 5. `MemoryAlgoAgent` |
| 30 | +A planning agent with memory augmentation. Retrieves similar states from memory to bias planning and action selection. |
| 31 | + |
| 32 | +### 6. `QAgent` |
| 33 | +Implements tabular Q-learning. Maintains a Q-table for state-action values and uses an epsilon-greedy policy. |
| 34 | + |
| 35 | +### 7. `MemoryQAgent` |
| 36 | +A Q-learning agent with memory augmentation. Stores and retrieves states, actions, and interactions from memory to bias exploration and exploitation. |
| 37 | + |
| 38 | +### 8. `DeepQAgent` |
| 39 | +Implements Deep Q-Learning using PyTorch. Uses a neural network to approximate Q-values and experience replay for training. |
| 40 | + |
| 41 | +### 9. `MemoryDeepQAgent` |
| 42 | +A deep Q-learning agent with memory augmentation. Stores and retrieves states and interactions from memory to bias action selection and learning. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +> **Note:** Only the abstract `Agent` is exposed in `agents/__init__.py`. To use concrete agents, import them directly from their respective files: |
| 49 | +
|
| 50 | +```python |
| 51 | +from agents.random_agent import RandomAgent, MemoryRandomAgent |
| 52 | +from agents.algo_agent import AlgoAgent, MemoryAlgoAgent |
| 53 | +from agents.q_agent import QAgent, MemoryQAgent |
| 54 | +from agents.deep_q_agent import DeepQAgent, MemoryDeepQAgent |
| 55 | +``` |
| 56 | + |
| 57 | +## Example |
| 58 | + |
| 59 | +```python |
| 60 | +from agents.q_agent import QAgent |
| 61 | +from memory.api.models import MazeObservation |
| 62 | + |
| 63 | +agent = QAgent(agent_id="A1", action_space=4) |
| 64 | +obs = MazeObservation(position=(0,0), target=(3,3), steps=0, nearby_obstacles=[]) |
| 65 | +action = agent.act(obs) |
| 66 | +``` |
| 67 | + |
| 68 | +## Extending Agents |
| 69 | +To create your own agent, inherit from `Agent` and implement the `act` and `set_demo_path` methods. |
| 70 | + |
| 71 | +## Memory-Augmented Agents |
| 72 | +Memory-augmented agents use a `MemorySpace` object to store and retrieve states, actions, and interactions. This enables: |
| 73 | +- Retrieval of similar past states for biasing action selection |
| 74 | +- Storing successful actions/interactions for future use |
| 75 | +- Episodic and semantic memory integration |
| 76 | + |
| 77 | +## Requirements |
| 78 | +- `memory` module (for memory-augmented agents) |
| 79 | +- `numpy`, `torch` (for DeepQAgent) |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## File Overview |
| 84 | +- `base.py`: Abstract base class |
| 85 | +- `random_agent.py`: RandomAgent, MemoryRandomAgent |
| 86 | +- `algo_agent.py`: AlgoAgent, MemoryAlgoAgent |
| 87 | +- `q_agent.py`: QAgent, MemoryQAgent |
| 88 | +- `deep_q_agent.py`: DeepQAgent, MemoryDeepQAgent |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +For more details, see the docstrings in each agent class. |
0 commit comments