Skip to main content

Single Agent

The Agent class is the foundation for building intelligent agents in Neurenix. It provides a flexible base class that you can extend to create custom agents for reinforcement learning, autonomous behavior, and more.

Agent Class

The Agent class is defined in neurenix/agent/agent.py and provides the core interface for all agents.

Constructor

Parameters:
  • name (str, optional): The name of the agent. If not provided, a random name is generated (e.g., Agent-a1b2c3d4)

Properties

name

Get the name of the agent.
Returns: str - The agent’s name

Core Methods

act(observation)

Choose an action based on the current observation. This method must be implemented by subclasses.
Parameters:
  • observation (Any): The current observation of the environment
Returns: Any - The action to take Raises: NotImplementedError if not overridden in subclass

learn(experience)

Learn from experience. This method should be implemented by subclasses that support learning.
Parameters:
  • experience (Any): The experience to learn from (format depends on your implementation)
Returns: None Raises: NotImplementedError if not overridden in subclass

reset()

Reset the agent’s internal state. This is typically called at the beginning of a new episode.
Returns: None

save(path)

Save the agent’s state to a file. This method should be implemented by subclasses.
Parameters:
  • path (str): The file path to save the agent to
Returns: None Raises: NotImplementedError if not overridden in subclass

load(path)

Load the agent’s state from a file. This method should be implemented by subclasses.
Parameters:
  • path (str): The file path to load the agent from
Returns: None Raises: NotImplementedError if not overridden in subclass

Creating Custom Agents

Basic Agent

Create a simple agent by extending the Agent class:

Reinforcement Learning Agent

Create an RL agent with a neural network policy:

Goal-Oriented Agent

Create an agent with specific goals:

Best Practices

1. Always Call Super Constructor

When creating custom agents, always call the parent constructor:

2. Use State Dictionary

The agent has an internal _state dictionary you can use to store episode-specific state:

3. Implement Save/Load for Training

If you’re training agents, implement save and load methods:

4. Reset Agent State

Always reset your agent’s internal state when reset() is called:

API Reference

Agent

Source: neurenix/agent/agent.py:10

See Also