9 · The world master at work¶
A real class is never complete. Students arrive in the middle of a lecture, laptops go to sleep during the exam and people close the browser. The teacher of the classroom is the world master and it must keep the community working through all of this. Besides examining the students, it asks them to label pictures that nobody labeled and adds the pictures they agree on to its lectures. The community thus improves the material it learns from.
Students who come and go¶
The teacher never keeps a fixed list of students. Every action that addresses the class calls self.get_agents_by_role("student") at the moment it runs. A student who joined a minute ago therefore receives the next announcement and the next lecture. A student who arrives in the middle of a lecture waits in in_class until the next request reaches it.
A student who leaves in the middle of an activity does not block the class. The teacher records the reason DISCONNECTED for that student. The interaction is complete once every student has a completion reason of any kind. The callback then runs once and the lecture or the exam ends normally for the others.
When the last student leaves, the teacher has nobody to teach. It checks this condition at every cycle in on_tick and goes back to init, where it waits for new students:
async def on_tick(self):
await super().on_tick()
if len(self.get_agents_by_role("student")) == 0 and self.behav.get_state_name() != "init":
await self.behav.act_ghost_transition("init")
The check lives in on_tick and not in the behavior because it applies to every state. A teleport from every state could express the same rule but would need an extra action that tests the condition.
The students recover on their side as well. A student that loses its teacher takes the teleport disconnected to wait_to_recover and waits 60 seconds. It then starts again from init and looks for a teacher with connect_by_role. When the teacher comes back, every student finds it again without any intervention.
Pausing the class¶
The teacher terminal accepts one command: the space bar. on_tick reads the keyboard without blocking and toggles a pause flag. While the flag is on, it calls self.behav.enable(False) at every cycle and the behavior stops after the current activity. A second press resumes the class. The keyboard handling runs only when the standard input is a terminal. It imports the terminal modules inside the method so that the role file still loads on every operating system.
Asking the class for help¶
After the exam the teacher has a quality index for every student. The feedback stage puts that index to use:
ask_for_feedbackannounces the stage with a notice.send_requestssendsprocessto every student with two unlabeled pictures. Both streams of the groupfeedbackgo onstdinand the class names of the group are allunknown.on_data(stream_group="feedback")records what goes out and what comes back in the same way as during the exam.augment_lectureswaits for the callbackmark_feedback_as_providedand then aggregates the answers.
The aggregation trusts only the students whose quality index is at least FEEDBACK_QUALITY_THRESHOLD (0.6). For each picture, it counts the answers of the trusted students and takes the class with the most votes:
for tag, (img, _) in self.sent_samples.items():
votes, best, best_class = {}, 0, None
for student, answer in self.received_samples.get(tag, {}).items():
if self.student_quality.get(student, 0.) >= self.FEEDBACK_QUALITY_THRESHOLD:
answer = answer.strip().capitalize()
votes[answer] = votes.get(answer, 0) + 1
if votes[answer] > best:
best, best_class = votes[answer], answer
if best_class in self.class_name_to_lecture_streams:
img_stream, names_stream = self.class_name_to_lecture_streams[best_class]
# save the picture as data/lectures/<n>/<next number>_<class>.jpg, then:
img_stream.add(file_name)
names_stream.add(best_class)
The picture joins the lecture of its class on disk and in the streams of that lecture. The next round of lectures shows it to every student. The students taught the teacher something and the teacher now teaches it to the whole class. The newcomers who missed the feedback stage learn it too.
The final world (run_world.py in the parent folder) removes the pictures added in this way every time the world starts. Each demonstration therefore begins from the original material.
Roles that change¶
A world master can do more than lead activities. It can ask the world to change the role of a member with the built-in action suggest_role_to_world(agent, role). The world applies the suggestions of its masters with set_role and ignores those of the other members. The member then switches to the class and the behavior of its new role (chapter 3). A teaching world can use this to promote a student who passes every exam to a tutor of the newcomers.
Badges¶
A badge is a public recognition that the world gives to an agent. It has a score in [0, 1], a type among completed, attended, intermediate and pro and an optional description. The world publishes its badges with the updates of its profile. A world master suggests badges with the built-in action suggest_badges_to_world(agent, score, badge_type, badge_description). The world node adds every suggestion that reaches it and does not check whether the sender is a master. Chapter 10 shows how the world adds badges itself with add_badge.
Other masters in the examples¶
The classroom has one teacher. Other worlds of the examples repository show different ways of leading:
unaiverse-examples/worlds/class_incremental_learningkeeps the roster current while a teacher fans lessons out to a group of students and examines them cumulatively. Its world awards a badge to the best student so far.unaiverse-examples/worlds/social_learningmakes only the first world master a teacher. With the join optionrole_preferencea student can ask for an isolated role. The world can then compare students who learn from each other with students who learn alone.
Where next¶
The class runs and improves itself. Chapter 10 records what happens in it, shows it on the page of the world and prepares the world for other people.