Skip to main content

Multi-Agent Systems

The MultiAgent class enables you to coordinate multiple agents interacting in a shared environment. This is essential for multi-agent reinforcement learning, competitive/cooperative scenarios, and complex simulations.

MultiAgent Class

The MultiAgent class is defined in neurenix/agent/multi_agent.py and provides functionality for coordinating multiple agents in a shared environment.

Constructor

Parameters:
  • agents (List[Agent]): List of agents in the system
  • environment (Environment): Shared environment for the agents

Properties

agents

The list of agents in the system.

environment

The shared environment for the agents.

step_count

Get the number of steps taken in the current episode.
Returns: int - Number of steps taken

Core Methods

step()

Perform a single step of the multi-agent system. This method:
  1. Gets observations for each agent from the environment
  2. Has each agent select an action based on its observation
  3. Applies all actions to the environment
  4. Returns the results
Returns: Dict[str, Any] - Dictionary containing:
  • observations (dict): Observations for each agent (keyed by agent.id)
  • actions (dict): Actions taken by each agent (keyed by agent.id)
  • rewards (dict): Rewards for each agent (keyed by agent.id)
  • done (bool): Whether the episode is complete
  • info (dict): Additional information from the environment

reset()

Reset the multi-agent system. This method:
  1. Resets the environment
  2. Resets each agent
  3. Returns the initial observations
Returns: Dict[str, Any] - Dictionary containing initial observations for each agent (keyed by agent.id)

add_agent(agent)

Add a new agent to the system.
Parameters:
  • agent (Agent): The agent to add
Returns: None

remove_agent(agent_id)

Remove an agent from the system.
Parameters:
  • agent_id (str): ID of the agent to remove
Returns: Optional[Agent] - The removed agent, or None if not found

Examples

Basic Multi-Agent Simulation

Run a simple multi-agent simulation:

Competitive Multi-Agent RL

Create a competitive multi-agent reinforcement learning scenario:

Cooperative Multi-Agent Task

Create agents that cooperate to achieve a shared goal:

Dynamic Agent Management

Add and remove agents dynamically during simulation:

Best Practices

1. Agents Need an id Attribute

The MultiAgent class uses agent.id to identify agents. Make sure your agents have this attribute:

2. Environment Must Support Multi-Agent

Your environment should handle actions from multiple agents:

3. Register Agents with Environment

If your environment needs to track agents, register them:

4. Handle Episode Termination

Decide when episodes end based on your use case:

API Reference

MultiAgent

Source: neurenix/agent/multi_agent.py:10

See Also