Build an assistant form
Add an AI button to a catalog price rule's description so an admin can draft text, review it and save the rule.
Add the editor
Use an enabled module with the namespace Vendor\StoreGuide on a store with catalog price rules. Include Magento_CatalogRule and Arlanix_Ai in your module's etc/module.xml sequence.
The handle, UI component and record parameter come from the Magento form for catalog price rules.
Add the form under the root of your module's
etc/arlanix_ai.xml. If the file is new, use the full declaration.<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Arlanix_Ai:etc/arlanix_ai.xsd"> <form code="vendor_catalog_rule" ui-form="catalog_rule_form" entity-param="id" resource="Magento_CatalogRule::promo_catalog" title="AI Assistant" label="Catalog price rule" facts-service="Vendor\StoreGuide\Model\RuleFacts" facts-method="facts" store-mode="switcher"> <handle name="catalog_rule_promo_catalog_edit"/> <field name="description" kind="plain" label="Description"/> <value name="name" label="Rule Name" required="true"/> </form> </config>Create
Model/RuleFacts.phpto give the assistant the name of the saved rule. The editable field and the current form value come from the declaration.<?php declare(strict_types=1); namespace Vendor\StoreGuide\Model; use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface; use Magento\Framework\AuthorizationInterface; use Magento\Framework\Exception\NoSuchEntityException; class RuleFacts { public function __construct( private readonly CatalogRuleRepositoryInterface $catalogRuleRepository, private readonly AuthorizationInterface $authorization ) { } public function facts(int $entityId): array { if ($entityId < 1 || !$this->authorization->isAllowed('Magento_CatalogRule::promo_catalog')) { return []; } try { $rule = $this->catalogRuleRepository->get($entityId); } catch (NoSuchEntityException) { return []; } return ['Saved rule name' => (string)$rule->getName()]; } }Deploy the module.
Clean the configuration cache with
bin/magento cache:clean config.Open an existing catalog price rule with an account that has the permissions in Admin access.
Click AI beside Description.
Choose Improve to request a revision.
Choose Apply to place the proposal in the form.
Click Save to keep it.
Add a skill to an existing form
To offer a reusable editing request on CMS blocks, reference the existing form by code under config in your module's etc/arlanix_ai.xml.
<form code="cms_block">
<skill label="Shorten a banner" description="Keep the offer and shorten the copy.">Shorten the banner text in this block. Keep the offer and its end date.</skill>
</form>
- Open a CMS block.
- In Skills, choose Shorten a banner.
- Send the request.
- Review the proposed text.
- To use the proposal, choose Apply.
Form declaration
| Element or attribute | Meaning |
|---|---|
form |
Add directly under config. Use a unique code across forms and pages. |
ui-form, entity-param |
Magento UI form namespace and the request parameter holding the record ID. |
title, label |
Dock heading and the entity label supplied to the model. |
resource, feature |
Existing ACL resource required alongside Arlanix_Ai::use, and optional usage label (default content). |
store-mode |
Use switcher for the request's store view (default 0) or field for a form with store assignments in store_id. |
facts-service, facts-method |
Optional pair. Return each saved fact as a label paired with a string. Accept the named arguments you need from entityId, storeId and editableFields. |
handle |
Supply at least one layout handle by name. Add another for the new-record page if it has a different handle. |
field |
Declare at least one editable UI component by name, label and kind. |
value |
Include a read-only form value by name and label. Use list for option labels, max-length to trim text and required for context needed to draft new content. |
image |
Declare the slot's name, label and kind (gallery or single). Give a single-image slot its component path in ui. Reference image_generate for generation. |
tool, skill |
Reference a tool by name or declare a ready-made request. See Pages and skills. |
Editable fields
| Element or attribute | Meaning |
|---|---|
kind |
Use plain for text, wysiwyg for HTML, pagebuilder for supported text slots or rows for a dynamic rows table. |
max-length |
Hard character limit for a text proposal. |
target-min-length, target-max-length |
Requested text length. Pair a minimum with a maximum. |
max-phrases |
Requested maximum number of comma-separated phrases. |
column under a rows field |
Declare one to eight columns with name and label. Set key="true" on exactly one to identify the row. |
title, hidden, hint on a column |
Identify a row title, hide a column or provide guidance about its contents. |
Check your declaration
- Run
bin/magento arlanix:ai:tool:verifyfrom the Magento root. - Look for
[ok] form vendor_catalog_rule.
If the check fails, check the form code, ACL resource, component names and PHP method signature. Then reload the edit page.