{"record":{"id":"b9e866f44fe857e7","repo":"Unity-Technologies/ml-agents","slug":"config-doesn-t-specify-use-recurrent-please-speci","errorCode":null,"errorMessage":"Config doesn't specify use_recurrent. Please specify true or false for use_recurrent in your config.","messagePattern":"Config doesn't specify use_recurrent\\. Please specify true or false for use_recurrent in your config\\.","errorType":"exception","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/upgrade_config.py","lineNumber":52,"sourceCode":"            new_config = {}\n            new_config[\"trainer_type\"] = trainer_type\n            hyperparam_cls = all_trainer_settings[trainer_type]\n            # Try to absorb as much as possible into the hyperparam_cls\n            new_config[\"hyperparameters\"] = cattr.structure(config, hyperparam_cls)\n\n            # Try to absorb as much as possible into the network settings\n            new_config[\"network_settings\"] = cattr.structure(config, NetworkSettings)\n            # Deal with recurrent\n            try:\n                if config[\"use_recurrent\"]:\n                    new_config[\n                        \"network_settings\"\n                    ].memory = NetworkSettings.MemorySettings(\n                        sequence_length=config[\"sequence_length\"],\n                        memory_size=config[\"memory_size\"],\n                    )\n            except KeyError:\n                raise TrainerConfigError(\n                    \"Config doesn't specify use_recurrent. \"\n                    \"Please specify true or false for use_recurrent in your config.\"\n                )\n            # Absorb the rest into the base TrainerSettings\n            for key, val in config.items():\n                if key in attr.fields_dict(TrainerSettings):\n                    new_config[key] = val\n\n            # Structure the whole thing\n            all_behavior_config_dict[behavior_name] = cattr.structure(\n                new_config, TrainerSettings\n            )\n    return all_behavior_config_dict\n\n\ndef write_to_yaml_file(unstructed_config: Dict[str, Any], output_config: str) -> None:\n    with open(output_config, \"w\") as f:\n        try:","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/upgrade_config.py#L34-L70","documentation":"upgrade_config.convert_behaviors() moves legacy use_recurrent/memory settings into a NetworkSettings.MemorySettings. When the legacy config contains sequence_length/memory_size handling, it also requires the 'use_recurrent' key to decide whether memory settings apply; its absence raises TrainerConfigError.","triggerScenarios":"Running the config upgrade (convert_behaviors via `mlagents-learn --convert-to-config`) on a legacy config that supplies memory fields (or reaches the memory block) but lacks a boolean 'use_recurrent:' entry at the top level.","commonSituations":"Upgrading old LSTM-era configs where use_recurrent was implicit or trimmed; hand-copying config fragments; removing 'use_recurrent: false' during cleanup while keeping sequence_length/memory_size keys.","solutions":["Add `use_recurrent: true` (or `false`) to the legacy config before running the upgrade.","If you don't need memory (LSTM), remove sequence_length and memory_size keys as well and set use_recurrent: false.","Manually migrate the config to the modern format, placing sequence_length/memory under network_settings.memory (only if recurrent), avoiding the upgrader entirely.","Confirm the top-level dict passed to the upgrader isn't missing the key because it was nested under a behavior name."],"exampleFix":"// before\nuse_vis_encoder_size: 64\nsequence_length: 64\nmemory_size: 128\n// after\nuse_recurrent: true\nuse_vis_encoder_size: 64\nsequence_length: 64\nmemory_size: 128","handlingStrategy":"validation","validationCode":"import yaml\n\ndef validate_recurrent_fields(path):\n    cfg = yaml.safe_load(open(path))\n    memory_keys = {\"sequence_length\", \"memory_size\"}\n    if memory_keys & set(cfg) and \"use_recurrent\" not in cfg:\n        raise ValueError(f\"{path} has memory settings but no 'use_recurrent: true|false'\")","typeGuard":"def has_use_recurrent(cfg: dict) -> bool:\n    return isinstance(cfg, dict) and isinstance(cfg.get(\"use_recurrent\"), bool)","tryCatchPattern":"from mlagents.trainers.exception import TrainerConfigError\ntry:\n    convert_behavior_configs(args)\nexcept TrainerConfigError as e:\n    if \"use_recurrent\" in str(e):\n        sys.exit(f\"Config error: add 'use_recurrent: true|false' to your YAML. {e}\")\n    raise","preventionTips":["Pair any sequence_length/memory_size keys with an explicit use_recurrent boolean.","Grep legacy configs for memory settings before upgrading.","Set use_recurrent: false explicitly when you don't need LSTM memory.","Test conversions in CI so missing keys surface before training runs."],"tags":["python","ml-agents","config","yaml","use-recurrent"],"backgroundTag":"missing-config-key","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}