15. Evaluate a multi-agent policy
Use a fresh episode and the same model and space definitions as during training. The excerpt below assumes that env is a configured GamaParallelEnv and that policy accepts an agent identifier and observation and returns a valid action for that agent.
Run an evaluation episode​
PettingZoo's parallel step returns dictionaries of observations, rewards, terminations and truncations. Accumulate rewards by agent, and preserve the distinction between an environment termination and a truncation such as a time limit:
observations, infos = env.reset()
episode_agent_ids = list(observations)
episode_rewards = {agent_id: 0.0 for agent_id in episode_agent_ids}
max_steps = 1000
for _ in range(max_steps):
if not observations:
break
actions = {
agent_id: policy(agent_id, observation)
for agent_id, observation in observations.items()
}
observations, rewards, terminations, truncations, infos = env.step(actions)
for agent_id, reward in rewards.items():
episode_rewards[agent_id] += reward
if all(
terminations.get(agent_id, False) or truncations.get(agent_id, False)
for agent_id in episode_agent_ids
):
break
print(episode_rewards)
env.close()
Choose a positive max_steps appropriate for the model. This loop assumes the GAMA model returns termination or truncation entries for every agent registered at reset; adapt the stop condition if the model uses a different episode lifecycle. The PettingZoo package wrapper and the Forager-specific bridge and training logic have not been validated together, so this example illustrates evaluation over the parallel API and does not report Forager results.
Tutorial summary​
| Part | Method | Main representation |
|---|---|---|
| 1. Tabular Q-learning | GAML implementation | Grid states and a Q-table |
| 2. Continuous forager | Gymnasium bridge | Continuous observations and actions |
| 3. Multi-agent foragers | PettingZoo parallel interface | Per-agent observations, actions and rewards |
The PettingZoo wrapper contract and the package README are not aligned at the referenced revision. The next step shows how to extend the agent identifiers; it does not claim that a ten-agent Forager model has been run or trained.