service.inclass.functions.readScript module
- class service.inclass.functions.readScript.ReadScript[source]
Bases:
Function
- static async_call_director(classroom_session, history, agent_list, **kwargs)[source]
Asynchronously triggers the director logic to select the next speaker in the script.
- Parameters:
classroom_session (ClassroomSession) – The classroom session instance.
history (list) – The conversation history as a list of messages.
agent_list (list) – A list of agent IDs eligible for selection.
**kwargs – Additional arguments for customization.
- Returns:
The job ID for the director call.
- Return type:
str
- static format_history(message, agent_dict)[source]
Formats a message from the conversation history for logging purposes.
- Parameters:
message (dict) – The message dictionary containing actor and content information.
agent_dict (dict) – A mapping of agent IDs to their names.
- Returns:
The formatted history string with actor and content.
- Return type:
str
- static format_history_for_agent(message, agent_dict)[source]
Formats a message for a specific agent by embedding the actor’s name in the message content.
- Parameters:
message (dict) – The message dictionary containing actor and content information.
agent_dict (dict) – A mapping of agent IDs to their names.
- Returns:
The formatted message string for the agent.
- Return type:
str
- static get_agent_id2name_dict(classroom_session, agent_list)[source]
Constructs a mapping of agent IDs to their names.
- Parameters:
classroom_session (ClassroomSession) – The classroom session instance.
agent_list (list) – A list of agent IDs.
- Returns:
A dictionary mapping agent IDs to their corresponding names.
- Return type:
dict
- static get_agent_name_by_id(agent_id, classroom_session)[source]
Retrieves the name of an agent by its ID.
- Parameters:
agent_id (str or ObjectId) – The ID of the agent.
classroom_session (ClassroomSession) – The classroom session instance.
- Returns:
The name of the agent.
- Return type:
str
- static get_agent_role(agent_id, classroom_session)[source]
Retrieves the role and identity of an agent based on its ID.
- ROLE:
“user”: the real human student. Role: the whole classroom’s purpose is to teach the student the knowledge in the classroom.
“小刘老师” or “小詹老师”: AI teachers. Role: responsible for teaching and answering students’ questions.
“助教”: AI teaching assistants. Role: responsible for maintaining the classroom order, when students are speaking out of topic or trying to deviate from the course’s theme, the assistant will stand up to maintain the classroom’s discipline.
“显眼包”: AI students. Role: Class Clown: Crafted to spark creativity, engender a lively classroom ambiance, and act as a supportive peer, this agent also assists the teacher in steering the class’s focus when the learner’s attention wanders.
“好奇宝宝”: AI students. Role: Inquisitive Mind: Characterized by a propensity for inquiring about lecture content, this agent fosters a culture of inquiry and dialogue, prompting others to engage in critical thinking and collaborative discourse.
“笔记员”: AI students. Role: Note Taker: With a penchant for summarizing and disseminating key points from the class discussions, this agent aids in the cognitive organization and retention of information for all participants.
“思考者”: AI students. Role: Deep Thinker: This agent is dedicated to profound contemplation and to posing thoughtprovoking questions that challenge and extend the intellectual boundaries of the classroom.
- Parameters:
agent_id (str) – The ID of the agent.
classroom_session (ClassroomSession) – The classroom session instance.
- Returns:
A dictionary containing the agent’s identity and role.
- Return type:
dict
- init_status = {'agent_talked': False, 'llm_job_id': None, 'phase': 0}
- static map_activation(activation)[source]
Maps the given activation level to a corresponding numerical value.
- Parameters:
activation (str) – The activation level, which can be “low”, “middle”, or “high”.
- Returns:
The mapped numerical value for the activation level. Return 0.05 for “low”, 0.1 for “middle”, and 0.2 for “high”. Returns -1 if the activation level is invalid.
- Return type:
float
- static step(value, function_id, classroom_session)[source]
Handles the state transitions and logic for the ReadScript function based on the current status.
- Phases:
UNREAD: Script Not Read Yet. Disables user input, sends script to message, and waits for user to read and type response.
NEED_CALL_DIRECTOR: Time to call the director. Update the chat history and send to the director, and wait for the director’s response.
WAITING_USER_INPUT: User was asked to type something and the frontend send a signal to continue classroom. User’s input is already in the history if the user did type something.
FORCE_AGENT_TO_HEATUP_TALK: Select the “显眼包” agent to say something to heat-up the discussion.
WAITING_DIRECTOR_RETURN: Check whether the director is returned and jummp to the next status accordingly (selected_speaker: user or teacher or a specific agent).
- Parameters:
value (dict) – The input values related to the function.
function_id (str) – The unique identifier for the function instance.
classroom_session (ClassroomSession) – The classroom session object managing the function’s state.
- Returns:
Whether the function should continue execution.
- Return type:
bool
- class service.inclass.functions.readScript.ReadScriptDirectorConst[source]
Bases:
object
Defines the constants used in the ReadScript function.
- Constants:
USER_NAME (str): The name of the user, “真人学生” (Real Student).
TEACHER_NAME (str): The name of the teacher, “老师” (Teacher).
END_SEQUENCE_NAME (str): The name of the end sequence, “上课” (Continue class).
- END_SEQUENCE_NAME = '上课'
- TEACHER_NAME = '老师'
- USER_NAME = '真人学生'
- class service.inclass.functions.readScript.ReadScriptStatus[source]
Bases:
object
Defines the possible states of the ReadScript function.
- States:
UNREAD (0): The script has not been read yet.
NEED_CALL_DIRECTOR (1): The script has been read and the director needs to be called.
WAITING_DIRECTOR_RETURN (2): The director has been called and is waiting for the user’s input.
WAITING_USER_INPUT (3): The user has been asked to type something and is waiting for the director’s response.
FINISHED (4): The script has been read and the user has finished reading it.
CONTINUE_FINISHED (5): The user has finished reading the script and the classroom should continue.
TOO_MUCH_ROUND_FINISHED (6): The user has finished reading the script and the classroom should continue, but the user has been too slow.
FORCE_AGENT_TO_HEATUP_TALK (9): The user has been asked to type something and the frontend send a signal to continue classroom. The user’s input is already in the history if the user did type something.
- CONTINUE_FINISHED = 5
- FINISHED = 4
- FORCE_AGENT_TO_HEATUP_TALK = 9
- NEED_CALL_DIRECTOR = 1
- TOO_MUCH_ROUND_FINISHED = 6
- UNREAD = 0
- WAITING_DIRECTOR_RETURN = 2
- WAITING_USER_INPUT = 3
- service.inclass.functions.readScript.random() x in the interval [0, 1).