@@ -10,181 +10,126 @@ tags:
1010<Since version =" 4.5 " issueNumber =" MDL-80888 " />
1111
1212The AI Subsystem in Moodle LMS provides a consistent and user-friendly way for users to interact with AI
13- in Moodle's user interface, as they do their teaching and learning activities.
14- As well as providing a straightforward way to integrate with various AI providers on the backend.
13+ in Moodle. It has been designed for easy integration with various AI providers and the development of [ AI plugins] ( /apis/plugintypes/ai/index.md ) .
1514
1615## What is AI in this context?
1716
18- When we talk about AI in the context of this subsystem, AI is anything that's plugged in via a Provider
19- Plugin and provides one or more Actions .
17+ The term 'AI' is very broad and covers a range of concepts like Artificial Intelligence (AI), Machine Learning (ML),
18+ Large Language Models (LLMs), Generative AI, etc .
2019
21- Artificial Intelligence (AI), Machine Learning (ML), Large Language Models (LLMs), Generative AI, etc.
22- are all individual terms with discrete meanings. However, to keep things simple and in the context of
23- the subsystem everything is just called AI.
20+ However, in the context of Moodle, we are simplifying the term 'AI' to mean the tools and actions AI technologies provide to the LMS learning experience.
21+ These AI tools are supplied in the form of [ plugins] ( /apis/plugintypes/ai/index.md ) that feature a set of possible actions.
22+
23+ For example, the [ Placement plugin] ( /apis/plugintypes/ai/placement.md ) allows users to gain access to the Course Assistant. This AI tool enables
24+ users to have information within their course summarised by the integrated AI.
25+
26+ This is the context of the term 'AI'.
2427
2528## Design Overview
2629
2730``` mermaid
28- flowchart TD
29- Placement["Placement"]:::placementStyle
30- Action["Action"]:::actionStyle
31- SubsystemManager["Subsystem Manager"]:::managerStyle
32- Provider["Provider"]:::providerStyle
33-
34- Placement --> |"Instantiates Action"| Action
35- Action --> |"Passes to Subsystem Manager"| SubsystemManager
36- SubsystemManager --> |"Selects & Invokes Provider"| Provider
37- Provider --> |"Returns Response to Action"| Action
38-
39- %% Define styles for each block
40- classDef placementStyle fill:#FFDDC1,stroke:#FF6F61,stroke-width:2px;
41- classDef actionStyle fill:#C1E1C1,stroke:#4CAF50,stroke-width:2px;
42- classDef managerStyle fill:#C1DFF0,stroke:#2196F3,stroke-width:2px;
43- classDef providerStyle fill:#FFD700,stroke:#FFC107,stroke-width:2px;
31+ sequenceDiagram
32+ User->>Placement: Input action
33+ Placement->>Manager: Action data
34+ Manager->>Provider: Formatted action data
35+ Provider->>External AI: Send data
36+ External AI-->>Provider: Receive response
37+ Provider-->>Manager: Response data
38+ Manager-->>Placement: Formatted response data
39+ Placement-->>User: Action completed
4440```
4541
46- The AI subsystem consists of the following (main) components:
42+ The AI Subsystem consists of the following (main) components:
4743
4844- ** Placements**
4945 - Are the UI components and associated workflows that allow users to interact with AI.
5046 - They implement one or more AI actions.
5147 - They provide a consistent experience for users regardless of which AI is providing the action.
5248 - They are LMS plugins.
5349- ** Actions**
54- - These are the " things" users can do with AI.
50+ - These are the ' things' users can do with AI.
5551 - Examples of an action include: generating text, generating an image, providing a chat interface.
5652 - Actions don't have a UI, they are classes that provide a predictable interface.
5753- ** Providers**
5854 - Providers are the interface between AI systems and the Moodle LMS.
5955 - They implement support for one or more actions.
60- - Providers should not have a UI, apart from those required for settings,
61- to configure and manage the provider. For example an Administration UI to allow setting of API
62- keys; and/or to enable or disable the enabled actions.
63- - The aim of Providers is to make it "easy" to integrate AI systems with LMS,
64- without the need to implement a UI to use them.
56+ - Providers should not have a UI, apart from those required to configure the provider.
57+ - The aim of Providers is to make it easy to integrate AI systems with Moodle LMS.
6558 - They are LMS plugins.
6659- ** Subsystem Manager**
6760 - This is implemented at code level and is a core part of the subsystem design.
68- - It is the "controller" that sits between Placements and Providers.
69- - It allows Placements to pass user requests to Providers and handles all the calls to
70- the providers including prioritisation and logging.
61+ - It is the 'controller' that sits between Placement and Provider plugins.
62+ - It allows Placements to pass user requests to Providers and handles all the calls to the Providers, including prioritisation and logging.
7163 - It allows Providers to respond to action requests.
7264
7365### Placements
7466
75- The aim of Placements is to provide a consistent UX and UI for users when they use AI backed functionality.
67+ Placements provide a consistent UX and UI for users when they use AI backed functionality (e.g. generating an image) .
7668
7769Placement plugins leverage the functionality of the other components of the AI subsystem.
7870This means plugin authors can focus on how users interact with the AI functionality, without needing to
7971implement the AI functionality itself.
8072
81- Because Placements are LMS plugins in their own right and are not "other" types of LMS plugins,
82- it gives great flexibility in how AI functionality is presented to users.
73+ Because Placements are plugins in their own right, it allows for greater flexibility in how AI functionality is presented to users.
8374
8475See the [ Placements] ( /apis/plugintypes/ai/placement.md ) documentation for more information
8576on developing Placement plugins.
8677
8778### Providers
8879
89- Provider plugins are the interface between the LMS AI subsystem and external AI systems.
90- Their focus is on converting the data requested by an Action into the format needed by the
91- external AI services API, and then correctly providing the response back from the AI
92- in an Action Response object.
93-
94- Because of this design the Providers that provide the AI Actions can be swapped out, mix and matched
95- or upgraded; both without the need to update the Placement code and without the need to change the
96- way users interact with the functionality.
80+ Providers are the interface between the [ AI subsystem] ( /apis/subsystems/ai/index.md ) and external AI.
81+ Their focus should be on converting the data requested into the format needed
82+ by the external AI, and then correctly providing the response back.
9783
9884See the [ Providers] ( /apis/plugintypes/ai/provider.md ) documentation for more information
9985on developing Provider plugins.
10086
10187### Subsystem Manager
10288
103- The Subsystem Manager is the "controller" that sits between Placements and Providers.
89+ The Subsystem Manager is the 'controller' that sits between Placements and Providers.
90+ In general it will be how most processes will interact with the AI subsystem.
10491
10592:::warning The Golden Rule:
10693
107- Placements DO NOT know about Providers, and Providers DO NOT know about Placements.
94+ Placements ** do not ** know about Providers, and Providers ** do not ** know about Placements.
10895Everything should go via the Manager.
10996
11097:::
11198
112- The manager class ` \core_ai\manager() ` is the "controller" for the subsystem.
113- In general it will be how most processes will interact with the AI subsystem.
114-
115- The main method in the class is ` process_action(base $action): responses\response_base `
116- this is the entry point for Action processing. Every Placement that wants to process an AI action
117- calls this method.
118- The manager will determine what Providers support this action and then hand off the action object to
119- a Provider. The Provider ** MUST** return an action response object. This method will also store the
99+ The main method in the class is ` process_action(base $action): responses\response_base ` .
100+ This is the entry point for Action processing. Every Placement that wants to process an AI action calls this method.
101+ The Manager will determine which Providers support this action and then hand-off the action object to
102+ a Provider. The Provider ** must** return an action response object. This method will also store the
120103result of each action call.
121104
122- The manager class also has various utility methods that can be accessed.
123- Such as getting the list of providers for specific actions, which is used to help render
124- administration settings.
125-
126- ### AI User Policy
127-
128- Inline with Moodle's AI Principles and as guided by emerging legislation; users must accept an
129- AI policy before using AI in LMS. As the requirements are different to a site policy
130- (legislation, seems to indicate it acknowledgement of AI must be made at point of use),
131- separate policy functionality has been implemented for the subsystem.
132-
133- All Placements must implement a check to see if a user has accepted the AI Policy.
134- Placements must also provide a way for users to accept the policy.
135- If a user has not previously accepted the AI Policy, the Placement must display the policy to the
136- user, and the user is not able to use the placement until they accept the policy.
137- Users only need to accept the policy once.
138-
139- To assist Placements with policy display and acceptance the Manager provides the following functionality:
140-
141- #### Direct call
142-
143- The Manager makes the following methods available for Placements to call directly:
144-
145- ##### ` \core_ai\manager::get_user_policy_status(int $userid): bool `
146-
147- Given a user ID (record id in user table), returns true if the user has accepted the policy,
148- false otherwise. It handles looking up the status and caching the response.
149-
150- ##### ` \core_ai\manager::user_policy_accepted(int $userid, int $contextid): bool `
151-
152- Given a user ID and a Context ID (of the context the policy was displayed in) set the policy
153- acceptance.
154-
155- #### Webservices
156-
157- The manager class also makes available webservices to be used for policy setting and getting.
158- This helps Placements set policy acceptance via ajax as part of a UI workflow:
159-
160- ##### ` core_ai_get_policy_status `
161-
162- Gets the policy status for a user. Calls: ` core_ai\external\get_policy_status `
163-
164- ##### ` core_ai_set_policy_status `
165-
166- Sets the policy status for a user. Calls: ` core_ai\external\set_policy_status `
105+ The Manager class also provides various utility methods, such as retrieving the list of providers for specific actions.
106+ These methods are useful for rendering administration settings.
167107
168108### Actions
169109
170- Actions provide a structured way to work with AI. Placements create an Action object when they want
171- to interact with AI and Providers, and it is an Action that Providers consume .
110+ Actions provide instructions to the integrated AI.
111+ Placements create an Action object which is then consumed by the Provider .
172112
173113Actions are defined as classes in the ` \core_ai\aiactions ` namespace.
174- The naming convention for Action classes is ` <verb>_<noun singular> ` ,
175- for example: ` generate_image ` , ` translate_text ` .
114+ The naming convention for Action classes is ` <verb>_<noun singular> ` .
115+
116+ #### Actions in AI subsystem
117+
118+ - ` generate_image `
119+ - ` generate_text `
120+ - ` summarise_text `
176121
177122#### Base abstract class
178123
179- Each action ** MUST ** inherit from the ` \core_ai\aiactions\base ` abstract class.
124+ Each Action ** must ** inherit from the ` \core_ai\aiactions\base ` abstract class.
180125They must also implement two methods:
181126
182127##### 1. ` __construct() `
183128
184- - The constructor method is allowed to have a variable signature, so that each action can define its own
129+ - The constructor method is allowed to have a variable signature, so that each Action can define its own
185130configuration requirements.
186- - The method ** MUST ** take a ` contextid ` as one of the variables.
187- - An Action ** MUST ** be correctly instantiated before it can be used and passed onto the AI manager.
131+ - The method ** must ** take a ` contextid ` as one of the variables.
132+ - An Action ** must ** be correctly instantiated before it can be used and passed to the AI manager.
188133
189134``` php title="Example: The __construct() method for the generate_image Action"
190135public function __construct(
@@ -208,10 +153,9 @@ public function __construct(
208153
209154##### 2. ` store() `
210155
211- - This method is responsible for storing any action specific data related to the action in the
212- LMS database.
213- - Each Action must store its own data can that can be referenced later.
214- - It takes a matching response class, that contains the result of the action call.
156+ - This method is responsible for storing data related to the Action in the LMS database.
157+ - Each Action must store its own data that can be referenced later.
158+ - It takes a matching response class that contains the result of the Action call.
215159
216160``` php title="Example: The store() method for the generate_image Action"
217161#[\Override]
@@ -233,8 +177,7 @@ public function store(response_base $response): int {
233177}
234178```
235179
236- It is up to the action to define its own database schema and stored data, that is relevant to
237- what the action does.
180+ Each Action will need to define its own database schema and stored data that is relevant to what it does.
238181
239182``` xml title="Example: The database table definition for the generate_image Action"
240183<TABLE NAME =" ai_action_generate_image" COMMENT =" Stores specific data about generate image actions" >
@@ -254,17 +197,16 @@ what the action does.
254197</TABLE >
255198```
256199
257- The naming convention for Action database tables is ` ai_action_<action_name> ` ,
258- for example: ` ai_action_generate_image ` , ` ai_action_translate_text ` .
200+ The naming convention for Action database tables is ` ai_action_<action_name> ` . For example: ` ai_action_generate_image ` , ` ai_action_translate_text ` .
259201
260202#### Responses
261203
262- When a Provider processes an Action it ** MUST ** return a response object.
204+ When a Provider processes an Action it ** must ** return a response object.
263205This allows Placements to receive an expected response for any Action call.
264- Each Action has a matching response class. The provider that processes the Action will instantiate
206+ Each Action has a matching response class. The Provider that processes the Action will instantiate
265207an instance of this response class and populate it with the data required for this type of response.
266208
267- Each Action response ** MUST ** inherit from the ` \core_ai\aiactions\responses\response_base ` abstract
209+ Each Action response ** must ** inherit from the ` \core_ai\aiactions\responses\response_base ` abstract
268210class. They must also implement two methods:
269211
270212##### 1. ` set_response_data() `
@@ -296,5 +238,45 @@ Returns the set response data.
296238 }
297239```
298240
299- The naming convention for Action Response classes is ` response_<action_name> ` ,
300- for example: ` response_generate_image ` , ` response_translate_text ` .
241+ The naming convention for Action response classes is ` response_<action_name> ` . For example: ` response_generate_image ` , ` response_translate_text ` .
242+
243+ ## AI User Policy
244+
245+ Inline with Moodle's AI Principles, and as guided by emerging legislation, users must accept the
246+ AI User Policy before using AI in LMS. As the requirements are different from a site policy,
247+ separate policy functionality has been implemented for the AI subsystem (legislation indicates acknowledgement of AI must be made at point of use).
248+
249+ - Placements must implement a check to see if a user has accepted the policy.
250+ - Placements must provide a way for users to accept the policy.
251+ - If a user has not previously accepted the policy, the Placement must display the policy to the user.
252+ - The user is not able to use the Placement until they accept the policy.
253+ - Users only need to accept the policy once.
254+
255+ To assist Placements with displaying the AI User Policy, the Manager provides the following functionality:
256+
257+ ### Direct call
258+
259+ The Manager makes the following methods available for Placements to call directly:
260+
261+ #### ` \core_ai\manager::get_user_policy_status(int $userid): bool `
262+
263+ Given a User ID (record id in user table), returns ` true ` if the user has accepted the policy,
264+ ` false ` otherwise. It handles looking up the status and caching the response.
265+
266+ #### ` \core_ai\manager::user_policy_accepted(int $userid, int $contextid): bool `
267+
268+ Given a User ID and a Context ID (context the policy was displayed in), set the policy
269+ acceptance.
270+
271+ ### Webservices
272+
273+ The Manager class also makes available webservices to be used for policy setting and getting.
274+ This helps Placements set policy acceptance via Ajax as part of a UI workflow:
275+
276+ #### ` core_ai_get_policy_status `
277+
278+ Gets the policy status for a user. Calls: ` core_ai\external\get_policy_status `
279+
280+ #### ` core_ai_set_policy_status `
281+
282+ Sets the policy status for a user. Calls: ` core_ai\external\set_policy_status `
0 commit comments