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.