|
dolibarr 24.0.0-beta
|
File to handle MCP (Model Context Protocol) Intent Parsing. More...
Go to the source code of this file.
Functions | |
| catch(Throwable $e) | recursiveUnmaskValues ($data, ?PrivacyGuard $guard) |
| Recursively unmask values in a dataset. | |
| isComplexScript (string $text) | |
| Detects if the query uses Non-Latin Scripts. | |
| 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.
Definition in file parse_intent.php.
| 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 916 of file parse_intent.php.
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, and applies additional synonym matching for Latin-based queries. For non-Latin scripts, it performs a simpler substring search.
Matching strategy:
Each category is detected if at least one keyword or synonym matches.
| string | $query | The user input query to analyze. |
| Translate | $langs | The Dolibarr translation object used to resolve localized keywords. |
Definition at line 695 of file parse_intent.php.
References dol_string_unaccent(), 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 822 of file parse_intent.php.
| extractActionFromTool | ( | $toolName | ) |
Extract action from tool name.
| string | $toolName | The tool name |
Definition at line 1013 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 787 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 994 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 638 of file parse_intent.php.
Referenced by classifyIntentUniversal().
| catch(Throwable $e) 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 600 of file parse_intent.php.
References recursiveUnmaskValues().
Referenced by recursiveUnmaskValues().