Interactive Language Tutor
Create an engaging AI tutor for language learning using ControlFlow
This example demonstrates how to use ControlFlow to create a simple yet interactive language learning assistant. It showcases the use of a custom agent, user interaction, and a flexible learning flow.
Code
The following code creates a basic language learning session with an AI tutor:
Key Concepts
This implementation showcases several important ControlFlow features and concepts:
-
Custom Agent: We define a tutor agent with specific instructions on how to interact with the user. This allows for a consistent and engaging teaching style throughout the session.
-
Flow-level Agent Assignment: We assign the tutor agent to the entire flow, eliminating the need to specify it for each task.
-
Interactive Tasks: We use the
interactive=True
parameter for tasks that require user interaction. This allows the AI tutor to engage directly with the user. -
Flexible Flow Control: The learning session uses a while loop with a condition checked after each lesson. This allows the session to continue as long as the user wants to keep learning.
-
Context Passing: We pass the
lesson
andexercise
objects as context to relevant tasks. This allows the AI tutor to have access to the current lesson content. -
Structured Data Models: We use a Pydantic model (
Lesson
) to define the structure of our lesson data. This ensures that the data passed between tasks is well-structured and type-safe.
By leveraging these ControlFlow features, we create a simple yet engaging language learning assistant. This example demonstrates how to build interactive AI workflows that can respond to user input and adapt their behavior based on the user’s choices.
The simplicity of this implementation allows for easy expansion. Users could extend this example by adding more complex lesson structures, implementing progress tracking, or incorporating additional language learning features like vocabulary reviews or grammar explanations.