Examples and Tutorials

This section provides practical examples and step-by-step tutorials to help you understand how to apply Project KARL in various scenarios and leverage its features effectively. Each item links to a more detailed page or resource.

The full source code for runnable examples can often be found within the :karl-example-desktop module or specific example directories in our GitHub repository.

Example: Learning User Preferences (Simple Classification)

Description: This example demonstrates how KARL can be used for a basic classification task, such as learning a user's preference for a UI theme (e.g., light vs. dark mode) or content categories. It illustrates how to structure InteractionData for preference signals and how a simple learning engine might adapt to these choices over time.

Key Concepts Covered:

  • Structuring InteractionData for explicit or implicit preference signals.

  • A conceptual simple classification model within a LearningEngine.

  • Using KARL's prediction to apply a learned preference.

Example: View Detailed Learning User Preferences

Example: Predicting Next Action in a Sequence

Description: This example showcases one of KARL's core strengths: learning sequential patterns to predict a user's next likely action. It draws inspiration from scenarios like predicting the next command in a CLI, the next tool a developer might use in an IDE, or the next step in a multi-stage workflow within an application. The :karl-example-desktop module implements a simplified version of this.

Key Concepts Covered:

  • Designing InteractionData to capture sequential events and their context.

  • The role of historical data (context) in making sequence-based predictions.

  • Conceptual considerations for sequence-aware models (e.g., using simple history windows with an MLP, or placeholders for future RNN/Transformer engines).

View Detailed Example: Predicting Next Action (See also the :karl-example-desktop module code)

Tutorial: Building a Basic Adaptive UI Element with KARL

Description: This step-by-step tutorial guides you through creating a simple Jetpack Compose UI element (e.g., a dynamic toolbar, a list of frequently accessed items) that adapts its content or layout based on user interactions learned by a KARL container. It demonstrates how to connect KARL's predictions to reactive UI updates.

Key Concepts Covered:

  • Integrating KarlContainer within a Compose application's state management (e.g., using ViewModels or `remember`ed state).

  • Implementing a DataSource based on Compose UI events.

  • Using StateFlow or similar reactive streams to observe KARL's Predictions.

  • Updating Composable functions based on prediction data to achieve UI adaptation.

  • Utilizing components from :karl-compose-ui like KarlContainerUI (if applicable).

View Tutorial: Building an UI Element

Tutorial: Implementing User Rules for KARL (KarlInstruction)

Description: This tutorial explains how to leverage KARL's instruction system to allow users or the application to define rules that govern the AI's behavior. It covers creating custom KarlInstruction types and implementing an InstructionParser to process user input into these structured rules.

Key Concepts Covered:

  • Understanding the purpose and structure of KarlInstruction (sealed class).

  • Designing a simple DSL or input format for user-defined rules.

  • Implementing a custom com.karl.core.instructions.InstructionParser.

  • Passing parsed instructions to the KarlContainer via updateInstructions().

  • How a LearningEngine might interpret and act upon these instructions during its predict() or trainStep() methods.

More complex or domain-specific examples and tutorials will be added over time as Project KARL evolves and as community use cases emerge. We encourage you to explore the karl-example-desktop module for a comprehensive, runnable integration.