Implementation:Facebookresearch Habitat lab Agent ABC
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Software_Architecture |
| Last Updated | 2026-02-15 02:00 GMT |
Overview
Concrete abstract base class defining the agent interface for Habitat environments, with concrete implementations including PPOAgent and simple baseline agents.
Description
The Agent ABC in habitat-lab defines the `reset()` and `act(observations)` methods. Concrete implementations include:
- PPOAgent: Loads a trained PPO checkpoint and runs inference
- RandomAgent: Takes random actions
- GoalFollower: Uses ShortestPathFollower oracle to navigate to goals
Usage
Subclass `habitat.Agent` to create custom agents, or use `PPOAgent` to wrap trained checkpoints for evaluation.
Code Reference
Source Location
- Repository: habitat-lab
- File: habitat-lab/habitat/core/agent.py (L16-36), habitat-baselines/habitat_baselines/agents/ppo_agents.py (L42-141), habitat-baselines/habitat_baselines/agents/simple_agents.py (L21-44, L75-110)
Signature
class Agent(metaclass=abc.ABCMeta):
"""Abstract base class for agents."""
@abc.abstractmethod
def reset(self) -> None:
"""Called at the beginning of each episode."""
raise NotImplementedError
@abc.abstractmethod
def act(self, observations: Observations) -> Union[int, str, Dict[str, Any]]:
"""
Args:
observations: Current observations from environment
Returns:
Action to execute
"""
raise NotImplementedError
# PPOAgent implementation
class PPOAgent(Agent):
def __init__(self, config: DictConfig):
"""Load trained PPO policy from checkpoint."""
def reset(self) -> None:
"""Reset recurrent hidden states."""
def act(self, observations) -> Dict[str, int]:
"""Run policy inference."""
Import
from habitat.core.agent import Agent
from habitat_baselines.agents.ppo_agents import PPOAgent
from habitat_baselines.agents.simple_agents import RandomAgent, GoalFollower
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| observations | Observations (Dict) | Yes | Current sensor observations from environment |
| config | DictConfig | Yes (for PPOAgent) | Config with checkpoint path |
Outputs
| Name | Type | Description |
|---|---|---|
| action | Union[int, str, Dict] | Action to execute in the environment |
Usage Examples
Create PPO Agent
from habitat_baselines.agents.ppo_agents import PPOAgent
agent = PPOAgent(config)
agent.reset()
action = agent.act(observations)
Create Random Agent
from habitat_baselines.agents.simple_agents import RandomAgent
agent = RandomAgent(
success_distance=0.2,
goal_sensor_uuid="pointgoal_with_gps_compass",
)
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment