ALFWorld
1. Paper Reading
2. Engineering

2.1 Introduction
2.1.1 Brief
Repo URL: ALFWorld
ALFWorld is a Text-based interaction household task benchmark.
Agent/LLM may receive a text-descripted task:
1 | Your task is to: |
The Environment will feedback continually:
1 | You are in the kitchen. |
e.g.
1 | Agent Step 1: |
2.1.2 Virtual Envs
ALFWorld supports 2 kinds of test: TextWorld and THOR.
1 | ALFWorld |
2.2 Task Structure
Download task dataset (Windows):
1 | conda create -n alfworld python=3.10 |
1 | test@▒ѩ▒ MINGW64 /e/Agent/Datasets |
The main tasks are 2 kinds: valid_seen and valid_unseen
A concrete instance:
1 | test@ѩ▒ MINGW64 /e/Agent/Datasets/ALFWorld/json_2.1.1/valid_seen/look_at_obj_in_light-AlarmClock-None-DeskLamp-323 |
2.2.1 ALFRED & AI2-THOR
ALFRED(Action Learning From Realistic Environments and Directives), is a benchmark for ==Embodied Agent==, based on AI2-THOR.
The benchmark is to solve the kind of problem:
Give the Agent a natural-language instruction and have it complete the task through a sequence of actions in a virtual 3D household environment.
e.g.
1 | Instruction: |
Agent:
1 | Kitchen |
The ==core feature== of ALFRED is:
Demonstrations of humans actually completing tasks in the AI2-THOR environment.
AI2-THOR demonstration:

1 | Human Expert |
e.g.
Task
1
Put the alarm clock in the drawer.
Expert Trajectory:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42Step 0
Observation:
Bedroom
Action:
go to desk
Step 1
Observation:
Alarm clock is on desk
Action:
pickup alarm clock
Step 2
Observation:
Holding alarm clock
Action:
go to drawer
Step 3
Observation:
Drawer is closed
Action:
open drawer
Step 4
Observation:
Drawer is open
Action:
put alarm clock in drawer
Step 5
Goal achieved
The task data of ALFWorld comes from ALFRED:
1 | ALFRED |
2.2.2 traj_data.json
To describe what the task is, including its task type, goal parameters, scene, expert trajectory, etc.
The traj_data.json can be divided into following parts:
1 | traj_data.json |

