lang_tools.exercises.conversational_tutor
¶
Conversational tutor exercise (from fala-comigo-ai-tutor).
This exercise is loosely coupled to UserWordProgress: each user turn is sent
to a TutorResponseChain (defined in lang_tools.llm.tutor) that produces a
correction block plus a conversation continuation. The chain itself is
provided by the caller so this module stays free of an LLM dependency.
Classes:
-
ConversationalTutorExercise–Conversational tutor session driven by a caller-supplied chain.
-
TutorMessage–One message in the tutor conversation history.
Attributes:
-
TutorChain–Callable that takes
(user_text, history)and returns the tutor reply.
TutorChain
module-attribute
¶
Callable that takes (user_text, history) and returns the tutor reply.
ConversationalTutorExercise
dataclass
¶
Bases: _BaseExercise
Conversational tutor session driven by a caller-supplied chain.
Attributes:
-
chain(TutorChain | None) –Callable matching the
TutorChainsignature. -
topic(str) –Conversation topic shown to the user.
-
history(list[TutorMessage]) –Live conversation history; mutated in place.
Initialize with an optional chain and topic.
Parameters:
-
chain(TutorChain | None, default:None) –Callable matching
TutorChain. May beNoneif the exercise will be driven manually. -
topic(str, default:'') –Conversation topic.
-
**kwargs(object, default:{}) –Forwarded to
_BaseExercise.
Methods:
-
start–Open the session with an optional tutor greeting.
-
submit–Send a user message and append the tutor reply.
Source code in src/lang_tools/exercises/conversational_tutor.py
start
¶
Open the session with an optional tutor greeting.
Parameters:
-
greeting(TutorMessage | None, default:None) –Initial tutor message; appended to history if provided.
Returns:
-
ExerciseRound–ExerciseRoundwhosepromptis the livehistoryreference.
Source code in src/lang_tools/exercises/conversational_tutor.py
submit
¶
Send a user message and append the tutor reply.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
user_text(str) –The user's target-language message.
Returns:
-
RoundResult–RoundResultwhosefeedbackcarries the correction block (if any) -
RoundResult–and
correctis True when no correction was returned.
Raises:
-
RuntimeError–If
chainis None when the user submits a message.
Source code in src/lang_tools/exercises/conversational_tutor.py
TutorMessage
¶
Bases: BaseModel
One message in the tutor conversation history.
Attributes:
-
role(Literal['user', 'tutor']) –"user"or"tutor". -
content(str) –Target-language text.
-
translation(str | None) –Optional user-language translation.
-
correction(str | None) –Optional correction block (tutor messages only).