backstage / ai
Add a generative and assisting AI to your Filament app forms and fields.
Fund package maintenance!
Requires
- php: ^8.1
- backstage/laravel-ai: v5.21.1
- filament/forms: ^5.0
- spatie/laravel-package-tools: ^1.15.0
- symfony/html-sanitizer: ^7.1|^8.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.9
- pestphp/pest: ^3.7
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- prism-php/prism: ^0.99.21
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 5.x-dev
- v5.21.1
- v5.21.0
- v5.20.1
- v5.20.0
- v5.19.2
- v5.19.1
- v5.19.0
- v5.18.2
- v5.18.1
- v5.18.0
- v5.17.1
- v5.17.0
- v5.16.0
- v5.15.2
- v5.15.1
- v5.15.0
- v5.14.4
- v5.14.3
- v5.14.2
- v5.14.1
- v5.14.0
- v5.13.1
- v5.13.0
- v5.12.1
- v5.12.0
- v5.11.0
- v5.10.1
- v5.10.0
- v5.9.4
- v5.9.0
- v5.8.2
- v5.8.1
- v5.8.0
- v5.7.7
- v5.7.6
- v5.7.5
- v5.7.4
- v5.7.3
- v5.7.2
- v5.7.1
- v5.7.0
- v5.6.2
- v5.6.1
- v5.6.0
- v5.5.0
- v5.4.0
- v5.3.0
- v5.2.9
- v5.2.8
- v5.2.7
- v5.2.6
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.1.19
- v5.1.18
- v5.1.17
- v5.1.16
- v5.1.15
- v5.1.14
- v5.1.13
- v5.1.12
- v5.1.11
- v5.1.10
- v5.1.9
- v5.1.8
- v5.1.7
- v5.1.6
- v5.1.5
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.20
- v5.0.19
- v5.0.18
- v5.0.17
- v5.0.16
- v5.0.15
- v5.0.14
- v5.0.13
- v5.0.12
- v5.0.11
- v5.0.10
- v5.0.9
- v5.0.8
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- 4.x-dev
- v4.2.10
- v4.2.9
- v4.2.8
- v4.2.7
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.15
- v4.0.14
- v4.0.13
- v4.0.12
- v4.0.11
- v4.0.10
- v4.0.9
- v4.0.8
- v4.0.7
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- 2.x-dev
- v2.0.29
- v2.0.28
- v2.0.27
- v2.0.26
- v2.0.25
- v2.0.24
- v2.0.23
- v2.0.22
- v2.0.21
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.0
- v2.0.0beta-37
- v2.0.0-beta3
- 1.x-dev
- v1.1.54
- v1.1.53
- v1.1.52
- v1.1.51
- v1.1.50
- v1.1.49
- v1.1.48
- v1.1.47
- v1.1.46
- v1.1.45
- v1.1.44
- v1.1.43
- v1.1.42
- v1.1.41
- v1.1.40
- v1.1.39
- v1.1.38
- v1.1.37
- v1.1.36
- v1.1.35
- v1.1.34
- v1.1.33
- v1.1.32
- v1.1.31
- v1.1.30
- v1.1.29
- v1.1.28
- v1.1.27
- v1.1.26
- v1.1.25
- v1.1.24
- v1.1.23
- v1.1.22
- v1.1.21
- v1.1.20
- v1.1.19
- v1.1.18
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.0
- dev-feature/ortho-shop
- dev-add-unsubscribe-date
- dev-feat/5x-formula-fillform-pdf
- dev-feat/auto-update-path-on-save
- dev-feat/mailings-cluster-navigation
- dev-feat/mcp-server
- dev-feature/ai-eleven-labs
- dev-feature/fix-hydration-fileupload-13-juli
- dev-feature/ux-nl-optimizations
- dev-fix-issue-95-5x
- dev-fix-mailing-pivot-foreign-keys
- dev-fix-mailing-sent-count-5x
- dev-fix-mails-routes-5x
- dev-fix/5x-legacy-form-morph-map
- dev-fix/backstage-upgrade-publishes-suite-migrations
- dev-fix/configurable-glide-driver
- dev-fix/content-actions-authorize
- dev-fix/content-depth-column
- dev-fix/fields-block-field-bridge-and-repeater-cache
- dev-fix/file-link-plugin-optional-media
- dev-fix/forms-from-name
- dev-fix/forms-migration-timestamps
- dev-fix/mails-recipient-duplication
- dev-fix/mails-route-authorization
- dev-fix/minify-preserve-response-original
- dev-fix/minify-skip-non-minifiable-responses
- dev-fix/og-image-absolute-url
- dev-fix/og-image-height
- dev-fix/security-workflow-failures
- dev-handle-inactive-recipients
- dev-hl/move-the-mcp-server-package-code
- dev-mailing-utm-tagging
- dev-speed-up-mails-list-5x
- dev-subscriber-email-validation
- dev-chore/security-workflow-hardening
- dev-chore/delete-uploadcare-packages
- dev-chore/laravel-filament-upgrade
- dev-feat/content-urls-scope
- dev-feat/restore-crop-on-original-5.x
- dev-feat/select-filter-by-field-reference
- dev-feature/backstage-support
- dev-feature/cms-error-pages
- dev-feature/components
- dev-feature/content-url-module
- dev-feature/fix-mysql-timeout
- dev-feature/media-helpers-22-juni
- dev-feature/move-country-flags-to-support
- dev-feature/static-improvements
- dev-feature/tenant-scoped-module
- dev-feature/translation-fixes-4-march
- dev-feature/workflow-fixes
- dev-fix/crop-original-disk
- dev-fix/file-upload-repeated-field-mapping
- dev-fix/file-upload-resolve-encoded-path
- dev-fix/file-upload-single-file-replace-vanish
- dev-fix/forms-filament-v5-compat
- dev-fix/language-delete-protection
- dev-fix/mails-nav-active-route-pattern
- dev-fix/media-deprecated-form-schema
- dev-fix/meta-tags-table-select-meta-tags
- dev-fix/rich-editor-repeater-slug-collision
- dev-fix/setting-hydrates-whole-setting
- dev-fix/settings-utility
- dev-plugin-class-make-upgrade
- dev-3a441865-aa1e-43ff-be2c-56ef198d17b0
- dev-5827d013-6cc0-432f-8883-6e14692ca5a1
- dev-b87e9b65-3571-4c0f-b3f7-9caf2a8b0ea7
- dev-d5d57415-3d60-4ca2-8154-6a57dfe630bc
- dev-feat/content-link-plugin
- dev-feat/favicon-management
- dev-feat/file-upload-drop-indicators
- dev-feat/forms-fillform-pdf-and-select-filter
- dev-feat/hreflang-meta-on-page-template
- dev-feat/improve-security-workflows
- dev-feat/media-crop-sync
- dev-feat/media-management
- dev-feat/props-helpers-bindsite
- dev-feat/restore-crop-on-original
- dev-feat/robots-txt
- dev-feat/schema-support-for-fields
- dev-feat/security-workflows
- dev-feat/svg-viewbox-cropping
- dev-feat/translation-improvements
- dev-feature/integrate-forms-package
- dev-feature/parallel-tests
- dev-feature/shop-plugin-refinement
- dev-feature/uploadcare-like-transformations
- dev-feature/uploadcare-like-transformations-helpers
- dev-fix-issue-94
- dev-fix-issue-95
- dev-fix-mailing-sent-count
- dev-fix-mails-issue-77
- dev-fix-mails-tenant-routes-4x
- dev-fix/attachment-s3-download
- dev-fix/content-resource-null-type
- dev-fix/email-change-verification
- dev-fix/field-config-null-array
- dev-fix/field-visibility-inside-builder
- dev-fix/file-upload-accepted-types
- dev-fix/file-upload-reorder-reversed
- dev-fix/fileupload-save-resolve-path-to-ulid
- dev-fix/fileupload-validation-json-string
- dev-fix/fileupload-validation-type-error
- dev-fix/form-email-spam-improvements
- dev-fix/mailings-stats-listener-pipeline
- dev-fix/mails-recipient-column-bloat
- dev-fix/media-create-respects-media-model-config
- dev-fix/page-template-title-trim-og-image-height
- dev-fix/relationables-null-ulid
- dev-fix/security-vulnerabilities
- dev-fix/setting-returns-media-model-and-textarea-string
- dev-fix/shop-wefact-subscription-product-sync
- dev-fix/sitemap-pretty-print-xml
- dev-fix/uploadcare-field-standalone
- dev-fix/url-trailing-slash-root
- dev-fix/v4-safe-formula-eval
- dev-port-mails-pr-70
- dev-refactor/rename-filament-mails-to-mails
- dev-remove-laravel-ray
- dev-feat/dusk-browser-tests
- dev-e56d9946-6d79-4948-baa9-ba133cd7fbbb
- dev-feat/crop-original-image
- dev-feat/media-picker
- dev-feat/remove-files-from-s3
- dev-feat/select-media-in-rte
- dev-feature/rename-filament-mails-to-mails
- dev-fix/add-sortable-column-indexes
- dev-fix/mailgun-uuid-array-return
- dev-fix/select-undefined-array-key
- dev-fix/status-column-sortable
- dev-fix/suppression-resource-aliasing
- dev-fix/prism-meta-tags-generation
- dev-feat/crops
- dev-feature/context-aware-hydration-contracts
- dev-feature/field-translatable-macros
- dev-feature/helpers
- dev-feature/remove-path-fields-from-meta-tab
- dev-feature/searchable-parent-selection
- dev-feature/translations-16-feb-optimalisations
- dev-fix/cropper-aspect-ratio-validation
- dev-fix/redirects
- dev-release/filament-v4
- dev-feature/ai-prompts
- dev-feature/refine-hintAction
- dev-feature/prism-extension
This package is auto-updated.
Last update: 2026-12-02 09:12:21 UTC
README
Adds an AI button to Filament form fields. The button writes or rewrites the content of the field it sits on, through Prism, with any provider Prism supports.
Installation
composer require backstage/ai
php artisan vendor:publish --tag="ai-config"
config/backstage/ai.php lists the models the button offers. The key is the model, the value the Prism provider. The first one is the default.
return [ 'providers' => [ 'gpt-5.1' => 'openai', ], 'action' => [ 'label' => 'AI', 'icon' => 'heroicon-o-sparkles', 'modal' => ['heading' => 'Generate with AI'], ], 'configuration' => [ 'max_tokens' => 1000, 'temperature' => 0.7, ], ];
Provider credentials are Prism's own configuration (config/prism.php).
Usage
A button that asks what to do
RichEditor::make('body')->withAI();
The button opens a modal with an instruction field. On submit the model receives the instruction and the text the field currently holds, and its answer replaces the field. So "Rewrite this more formally" rewrites what is there, and on an empty field "Write a note that the customer wants a call on Monday" writes from the instruction alone.
A string pre-fills the instruction:
Textarea::make('summary')->withAI('Summarise the text in three sentences');
Saying what the field is for
The model knows nothing about your form. A context tells it what kind of text it is writing:
RichEditor::make('body') ->withAI(context: 'An internal note about a customer. Short and factual.'); Textarea::make('intro') ->withAI(context: fn (Get $get) => 'The introduction of an article titled ' . $get('title'));
A one-click button
Pass a closure to skip the modal. It builds the prompt, and that prompt is sent as it is; the field's own content is not added.
TextInput::make('meta_title') ->maxLength(60) ->withAI(fn (Get $get) => 'Write an SEO title for: ' . $get('name'));
What the model is told, and what is written
Every request carries a system prompt that makes the model fill a field instead of holding a conversation: reply with the field content only, treat the field's text as material and never as a message to answer, use only facts that were given.
The answer is cleaned before it reaches the field:
| Field | Asked for | Written |
|---|---|---|
RichEditor |
HTML | Sanitized HTML with p, br, strong, em, u, s, a, ul, ol, li, h2 and h3. Plain or Markdown answers are converted. |
MarkdownEditor |
Markdown | Markdown |
| anything else | Plain text | Text without markup; the field's maxLength() is passed to the model |
Images, tables and custom blocks in a rich editor do not survive a rewrite.
The field is not changed, and the user gets a warning, when:
- the field is empty and the instruction gives nothing to write from (the model answers
NO_OUTPUT, for instance for "rewrite this" on an empty field), or - the answer was cut off by the token limit.
A field that holds text always gets an answer. The model is then not offered NO_OUTPUT: it applies the instruction as far as it goes, keeps a short text short, and returns the text unchanged when the instruction asks nothing of it.
Temperature and token limit
The modal's Configuration section sends both to the model, with the defaults from the config file. Keep max_tokens roomy: an answer that does not fit is refused rather than written half. Temperature is left out for models that reject it (gpt-5 and the o-series).
Without a field
use Backstage\AI\AI; $response = AI::generateText('Return a JSON list of five keywords for: ...', 'gpt-5.1'); $response = AI::generateText($prompt, 'gpt-5.1', systemPrompt: 'Reply with the text only.', temperature: 0.2, maxTokens: 500);
With only a prompt and a model, nothing is added to the request.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.