Skip to content

MelisAIEngine

The core AI engine — agents, instances, scenarios, models and the MCP/tool layer. Package melisplatform/melis-ai-engine.

Purpose

MelisAIEngine is the provider-agnostic runtime that powers Melis AI. It defines the abstract model contract (MelisAIEngineModelService) that provider modules (Claude, Gemini…) implement, runs agents through their scenario steps, builds the payload from conversation context and uploaded files, manages tool/function declarations (including MCP servers), tracks token usage, and exposes the chat view helpers used in the backoffice. It is the engine layer; the backoffice UI lives in the companion module melis-ai. See the AI guide and the MCP guide.

Enable it

A standard Laminas module. Add it to config/melis.module.load.php:

php
'MelisAIEngine',

It is typically loaded alongside MelisAIEngineClaude / MelisAIEngineGemini (providers) and MelisAI (backoffice). Composer dependencies: melisplatform/melis-core and melisplatform/melis-document-upload (for document ingestion). At least one provider module must be installed for real model calls.

Key services

Service aliasRole
MelisAIEngineServiceCore data access for the engine: getActiveInstance(), getActiveAgent(), getActiveModel(), getActiveModelClass(), getEntryParams() / getExitParams(), getDefaultModel(), getActiveAITools(), saveDailyUsage().
MelisAIEngineModelServiceAbstract base contract for provider adapters. Concrete send(), getAgentFunctions(), token getters, document extraction (extractTextFromDocx(), extractTextFromXlsx()); abstract setClient(), addToolsToPayload(), addContentToPayload(), sendCustomAI(), getAllowedMimetypes(), processFiles(), processContextFiles().
MelisAIEngineFunctionServiceBuilt-in (non-MCP) tool/function implementations, e.g. get_table_structure(), create_database_table(), add_database_table_fields(), activate_module(), save_file().
MelisAIEngineMcpServiceMCP client: server management, tool discovery, schema handling, communication and circuit-breaker logic (composed from the Service/Traits/Mcp/* traits). Built via factory.
MelisAIEngineFileServiceFile lifecycle for AI uploads, e.g. deleteAIDocUploads().
MelisAIEngineGeneralServiceEvent-aware helpers: sendEvent(), makeArrayFromParameters(), getRenderMode().
MelisAIEngineConversationStorePersists conversation state (get(), set(), has(), delete()) in melis_ai_conversation_state. Built via factory.
MelisAIEngine\Service\MelisAIEngineAgentServicePer-run agent orchestration (factory-built with an agent id + instance id): runAgent(), continueConversation(), validateAnswer(), validateResult(), session context/historic/answer accessors, restartAgent(), clearSession().

The *Table aliases (MelisAIEngineAgentTable, MelisAIEngineInstanceTable, MelisAIEngineModelTable, MelisAIEngineToolTable, MelisAIEngineAgentToolTable, MelisAIEngineScenarioStepTable, …) expose the underlying tables for the services above.

Backoffice

The engine ships no tool-tree entry of its own (app.tools.php and app.toolstree.php are empty — the UI is provided by melis-ai). It contributes:

  • Controller MelisAIEngine\Controller\AI (AIController), routed under MelisAIEngine, with the AJAX actions that drive a chat session: runAgentAction, validateAnswerAction, continueConversationAction, restartAgentAction, closeAgentAction, plus the modal renderers renderErrorModalAction and renderMessageModalAction.
  • Two interface modals declared in app.interface.php: melisKeys melisaiengine_error_modal and melisaiengine_message_modal.

Front office

The chat experience is exposed as view helpers (not drag-drop templating plugins), usable in any .phtml:

View helper aliasRole
AIChatViewHelperRenders a full chat box bound to an instance/agent. __invoke($maiInstanceId, ?int $agentId = null, $extraEntryParams = [], $debugMode = false, $exitParamArr = [], $showCloseButton = true, $needExitParam = true, $showHideButton = false, $clearSession = true, $renderMode = 'melis').
AIChatFormBoxViewHelperRenders the chat input/form box. __invoke($agentId, $withLabel = true).
AIChatHistoricViewHelperRenders the conversation history. __invoke($debugMode = false).
AIChatHistoricDebugViewHelperRenders the debug history view.
AIUserInputViewHelperBuilds a Laminas form element for a user-input step. __invoke($fieldType, $label, $fieldName = 'user_input').

The agent scenario steps are implemented as controller plugins, registered under controller_plugins and named MelisAIAgentStepType*Plugin (e.g. MelisAIAgentStepTypeAIChatPlugin, MelisAIAgentStepTypeUserInputPlugin, MelisAIAgentStepTypeCodePhpPlugin, MelisAIAgentStepTypeCodeBuiltInPlugin, MelisAIAgentStepTypeAIContextPlugin, MelisAIAgentStepTypeEntryParamsPlugin, MelisAIAgentStepTypeExitParamsPlugin, MelisAIAgentStepTypeCodeAICallPlugin). Two extra plugins back the built-in code steps: MelisAIEngineBuiltInConnectedUser and MelisAIEngineBuiltInGetString.

Database tables

Created by install/dbdeploy/ (the module sets extra.dbdeploy: true):

TableHolds
melis_ai_companiesAI providers/companies.
melis_ai_modelsProvider models.
melis_ai_agentsAgents (incl. maa_agent_tools, file-context settings).
melis_ai_instances / melis_ai_instance_transAgent instances and their translations.
melis_ai_scenario_steps / melis_ai_scenario_steps_datas / melis_ai_scenario_steps_datas_entryexitScenario steps, their data, and entry/exit params.
melis_ai_return_typesStep return-type reference data.
melis_ai_tools / melis_ai_agents_toolsTool catalogue and the agent↔tool assignment.
melis_ai_platform_keysPer-platform API keys/credentials.
melis_ai_daily_usageToken/usage accounting per agent.
melis_ai_filesUploaded AI documents/context files.
melis_ai_conversation_statePersisted multi-turn conversation state.

(The MelisAIEnginePlatformTable alias reads the core melis_core_platform table.)

Example

Drop a chat box for an existing AI instance into a backoffice view:

php
// in a .phtml view
echo $this->AIChatViewHelper($maiInstanceId, $agentId);

Add a custom non-MCP function for agents to call by extending MelisAIEngineFunctionService and declaring the function under plugins -> melisaiengine -> datas -> function_declarations, then assign it to an agent via Melis AI > AI Agents > [Agent] > AI Tools. See Create a tool and the MCP guide.

Key files

ConcernPath
Module config (services, routes, helpers, plugins)vendor/melisplatform/melis-ai-engine/config/module.config.php
Interface modalsvendor/melisplatform/melis-ai-engine/config/app.interface.php
Provider contractvendor/melisplatform/melis-ai-engine/src/Service/MelisAIEngineModelService.php
Agent runtimevendor/melisplatform/melis-ai-engine/src/Service/MelisAIEngineAgentService.php
Built-in functions/toolsvendor/melisplatform/melis-ai-engine/src/Service/MelisAIEngineFunctionService.php
MCP service + traitsvendor/melisplatform/melis-ai-engine/src/Service/MelisAIEngineMcpService.php, src/Service/Traits/Mcp/
Chat controllervendor/melisplatform/melis-ai-engine/src/Controller/AIController.php
View helpersvendor/melisplatform/melis-ai-engine/src/View/Helper/
Step pluginsvendor/melisplatform/melis-ai-engine/src/Controller/Plugin/
DB deltasvendor/melisplatform/melis-ai-engine/install/dbdeploy/

See also: Module reference, AI guide, MCP guide.