2.2.2.1 images
images structure:
1
2
3
4
5
6
7
8
9"images": [
...
{
"high_idx": 0,
"image_name": "000000000.png",
"low_idx": 0
}
...
]
2.2.2.2 pddl_params
pddl_params structure:
PDDL(Planning Domain Definition Language) is used to generate a text world.
1
2
3
4
5
6
7"pddl_params": {
"mrecep_target": "",
"object_sliced": false,
"object_target": "AlarmClock",
"parent_target": "",
"toggle_target": "DeskLamp"
}- mrecep_target: movable receptacle
- object_sliced: If object should be sliced
- object_target: target object
- parent_target: parent target
- toggle_target: The switch should be toggled
2.2.2.3 plan
plan main structure:
1
2
3
4"plan": {
"high_pddl": [...],
"low_actions": [...]
}- high_pddl is to describe high-level of expert trajectory. e.g .
- GotoLocation / PickupObject / PutObject /…
- low_actions is to describe concrete actions e.g.
- LookDown / Forward / RotateLeft /
- high_pddl is to describe high-level of expert trajectory. e.g .
high_pddl and low_actions are corresonding
e.g.
1
2
3
4
5
6
7
8
9
10
11
12
13high_pddl[0]
│
├── low_actions[0]
├── low_actions[1]
├── low_actions[2]
├── ...
└── low_actions[n]
high_pddl[1]
│
├── low_actions[n+1]
├── low_actions[n+2]
└── ...1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22high_pddl
│
├── [0] GotoLocation(dresser)
│ │
│ │ high_idx = 0
│ ▼
│ low_actions
│ ├── LookDown_15
│ ├── RotateLeft_90
│ ├── MoveAhead
│ ├── MoveAhead
│ └── ...
│
├── [1] PickupObject(mug)
│ │
│ │ high_idx = 1
│ ▼
│ low_actions
│ ├── ...
│ └── PickupObject
│
└── [2] ...A action description may includes many visual information but TextWorld do not need:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15{
"api_action": {
"action": "ToggleObjectOn",
"objectId": "DeskLamp|..."
},
"discrete_action": {
"action": "ToggleObjectOn",
"args": {
"bbox": [...],
"mask": [...],
"point": [88, 111]
}
},
"high_idx": 3
}
2.2.2.4 scene
“==scene==” is to what is the state of the world when the task begins.
1 | "scene": { |
2.2.2.5 turk_annotations
1 | turk_annotations |
For one same task, there may exists many different annotations:
e.g. 1
Look at an alarm clock by the light of a lamp.
1 | Look at the clock under the lamp. |
For a concrete annotations:
1 | { |
2.2.3 initial_state.pddl
Describe the initial world state of the task.
The initial_state.pddl can be divided into 3 main parts:
1 | initial_state.pddl |
e.g.
object:
1
2
3
4
5
6agent1 - agent
Mug_xxx - object
MugType - otype
Desk_xxx - receptacle
DeskType - rtype
loc_xxx - locationinit:
1
2
3
4(atLocation agent1 loc_xxx)
(inReceptacle Mug_xxx Desk_xxx)
(pickupable Mug_xxx)
(openable Drawer_xxx)goal:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24(:goal
(and
(exists (?ot - object
?r - receptacle
?a - agent
?l - location)
(and
(objectType ?ot DeskLampType)
(toggleable ?ot)
(isToggled ?ot)
(receptacleAtLocation ?r ?l)
(atLocation ?a ?l)
(inReceptacle ?ot ?r)
)
)
(exists (?o - object
?a - agent)
(and
(objectType ?o AlarmClockType)
(holds ?a ?o)
)
)
)
)
2.2.4 game.tw-pddl
Convert the task into game rules that can be executed by TextWorld.
1 | game.tw-pddl |
The game.tw-ddl is composed of different parts:
1 | python -c "import json; d=json.load(open('game.tw-pddl', encoding='utf-8'), strict=False); open('domain.pddl','w',encoding='utf-8').write(d['pddl_domain']); open('problem.pddl','w',encoding='utf-8').write(d['pddl_problem']); open('grammar.txt','w',encoding='utf-8').write(str(d['grammar'])); open('walkthrough.txt','w',encoding='utf-8').write(str(d['walkthrough'])); print('solvable =', d['solvable'])" |
2.2.5 Summary
| File | Function | Child Item |
|---|---|---|
traj_data.json |
Task / Expert Trajectory | task、pddl_params、scene、plan、turk_annotations、images
… |
initial_state.pddl |
****The symbolic state and goal of the task**** | :objects、:init、:goal |
game.tw-pddl |
Change Task into TextWorld Game | pddl_domain、pddl_problem、grammar、solvable、walkthrough |
2.3 Task Workflow
2.3.1 Entrance
alfworld/scripts/run_eval.py
1 | def run_eval(): |
2.3.2 Collect Game List
alfworld/alfworld/agents/environment/alfred_tw_env.py:118
1 | def __init__(self, config, train_eval="train"): |
2.3.3 Start TextWorld
alfworld/alfworld/agents/environment/alfred_tw_env.py:245
1 | def init_env(self, batch_size): |
Core code:
1 | env_id = textworld.gym.register_games( |
game_files is the set of game.tw-pddl
Gym is a standardized environment for agents to interact
with.
2.3.4 Evaluation
1 | def evaluate_dagger(env, agent, num_games, debug=False): |
Input for Agent like:
1 | Task: |
1 | action_candidate_list = list(infos["admissible_commands"]) |
Start Loop:
1 | for step_no in range(agent.max_nb_steps_per_episode): |