|
| 1 | +# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | + |
| 3 | +from typing import Type |
| 4 | + |
| 5 | +from examples.rl.environments.countdown.countdown_agent import CountdownAgent |
| 6 | +from examples.rl.environments.math.aime_agent import AIMEAgent |
| 7 | +from examples.rl.environments.math.bigmath_agent import BigMathAgent |
| 8 | +from examples.rl.environments.math.dapo_agent import DAPOAgent |
| 9 | +from examples.rl.environments.math.gsm8k_agent import GSM8KAgent |
| 10 | +from examples.rl.environments.math.openmath_agent import OpenMathInstructAgent |
| 11 | +from megatron.rl.agent.remote_agent import RemoteAgent |
| 12 | + |
| 13 | +AGENT_REGISTRY: dict[str, Type] = { |
| 14 | + "RemoteAgent": RemoteAgent, |
| 15 | + "CountdownAgent": CountdownAgent, |
| 16 | + "OpenMathInstructAgent": OpenMathInstructAgent, |
| 17 | + "BigMathAgent": BigMathAgent, |
| 18 | + "DAPOAgent": DAPOAgent, |
| 19 | + "GSM8KAgent": GSM8KAgent, |
| 20 | + "AIMEAgent": AIMEAgent, |
| 21 | +} |
| 22 | + |
| 23 | +try: |
| 24 | + from nemogym2mrl.nemo_gym_agent import NemoGymAgent |
| 25 | + |
| 26 | + AGENT_REGISTRY["NemoGymAgent"] = NemoGymAgent |
| 27 | +except ImportError: |
| 28 | + pass |
| 29 | + |
| 30 | +try: |
| 31 | + from environments.acemath_agent import AceMathAgent |
| 32 | + |
| 33 | + AGENT_REGISTRY["AceMathAgent"] = AceMathAgent |
| 34 | +except ImportError: |
| 35 | + pass |
| 36 | + |
| 37 | + |
| 38 | +def get_agent_class(agent_name: str) -> Type: |
| 39 | + """Resolve a config agent_type string to a registered agent class. |
| 40 | +
|
| 41 | + Only explicitly registered agent names are allowed. This prevents arbitrary |
| 42 | + code execution from untrusted environment configuration files. |
| 43 | + """ |
| 44 | + try: |
| 45 | + return AGENT_REGISTRY[agent_name] |
| 46 | + except KeyError as exc: |
| 47 | + known = ", ".join(sorted(AGENT_REGISTRY)) |
| 48 | + raise ValueError( |
| 49 | + f"Unknown agent_type {agent_name!r}. " |
| 50 | + f"Registered agent types: {known or '(none)'}" |
| 51 | + ) from exc |
0 commit comments