self-evolve-framework 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/package.json +1 -1
  2. package/template/skills/skillopt-sleep/SKILL.md +42 -0
  3. package/template/skills/skillopt-sleep/configs/_base_/default.yaml +103 -0
  4. package/template/skills/skillopt-sleep/configs/alfworld/default.yaml +29 -0
  5. package/template/skills/skillopt-sleep/configs/docvqa/default.yaml +28 -0
  6. package/template/skills/skillopt-sleep/configs/features/soft_gate.yaml +47 -0
  7. package/template/skills/skillopt-sleep/configs/livemathematicianbench/default.yaml +22 -0
  8. package/template/skills/skillopt-sleep/configs/officeqa/default.yaml +34 -0
  9. package/template/skills/skillopt-sleep/configs/searchqa/default.yaml +32 -0
  10. package/template/skills/skillopt-sleep/configs/spreadsheetbench/default.yaml +34 -0
  11. package/template/skills/skillopt-sleep/scripts/framework/skillopt/__init__.py +28 -0
  12. package/template/skills/skillopt-sleep/scripts/framework/skillopt/config.py +282 -0
  13. package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/__init__.py +7 -0
  14. package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/base.py +512 -0
  15. package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/__init__.py +9 -0
  16. package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/trainer.py +2379 -0
  17. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/__init__.py +1 -0
  18. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/README.md +43 -0
  19. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/config_template.yaml +55 -0
  20. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/env_template.py +151 -0
  21. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/loader_template.py +87 -0
  22. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/__init__.py +5 -0
  23. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/adapter.py +428 -0
  24. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/dataloader.py +123 -0
  25. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_error.md +55 -0
  26. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_success.md +33 -0
  27. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_no_history.md +8 -0
  28. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_history.md +9 -0
  29. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_memory.md +16 -0
  30. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/reflect.py +4 -0
  31. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/rollout.py +366 -0
  32. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/skills/initial.md +45 -0
  33. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/__init__.py +9 -0
  34. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_envs.py +221 -0
  35. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_projection.py +60 -0
  36. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_prompts.py +8 -0
  37. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/config_tw.yaml +145 -0
  38. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_base.py +84 -0
  39. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_manager.py +139 -0
  40. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/memory.py +87 -0
  41. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/base.py +329 -0
  42. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/__init__.py +1 -0
  43. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/adapter.py +90 -0
  44. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/dataloader.py +61 -0
  45. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/evaluator.py +113 -0
  46. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_error.md +35 -0
  47. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_success.md +24 -0
  48. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/rollout_system.md +12 -0
  49. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/rollout.py +391 -0
  50. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/skills/initial.md +11 -0
  51. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/__init__.py +1 -0
  52. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/adapter.py +129 -0
  53. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/dataloader.py +308 -0
  54. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/evaluator.py +62 -0
  55. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_error.md +37 -0
  56. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_success.md +25 -0
  57. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/rollout_system.md +12 -0
  58. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/reflect.py +4 -0
  59. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/rollout.py +434 -0
  60. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/skills/initial.md +16 -0
  61. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/__init__.py +1 -0
  62. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/adapter.py +112 -0
  63. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/dataloader.py +71 -0
  64. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/evaluator.py +46 -0
  65. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_error.md +37 -0
  66. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_success.md +25 -0
  67. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/rollout_system.md +15 -0
  68. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/rollout.py +799 -0
  69. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/skills/initial.md +15 -0
  70. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/tool_runtime.py +552 -0
  71. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/__init__.py +1 -0
  72. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/adapter.py +96 -0
  73. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/dataloader.py +42 -0
  74. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/evaluator.py +100 -0
  75. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_error.md +46 -0
  76. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_success.md +32 -0
  77. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/rollout_system.md +13 -0
  78. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/reflect.py +4 -0
  79. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/rollout.py +494 -0
  80. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/skills/initial.md +3 -0
  81. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/__init__.py +5 -0
  82. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/adapter.py +159 -0
  83. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/codegen_agent.py +731 -0
  84. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/dataloader.py +37 -0
  85. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/evaluator.py +158 -0
  86. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/executor.py +67 -0
  87. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_error.md +46 -0
  88. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_success.md +32 -0
  89. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/codegen_system.md +1 -0
  90. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/critical_rules.md +9 -0
  91. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/react_system.md +21 -0
  92. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/react_agent.py +395 -0
  93. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/reflect.py +4 -0
  94. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/rollout.py +979 -0
  95. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/skills/initial.md +56 -0
  96. package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/__init__.py +13 -0
  97. package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/gate.py +148 -0
  98. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/__init__.py +15 -0
  99. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/aggregate.py +253 -0
  100. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/reflect.py +635 -0
  101. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/__init__.py +514 -0
  102. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/azure_openai.py +915 -0
  103. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/backend_config.py +185 -0
  104. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/claude_backend.py +371 -0
  105. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_backend.py +666 -0
  106. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_harness.py +1057 -0
  107. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/common.py +229 -0
  108. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/minimax_backend.py +277 -0
  109. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/qwen_backend.py +456 -0
  110. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/router.py +236 -0
  111. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/__init__.py +15 -0
  112. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/appendix.py +156 -0
  113. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/clip.py +109 -0
  114. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/lr_autonomous.py +108 -0
  115. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/meta_skill.py +79 -0
  116. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/rewrite.py +59 -0
  117. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/scheduler.py +127 -0
  118. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/select.py +4 -0
  119. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill.py +201 -0
  120. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill_aware.py +206 -0
  121. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/slow_update.py +396 -0
  122. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/update_modes.py +135 -0
  123. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/__init__.py +63 -0
  124. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error.md +41 -0
  125. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_full_rewrite.md +32 -0
  126. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_rewrite.md +44 -0
  127. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success.md +36 -0
  128. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_full_rewrite.md +30 -0
  129. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_rewrite.md +33 -0
  130. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/lr_autonomous.md +20 -0
  131. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure.md +30 -0
  132. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_full_rewrite.md +28 -0
  133. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_rewrite.md +26 -0
  134. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final.md +33 -0
  135. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_full_rewrite.md +28 -0
  136. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_rewrite.md +25 -0
  137. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success.md +28 -0
  138. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_full_rewrite.md +28 -0
  139. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_rewrite.md +25 -0
  140. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/meta_skill.md +40 -0
  141. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking.md +20 -0
  142. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking_rewrite.md +15 -0
  143. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/rewrite_skill.md +25 -0
  144. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/slow_update.md +60 -0
  145. package/template/skills/skillopt-sleep/scripts/framework/skillopt/scheduler/__init__.py +8 -0
  146. package/template/skills/skillopt-sleep/scripts/framework/skillopt/types.py +306 -0
  147. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/__init__.py +4 -0
  148. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/json_utils.py +172 -0
  149. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/scoring.py +28 -0
