Skip to content

[6.x] AI connections - #20006

Merged
brandonkelly merged 13 commits into
6.xfrom
feature/ai-connections
Oct 18, 2026
Merged

brandonkelly merged 13 commits into
6.xfrom
feature/ai-connections

Conversation

@riasvdv

@riasvdv riasvdv commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds AI connections: one place where core and plugins get AI provider access. Customers bring their own keys. Admins choose a provider and model per task under Settings → AI → Connections.

config/ai.php (laravel/ai, owned by the app)   ← provider keys from env vars
        │
Settings → AI → Connections (project config `ai`)  ← default provider/model per modality
        │                                           + per-task: enabled, provider, model ($ENV refs allowed)
        ▼
AiTasks registry ── plugin registers DescribeImage::class (handle, label, modality)
        │
Ai::task('altText:describe')
  ├─ resolve()      → ResolvedProvider (provider, model) or AiUnavailableException
  ├─ prompt()/stream()/queue()   (laravel/ai agents)
  └─ generate()/rerank()/classify()  (images, audio, transcription, embeddings, …)
        │
TaskRunning (cancelable) → TaskCompleted (usage, duration) | TaskFailed
  • Off until configured: Craft never falls back to ai.default. A task is available only once Craft's settings choose a provider for it or for its modality.
  • Host config untouched: connections are the app's ai.providers entries. Craft stores no keys.
  • Tasks are classes registered through TypeRegistry (AiTasks). Labels are translated at render time.
  • Queued prompts resolve the task when the job runs, so disabling or remapping a task affects queued work.
  • Events let plugins track usage and cost, count failures, or enforce limits by canceling requests.
  • Settings nav: a new AI section groups Connections and MCP. MCP moves out of System.
  • Embeddings warning appears in the settings when a registered task uses embeddings, because remapping it invalidates stored vectors.
  • Adds laravel/ai: ^1.2. laravel/mcp, a dev dependency through Boost, moves from 0.9.4 to 1.0.2 to satisfy its conflict rule.
  • Plugin docs: docs/ai.md..

Evidence

Settings → AI → Connections in the workbench, with two workbench tasks registered locally (the workbench registration isn't part of this PR):

AI connections screen

Tests (tests/Unit/Ai, tests/Feature/Ai):

host app has ai.default = openai, Craft has no default  → resolve() throws NoDefault, available() = false
task disabled after queue()                             → job throws TaskDisabled when it runs
TaskRunning listener sets cancel                        → no request sent, no TaskFailed
provider not in ai.providers                            → save rejected
provider '$AI_TEST_PROVIDER' (= anthropic)              → accepted, stored as written

composer ci passes locally (Pint, Rector, PHPStan, 10,906 core tests, adapter tests).

Admins choose providers and models for AI tasks under Settings → AI.
Providers come from laravel/ai's ai.providers config. Plugins register
task classes and run laravel/ai agents and requests through them.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

@riasvdv
riasvdv requested a review from brandonkelly October 17, 2026 12:51
@riasvdv
riasvdv marked this pull request as ready for review October 17, 2026 12:51
riasvdv and others added 10 commits October 17, 2026 15:15
Model fields list the default, cheapest, and smartest models laravel/ai names
for the chosen provider, refreshing when a provider changes. Provider fields
only offer providers that implement the modality's contract, and saving
enforces it. Drop the display-only Capability enum in favor of task descriptions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The AI settings screen lists each enabled task that can't run, with the reason, and other control panel screens show an alert linking to it. Providers without an API key are marked in the provider menus, and task details put the plugin name on its own line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…warnings

Warn admins about AI tasks that can't run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brandonkelly
brandonkelly merged commit 4c952ef into 6.x Oct 18, 2026
18 checks passed
@brandonkelly
brandonkelly deleted the feature/ai-connections branch October 18, 2026 23:03
@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

CMS-2553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants