|
dolibarr 25.0.0-alpha
|
File to handle MCP (Model Context Protocol) Intent Parsing This service receive a prompt, format and complete it with list of tools, send it to AI service and return the answer. More...
Go to the source code of this file.
Functions | |
| catch(Throwable $e) | aiQueryAsksForWrite ($query, $langs) |
| Does the user's message ask for a write (create / update / delete / ...)? Translated keys of the current language plus the short verbs users type in French and English whatever the UI language; whole words only. | |
| aiLabelOfResolvedObject (array $readResult, array $writeArgs) | |
| Name of the object a write targets, taken from the read result that produced its id (so the confirmation names "Dupont SA", not "socid 2305"). | |
| recursiveUnmaskValues ($data, ?PrivacyGuard $guard) | |
| Recursively unmask values in a dataset. | |
| isComplexScript (string $text) | |
| Detects if the query uses Non-Latin Scripts. | |
| aiNormalizeForMatch ($word, $asStem=false) | |
| Normalize a keyword or query for inflection-tolerant non-Latin matching. | |
| classifyIntentUniversal (string $query, Translate $langs) | |
| Detect intent categories from a user query. | |
| filterToolsProfessional (array $allTools, array $activeCategories) | |
| Filter a list of tools based on active intent categories. | |
| cleanToolSchemaForLLM (array $tools, bool $isLargeSchema=false) | |
| Compresses tool schema by removing optional parameters with defaults and stripping descriptions, relying on LLM inference of variable names. | |
| calculateConfidence ($intentJSON, $toolsSchema, $rawResponse) | |
| Calculate confidence score based on multiple factors. | |
| formatArgumentsForDisplay ($arguments) | |
| Format arguments for display in confirmation. | |
| extractActionFromTool ($toolName) | |
| Extract action from tool name. | |
File to handle MCP (Model Context Protocol) Intent Parsing This service receive a prompt, format and complete it with list of tools, send it to AI service and return the answer.
Definition in file parse_intent.php.
| aiLabelOfResolvedObject | ( | array | $readResult, |
| array | $writeArgs ) |
Name of the object a write targets, taken from the read result that produced its id (so the confirmation names "Dupont SA", not "socid 2305").
| array<mixed> | $readResult Result of the read tool (a row, a list of rows, or {data:[...]}) |
| array<mixed> | $writeArgs Arguments of the write tool |
Definition at line 1189 of file parse_intent.php.
References dol_trunc().
| aiNormalizeForMatch | ( | $word, | |
| $asStem = false ) |
Normalize a keyword or query for inflection-tolerant non-Latin matching.
Translators translate UI keys as natural dictionary words - as they should. Inflected languages then break exact substring matching so the code derives a match-friendly form instead of asking humans for stems: lowercase, strip combining accents (Unicode NFD marks, when the intl Normalizer is available), and for keywords drop the trailing inflection-bearing characters. No language is special-cased.
| string | $word | Word to normalize |
| bool | $asStem | True to also truncate the inflected tail (keywords); false for the query |
Definition at line 1328 of file parse_intent.php.
References dol_strlen(), dol_strtolower(), and dol_substr().
Referenced by classifyIntentUniversal().
| catch(Throwable $e) aiQueryAsksForWrite | ( | $query, | |
| $langs ) |
Does the user's message ask for a write (create / update / delete / ...)? Translated keys of the current language plus the short verbs users type in French and English whatever the UI language; whole words only.
| string | $query | Message of the user |
| Translate | $langs | Translations |
Definition at line 1159 of file parse_intent.php.
References dol_strtolower().
| calculateConfidence | ( | $intentJSON, | |
| $toolsSchema, | |||
| $rawResponse ) |
Calculate confidence score based on multiple factors.
This function analyzes the AI's response to determine if the intent was parsed correctly and if all required arguments were provided according to the tool's schema.
| array<string,mixed> | $intentJSON The parsed intent (Keys: 'tool', 'arguments'). | |
| array<string,array<string,mixed>> | $toolsSchema Available tools schema (Key=ToolName, Value=ToolDefinition). | |
| string | $rawResponse | Raw response string from the AI provider. |
Definition at line 1640 of file parse_intent.php.
| classifyIntentUniversal | ( | string | $query, |
| Translate | $langs ) |
Detect intent categories from a user query.
This function analyzes a natural language query and attempts to classify it into one or more predefined intent categories (e.g., billing, commercial, thirdparty, stock, project, reporting).
It leverages Dolibarr translations ($langs->trans()) to match localized keywords in the user's language and in the en_US reference. For non-Latin scripts, it performs a simpler substring search.
Matching strategy:
Each category is detected if at least one keyword matches.
| string | $query | The user input query to analyze. |
| Translate | $langs | The Dolibarr translation object used to resolve localized keywords. |
Definition at line 1372 of file parse_intent.php.
References $conf, aiNormalizeForMatch(), dol_string_unaccent(), dol_substr(), and isComplexScript().
| cleanToolSchemaForLLM | ( | array | $tools, |
| bool | $isLargeSchema = false ) |
Compresses tool schema by removing optional parameters with defaults and stripping descriptions, relying on LLM inference of variable names.
| array<int,array<string,mixed>> | $tools Array of tool definitions. | |
| bool | $isLargeSchema | True if compression is needed. |
Definition at line 1546 of file parse_intent.php.
| extractActionFromTool | ( | $toolName | ) |
Extract action from tool name.
| string | $toolName | The tool name |
Definition at line 1737 of file parse_intent.php.
| filterToolsProfessional | ( | array | $allTools, |
| array | $activeCategories ) |
Filter a list of tools based on active intent categories.
This function narrows down the available tools by matching their assigned categories against the detected intent categories. Tools tagged as "global" are always considered, but may be excluded when more specific categories are active to avoid overly generic matches.
Behavior:
| array<int,array<string,mixed>> | $allTools List of all available tools. | |
| string[] | $activeCategories | Detected intent categories (e.g., ['billing', 'stock']). |
Definition at line 1511 of file parse_intent.php.
References dol_syslog().
| formatArgumentsForDisplay | ( | $arguments | ) |
Format arguments for display in confirmation.
| array<string,mixed> | $arguments The arguments to format (Key=ParamName, Value=Value) |
Definition at line 1718 of file parse_intent.php.
| isComplexScript | ( | string | $text | ) |
Detects if the query uses Non-Latin Scripts.
Supports all Dolibarr Core Non-Latin languages:
| string | $text | The input text to be checked. |
Definition at line 1279 of file parse_intent.php.
Referenced by classifyIntentUniversal().
| recursiveUnmaskValues | ( | $data, | |
| ?PrivacyGuard | $guard ) |
Recursively unmask values in a dataset.
This helper walks through an array structure and applies the appropriate unmasking method on all string values. It ensures that any masked or placeholder data is restored before being used in actual tool execution.
Supported guard methods:
If both methods exist, unmask() takes precedence.
| mixed | $data | The input data (array, string, or scalar) to process. |
| PrivacyGuard | null | $guard | An object providing unmasking methods. |
| mixed | $item |
Definition at line 1241 of file parse_intent.php.
References recursiveUnmaskValues().
Referenced by recursiveUnmaskValues().