@@ -0,0 +1,60 @@
1
+ # Vendored from SkillRL (Apache-2.0 License)
2
+ # Original: agent_system/environments/env_package/alfworld/projection.py
3
+
4
+ from typing import List
5
+ import re
6
+
7
+
8
+ def alfworld_projection(actions: List[str], action_pools: List[List[str]]):
9
+ """Process raw model outputs into valid ALFWorld actions.
10
+
11
+ Extracts text from ``<action>...</action>`` tags and validates that
12
+ the response also contains ``<think>...</think>`` tags.
13
+
14
+ Parameters
15
+ ----------
16
+ actions : list[str]
17
+ Raw model outputs, one per environment.
18
+ action_pools : list[list[str]]
19
+ Admissible action lists per environment (unused but kept for API compat).
20
+
21
+ Returns
22
+ -------
23
+ actions : list[str]
24
+ Cleaned action strings.
25
+ valids : list[int]
26
+ 1 if the action was successfully parsed, 0 otherwise.
27
+ """
28
+ valids = [0] * len(actions)
29
+
30
+ for i in range(len(actions)):
31
+ original_str = actions[i]
32
+ actions[i] = actions[i].lower()
33
+
34
+ start_tag = "<action>"
35
+ end_tag = "</action>"
36
+ start_idx = actions[i].find(start_tag)
37
+ end_idx = actions[i].find(end_tag)
38
+ try:
39
+ if start_idx == -1 or end_idx == -1:
40
+ actions[i] = actions[i][-30:]
41
+ continue
42
+
43
+ extracted_action = actions[i][start_idx + len(start_tag):end_idx].strip().lower()
44
+ actions[i] = extracted_action
45
+ valids[i] = 1
46
+
47
+ except Exception:
48
+ actions[i] = actions[i][-30:]
49
+
50
+ # Require <think>...</think>
51
+ think_start_idx = original_str.find("<think>")
52
+ think_end_idx = original_str.find("</think>")
53
+ if think_start_idx == -1 or think_end_idx == -1:
54
+ valids[i] = 0
55
+
56
+ # Reject responses containing Chinese characters
57
+ if re.search(r'[\u4e00-\u9fff]', original_str):
58
+ valids[i] = 0
59
+
60
+ return actions, valids
@@ -0,0 +1,8 @@
1
+ # Vendored from SkillRL (Apache-2.0 License)
2
+ # Original: agent_system/environments/prompts/alfworld.py
3
+
4
+ from skillopt.prompts import load_prompt
5
+
6
+ ALFWORLD_TEMPLATE_NO_HIS = load_prompt("rollout_no_history", env="alfworld")
7
+ ALFWORLD_TEMPLATE = load_prompt("rollout_with_history", env="alfworld")
8
+ ALFWORLD_TEMPLATE_WITH_MEMORY = load_prompt("rollout_with_memory", env="alfworld")
@@ -0,0 +1,145 @@
1
+ dataset:
2
+ data_path: '$ALFWORLD_DATA/json_2.1.1/train'
3
+ eval_id_data_path: '$ALFWORLD_DATA/json_2.1.1/valid_seen' # null/None to disable
4
+ eval_ood_data_path: '$ALFWORLD_DATA/json_2.1.1/valid_unseen' # null/None to disable
5
+ num_train_games: -1 # max training games (<=0 indicates full dataset)
6
+ num_eval_games: -1 # max evaluation games (<=0 indicates full dataset)
7
+
8
+ logic:
9
+ domain: '$ALFWORLD_DATA/logic/alfred.pddl' # PDDL domain file that defines the world dynamics
10
+ grammar: '$ALFWORLD_DATA/logic/alfred.twl2' # Grammar file that defines the text feedbacks
11
+
12
+ env:
13
+ type: 'AlfredTWEnv' # 'AlfredTWEnv' or 'AlfredThorEnv' or 'AlfredHybrid'
14
+ # regen_game_files: False # check if game is solvable by expert and save to game.tw-pddl file
15
+ domain_randomization: False # shuffle Textworld print order and object id nums
16
+ task_types: [1, 2, 3, 4, 5, 6] # task-type ids: 1 - Pick & Place, 2 - Examine in Light, 3 - Clean & Place, 4 - Heat & Place, 5 - Cool & Place, 6 - Pick Two & Place
17
+ expert_timeout_steps: 150 # max steps before timeout for expert to solve the task
18
+ expert_type: "handcoded" # 'handcoded' or 'planner'. Note: the planner is very slow for real-time use
19
+ goal_desc_human_anns_prob: 0.0 # prob of using human-annotated goal language instead of templated goals (1.0 indicates all human annotations from ALFRED)
20
+
21
+ hybrid:
22
+ start_eps: 100000 # starting episode of hybrid training, tw-only training upto this point
23
+ thor_prob: 0.5 # prob of AlfredThorEnv during hybrid training
24
+ eval_mode: "tw" # 'tw' or 'thor' - env used for evaluation during hybrid training
25
+
26
+ thor:
27
+ screen_width: 300 # width of THOR window
28
+ screen_height: 300 # height of THOR window
29
+ smooth_nav: False # smooth rotations, looks, and translations during navigation (very slow)
30
+ save_frames_to_disk: False # save frame PNGs to disk (useful for making videos)
31
+ save_frames_path: './videos/' # path to save frame PNGs
32
+
33
+ controller:
34
+ type: 'oracle' # 'oracle' or 'oracle_astar' or 'mrcnn' or 'mrcnn_astar' (aka BUTLER)
35
+ debug: False
36
+ load_receps: True # load receptacle locations from precomputed dict (if available)
37
+
38
+ mask_rcnn:
39
+ pretrained_model_path: '$ALFWORLD_DATA/detectors/mrcnn.pth'
40
+
41
+ general:
42
+ random_seed: 42
43
+ use_cuda: True # disable this when running on machine without cuda
44
+ visdom: False # plot training/eval curves, run with visdom server
45
+ task: 'alfred'
46
+ training_method: 'dagger' # 'dqn' or 'dagger'
47
+ save_path: './training/' # path to save pytorch models
48
+ observation_pool_capacity: 3 # k-size queue, 0 indicates no observation
49
+ hide_init_receptacles: False # remove initial observation containing navigable receptacles
50
+
51
+ training:
52
+ batch_size: 10
53
+ max_episode: 50000
54
+ smoothing_eps: 0.1
55
+ optimizer:
56
+ learning_rate: 0.001
57
+ clip_grad_norm: 5
58
+
59
+ evaluate:
60
+ run_eval: True
61
+ batch_size: 10
62
+ env:
63
+ type: "AlfredTWEnv"
64
+
65
+ checkpoint:
66
+ report_frequency: 1000 # report every N episode
67
+ experiment_tag: 'test' # name of experiment
68
+ load_pretrained: False # during test, enable this so that the agent load your pretrained model
69
+ load_from_tag: 'not loading anything' # name of pre-trained model to load in save_path
70
+
71
+ model:
72
+ encoder_layers: 1
73
+ decoder_layers: 1
74
+ encoder_conv_num: 5
75
+ block_hidden_dim: 64
76
+ n_heads: 1
77
+ dropout: 0.1
78
+ block_dropout: 0.1
79
+ recurrent: True
80
+
81
+ rl:
82
+ action_space: "admissible" # 'admissible' (candidates from text engine) or 'generation' (seq2seq-style generation) or 'beam_search_choice' or 'exhaustive' (not working)
83
+ max_target_length: 20 # max token length for seq2seq generation
84
+ beam_width: 10 # 1 means greedy
85
+ generate_top_k: 3
86
+
87
+ training:
88
+ max_nb_steps_per_episode: 50 # terminate after this many steps
89
+ learn_start_from_this_episode: 0 # delay updates until this epsiode
90
+ target_net_update_frequency: 500 # sync target net with online net per this many epochs
91
+
92
+ replay:
93
+ accumulate_reward_from_final: True
94
+ count_reward_lambda: 0.0 # 0 to disable
95
+ novel_object_reward_lambda: 0.0 # 0 to disable
96
+ discount_gamma_game_reward: 0.9
97
+ discount_gamma_count_reward: 0.5
98
+ discount_gamma_novel_object_reward: 0.5
99
+ replay_memory_capacity: 500000 # adjust this depending on your RAM size
100
+ replay_memory_priority_fraction: 0.5
101
+ update_per_k_game_steps: 5
102
+ replay_batch_size: 64
103
+ multi_step: 3
104
+ replay_sample_history_length: 4
105
+ replay_sample_update_from: 2
106
+
107
+ epsilon_greedy:
108
+ noisy_net: False # if this is true, then epsilon greedy is disabled
109
+ epsilon_anneal_episodes: 1000 # -1 if not annealing
110
+ epsilon_anneal_from: 0.3
111
+ epsilon_anneal_to: 0.1
112
+
113
+ dagger:
114
+ action_space: "generation" # 'admissible' (candidates from text engine) or 'generation' (seq2seq-style generation) or 'exhaustive' (not working)
115
+ max_target_length: 20 # max token length for seq2seq generation
116
+ beam_width: 10 # 1 means greedy
117
+ generate_top_k: 5
118
+ unstick_by_beam_search: False # use beam-search for failed actions, set True during evaluation
119
+
120
+ training:
121
+ max_nb_steps_per_episode: 50 # terminate after this many steps
122
+
123
+ fraction_assist:
124
+ fraction_assist_anneal_episodes: 50000
125
+ fraction_assist_anneal_from: 1.0
126
+ fraction_assist_anneal_to: 0.01
127
+
128
+ fraction_random:
129
+ fraction_random_anneal_episodes: 0
130
+ fraction_random_anneal_from: 0.0
131
+ fraction_random_anneal_to: 0.0
132
+
133
+ replay:
134
+ replay_memory_capacity: 500000
135
+ update_per_k_game_steps: 5
136
+ replay_batch_size: 64
137
+ replay_sample_history_length: 4
138
+ replay_sample_update_from: 2
139
+
140
+ vision_dagger:
141
+ model_type: "resnet" # 'resnet' (whole image features) or 'maskrcnn_whole' (whole image MaskRCNN feats) or 'maskrcnn' (top k MaskRCNN detection feats) or 'no_vision' (zero vision input)
142
+ resnet_fc_dim: 64
143
+ maskrcnn_top_k_boxes: 10 # top k box features
144
+ use_exploration_frame_feats: False # append feats from initial exploration (memory intensive!)
145
+ sequence_aggregation_method: "average" # 'sum' or 'average' or 'rnn'
@@ -0,0 +1,84 @@
1
+ # Vendored from SkillRL (Apache-2.0 License)
2
+ # Original: agent_system/environments/base.py
3
+ # Trimmed to only include what ALFWorld needs.
4
+
5
+ from typing import List, Tuple, Dict, Any
6
+ import numpy as np
7
+ from collections import defaultdict
8
+
9
+
10
+ def to_numpy(data):
11
+ """Convert data to numpy array."""
12
+ # Lazy-check for torch.Tensor to avoid hard dependency on torch
13
+ _torch_tensor = None
14
+ try:
15
+ import torch
16
+ _torch_tensor = torch.Tensor
17
+ except ImportError:
18
+ pass
19
+
20
+ if _torch_tensor is not None and isinstance(data, _torch_tensor):
21
+ data = data.detach().cpu().numpy()
22
+ elif isinstance(data, np.ndarray):
23
+ pass
24
+ elif isinstance(data, (int, float, bool, Tuple, List)):
25
+ data = np.array(data)
26
+ else:
27
+ raise ValueError(f"Unsupported type: {type(data)})")
28
+ return data
29
+
30
+
31
+ class EnvironmentManagerBase:
32
+ """Base class for vectorized environment managers.
33
+
34
+ Manages a set of parallel environments, handles action projection,
35
+ observation post-processing, and history tracking.
36
+ """
37
+
38
+ def __init__(self, envs, projection_f, config):
39
+ self.envs = envs
40
+ self.projection_f = projection_f
41
+ self.config = config
42
+
43
+ def reset(self, kwargs) -> Dict[str, Any]:
44
+ obs, infos = self.envs.reset()
45
+ return {'text': None, 'image': obs, 'anchor': None}, infos
46
+
47
+ def step(self, text_actions: List[str]):
48
+ actions, valids = self.projection_f(text_actions)
49
+ next_obs, rewards, dones, infos = self.envs.step(actions)
50
+
51
+ next_observations = {
52
+ 'text': None,
53
+ 'image': next_obs,
54
+ 'anchor': None,
55
+ }
56
+ for i, info in enumerate(infos):
57
+ info['is_action_valid'] = to_numpy(valids[i])
58
+
59
+ rewards = to_numpy(rewards)
60
+ dones = to_numpy(dones)
61
+ return next_observations, rewards, dones, infos
62
+
63
+ def close(self) -> None:
64
+ self.envs.close()
65
+
66
+ def success_evaluator(self, *args, **kwargs) -> Dict[str, np.ndarray]:
67
+ total_infos = kwargs['total_infos']
68
+ total_batch_list = kwargs['total_batch_list']
69
+ batch_size = len(total_batch_list)
70
+
71
+ success = defaultdict(list)
72
+ for bs in range(batch_size):
73
+ self._process_batch(bs, total_batch_list, total_infos, success)
74
+ assert len(success['success_rate']) == batch_size
75
+ return {key: np.array(value) for key, value in success.items()}
76
+
77
+ def _process_batch(self, batch_idx, total_batch_list, total_infos, success):
78
+ for i in reversed(range(len(total_batch_list[batch_idx]))):
79
+ batch_item = total_batch_list[batch_idx][i]
80
+ if batch_item['active_masks']:
81
+ info = total_infos[batch_idx][i]
82
+ won_value = float(info['won'])
83
+ success['success_rate'].append(won_value)
84
+ return
@@ -0,0 +1,139 @@
1
+ # Vendored from SkillRL (Apache-2.0 License)
2
+ # Original: agent_system/environments/env_manager.py
3
+ # Trimmed to only include AlfWorldEnvironmentManager and its helpers.
4
+
5
+ from typing import List, Dict, Any
6
+ from collections import defaultdict
7
+ import numpy as np
8
+
9
+ from skillopt.envs.alfworld.vendor.env_base import EnvironmentManagerBase, to_numpy
10
+ from skillopt.envs.alfworld.vendor.alfworld_prompts import (
11
+ ALFWORLD_TEMPLATE,
12
+ ALFWORLD_TEMPLATE_NO_HIS,
13
+ ALFWORLD_TEMPLATE_WITH_MEMORY,
14
+ )
15
+ from skillopt.envs.alfworld.vendor.memory import SimpleMemory
16
+
17
+
18
+ def parse_gamefile(infos):
19
+ gamefile = []
20
+ for info in infos:
21
+ if 'extra.gamefile' in info:
22
+ gamefile.append(info['extra.gamefile'])
23
+ else:
24
+ gamefile.append(None)
25
+ return gamefile
26
+
27
+
28
+ def set_gamefile(infos, gamefile):
29
+ for i in range(len(infos)):
30
+ if 'extra.gamefile' in infos[i]:
31
+ infos[i]['extra.gamefile'] = gamefile[i]
32
+ else:
33
+ infos[i]['extra.gamefile'] = None
34
+ return infos
35
+
36
+
37
+ class AlfWorldEnvironmentManager(EnvironmentManagerBase):
38
+ """Manages parallel ALFWorld environments with observation templating."""
39
+
40
+ def __init__(self, envs, projection_f, config):
41
+ self.memory = SimpleMemory()
42
+ self.retrieval_memory = None
43
+ super().__init__(envs, projection_f, config)
44
+
45
+ def reset(self, kwargs):
46
+ text_obs, image_obs, infos = self.envs.reset()
47
+ self.gamefile = parse_gamefile(infos)
48
+ self.memory.reset(batch_size=len(text_obs))
49
+ self.tasks = []
50
+ self.pre_text_obs = text_obs
51
+ self.extract_task(text_obs)
52
+
53
+ full_text_obs = self.build_text_obs(text_obs, self.envs.get_admissible_commands, init=True)
54
+ return {'text': full_text_obs, 'image': image_obs, 'anchor': text_obs}, infos
55
+
56
+ def step(self, text_actions: List[str]):
57
+ actions, valids = self.projection_f(text_actions, self.envs.get_admissible_commands)
58
+ text_obs, image_obs, rewards, dones, infos = self.envs.step(actions)
59
+ self.memory.store({'text_obs': self.pre_text_obs, 'action': actions})
60
+ self.pre_text_obs = text_obs
61
+
62
+ full_text_obs = self.build_text_obs(text_obs, self.envs.get_admissible_commands)
63
+ if infos[0].get("extra.gamefile") is None:
64
+ infos = set_gamefile(infos, self.gamefile)
65
+
66
+ for i, info in enumerate(infos):
67
+ info['is_action_valid'] = to_numpy(valids[i])
68
+
69
+ next_observations = {'text': full_text_obs, 'image': image_obs, 'anchor': text_obs}
70
+ rewards = to_numpy(rewards)
71
+ dones = to_numpy(dones)
72
+ return next_observations, rewards, dones, infos
73
+
74
+ def extract_task(self, text_obs: List[str]):
75
+ for obs in text_obs:
76
+ task_start = obs.find('Your task is to: ')
77
+ if task_start != -1:
78
+ self.tasks.append(obs[task_start + len('Your task is to: '):].strip())
79
+ else:
80
+ raise ValueError("Task description not found in text observation.")
81
+
82
+ def build_text_obs(self, text_obs: List[str], admissible_actions: List[List[str]], init: bool = False) -> List[str]:
83
+ postprocess_text_obs = []
84
+ if not init and self.config.env.history_length > 0:
85
+ memory_contexts, valid_lens = self.memory.fetch(
86
+ self.config.env.history_length,
87
+ obs_key="text_obs",
88
+ action_key="action",
89
+ )
90
+
91
+ for i in range(len(text_obs)):
92
+ reformatted_admissible_actions = "\n ".join(
93
+ f"'{s}'" for s in admissible_actions[i] if s != 'help'
94
+ )
95
+
96
+ if init or self.config.env.history_length <= 0:
97
+ obs = ALFWORLD_TEMPLATE_NO_HIS.format(
98
+ current_observation=text_obs[i],
99
+ admissible_actions=reformatted_admissible_actions,
100
+ )
101
+ else:
102
+ obs = ALFWORLD_TEMPLATE.format(
103
+ task_description=self.tasks[i],
104
+ step_count=len(self.memory[i]),
105
+ history_length=valid_lens[i],
106
+ action_history=memory_contexts[i],
107
+ current_step=len(self.memory[i]) + 1,
108
+ current_observation=text_obs[i],
109
+ admissible_actions=reformatted_admissible_actions,
110
+ )
111
+ postprocess_text_obs.append(obs)
112
+ return postprocess_text_obs
113
+
114
+ def _process_batch(self, batch_idx, total_batch_list, total_infos, success):
115
+ for i in reversed(range(len(total_batch_list[batch_idx]))):
116
+ batch_item = total_batch_list[batch_idx][i]
117
+ if batch_item['active_masks']:
118
+ info = total_infos[batch_idx][i]
119
+ won_value = float(info['won'])
120
+ success['success_rate'].append(won_value)
121
+
122
+ gamefile = info.get("extra.gamefile")
123
+ if gamefile:
124
+ self._process_gamefile(gamefile, won_value, success)
125
+ return
126
+
127
+ def _process_gamefile(self, gamefile, won_value, success):
128
+ tasks = [
129
+ "pick_and_place",
130
+ "pick_two_obj_and_place",
131
+ "look_at_obj_in_light",
132
+ "pick_heat_then_place_in_recep",
133
+ "pick_cool_then_place_in_recep",
134
+ "pick_clean_then_place_in_recep",
135
+ ]
136
+ for task in tasks:
137
+ if task in gamefile:
138
+ success[f"{task}_success_rate"].append(won_value)
139
+ break
@@ -0,0 +1,87 @@
1
+ # Vendored from SkillRL (Apache-2.0 License)
2
+ # Original: agent_system/memory/base.py + agent_system/memory/memory.py
3
+ # Merged into a single file for simplicity.
4
+
5
+ from abc import ABC, abstractmethod
6
+ from typing import List, Dict, Any, Tuple
7
+
8
+
9
+ class BaseMemory(ABC):
10
+ """Base class for memory management."""
11
+
12
+ @abstractmethod
13
+ def __len__(self):
14
+ pass
15
+
16
+ @abstractmethod
17
+ def __getitem__(self, idx: int):
18
+ pass
19
+
20
+ @abstractmethod
21
+ def reset(self, batch_size: int):
22
+ pass
23
+
24
+ @abstractmethod
25
+ def store(self, record: Dict[str, List[Any]]):
26
+ pass
27
+
28
+ @abstractmethod
29
+ def fetch(self, step: int):
30
+ pass
31
+
32
+
33
+ class SimpleMemory(BaseMemory):
34
+ """Per-environment history buffer for storing observations and actions."""
35
+
36
+ def __init__(self):
37
+ self._data = None
38
+ self.keys = None
39
+ self.batch_size = 0
40
+
41
+ def __len__(self):
42
+ return len(self._data)
43
+
44
+ def __getitem__(self, idx):
45
+ return self._data[idx]
46
+
47
+ def reset(self, batch_size: int):
48
+ if self._data is not None:
49
+ self._data.clear()
50
+ self._data = [[] for _ in range(batch_size)]
51
+ self.batch_size = batch_size
52
+ self.keys = None
53
+
54
+ def store(self, record: Dict[str, List[Any]]):
55
+ if self.keys is None:
56
+ self.keys = list(record.keys())
57
+ assert self.keys == list(record.keys())
58
+
59
+ for env_idx in range(self.batch_size):
60
+ self._data[env_idx].append({k: record[k][env_idx] for k in self.keys})
61
+
62
+ def fetch(
63
+ self,
64
+ history_length: int,
65
+ obs_key: str = "text_obs",
66
+ action_key: str = "action",
67
+ ) -> Tuple[List[str], List[int]]:
68
+ memory_contexts, valid_lengths = [], []
69
+
70
+ for env_idx in range(self.batch_size):
71
+ recent = self._data[env_idx][-history_length:]
72
+ valid_len = len(recent)
73
+ start_idx = len(self._data[env_idx]) - valid_len
74
+
75
+ lines = []
76
+ for j, rec in enumerate(recent):
77
+ step_num = start_idx + j + 1
78
+ act = rec[action_key]
79
+ obs = rec[obs_key]
80
+ lines.append(
81
+ f"[Observation {step_num}: '{obs}', Action {step_num}: '{act}']"
82
+ )
83
+
84
+ memory_contexts.append("\n".join(lines))
85
+ valid_lengths.append(valid_len)
86
+
87
+ return memory_contexts, valid_lengths