Skip to content
Free Magento 2 moduleOpen source · MIT

The Magento AI SDK.

Inspired by the Laravel AI SDK, built for Magento 2 and Mage-OS. It gives your modules one API for agents, tools and structured output, with providers you can swap or fail over per call. Free and MIT-licensed.

Free
no card needed
MIT
open source on GitHub
PHP 8.2+
Magento 2.4.8+ & Mage-OS
1 API
agents, tools, structured output
Spec sheetMagento 2.4.8+Mage-OSPHP 8.2 to 8.5Anthropic driverAgents and toolsStructured outputProvider failoverTesting fakesMIT licence
Magento AI SDK

AI features in Magento,
without the plumbing.

Write an agent as a PHP class, prompt it, and read the answer. The SDK handles the HTTP calls, the tool loop, schema validation, failover and events, so your module only holds the part that is yours.

What it doesEverything in the boxFree · all 6 included

Agents as plain PHP classes

An agent is a class with instructions. Add tools, conversation history, an output schema or middleware by implementing an interface, and tune the model, step limit and timeout with PHP attributes.

Structured output you can rely on

Describe the response with a schema builder and read the result like an array. No parsing JSON out of free text.

Tools that call your own code

Give an agent a tool, such as looking up an order, and the model calls it when it needs to. Arguments are validated against the tool's schema, and errors go back to the model to correct.

Failover between providers

Pass a list of providers and the next one is tried when the first is rate limited, overloaded, out of credit or unreachable. Build a provider at runtime too, for example with a key stored per customer.

Fakes for unit tests

Fake any agent to return canned responses and assert what it was asked. Fakes need no API key and no ObjectManager, so they run in plain unit tests.

Magento events and middleware

Every run, step and tool call fires a Magento event, so logging token usage is one observer. Middleware runs on each step to cap spend or remove a tool.

ExamplesFive things to build this weekVendor/Module/Ai

Real Magento jobs. A few lines each.

Each example is a complete class or call using the SDK as it ships today. Pick one, change the instructions and you have a working feature.

Ai/Agents/ProductCopywriter.php
#[MaxTokens(600)]
class ProductCopywriter implements AgentInterface, HasStructuredOutputInterface
{
    use Promptable;

    public function instructions(): string
    {
        return 'You write product copy for an online store. Plain, specific, no hype.';
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'meta_title' => $schema->string()->description('Under 60 characters')->required(),
            'meta_description' => $schema->string()->required(),
            'bullets' => $schema->array()->items($schema->string())->required(),
        ];
    }
}

$copy = (new ProductCopywriter)->prompt(
    $product->getName() . "\n" . $product->getDescription()
);

$product->setMetaTitle($copy['meta_title']);
$product->setMetaDescription($copy['meta_description']);
Example response
meta_title        'Waxed Field Jacket in Olive | Water-Resistant Cotton'
meta_description  'A waxed cotton field jacket with four pockets and a…'
bullets           ['Waxed cotton shell', 'Corduroy collar', 'Two-way zip']
03 · Getting started

Install to first response, in four steps.

$ composer require upturnstudio/module-ai
$ bin/magento setup:upgrade
Module UpturnStudio_Ai enabled
  1. Step 1

    Install the module

    Composer require it and run setup:upgrade, like any other Magento module.

  2. Step 2

    Add your API key

    Paste an Anthropic key under Stores › Configuration › UpturnStudio › AI. It is stored encrypted.

  3. Step 3

    Check the connection

    Run bin/magento upturn:ai:prompt "Say hello" to make one real request from the command line.

  4. Step 4

    Write an agent

    Add a class with instructions, call prompt() and read the response. Add tools or a schema when you need them.

04 · Before you install

What you need, and what it won’t do.

Every module lists its limitations up front, so there are no surprises after install.

Requirements

Magento 2.4.8 or later, or Mage-OS
PHP 8.2 to 8.5
An Anthropic API key

Known limitations

It is a work in progress. Anthropic is the only provider so far. OpenAI, Gemini and OpenAI-compatible providers such as Ollama are planned next.
Streaming, conversation memory, tool approval, queueing, files, images and audio are not built yet.
It is a library for developers. It adds no storefront or admin features on its own, only a configuration section and a test command.
Anthropic ignores the `Temperature` and `TopP` attributes, because its current API rejects sampling parameters.
You pay your AI provider for the tokens you use. The module itself is free.
Open source

MIT-licensed. Read every line.

The source, the unit tests and a progress file tracking each section of the Laravel AI SDK docs against this module are all on GitHub. Issues and pull requests are welcome.

View on GitHub
FAQ

Questions, answered straight.

Is it really free?

Yes. The module is MIT-licensed and free to use in client and commercial projects. You pay your AI provider for the tokens you use.

Which AI providers does it support?

Anthropic today. OpenAI, Gemini and OpenAI-compatible providers such as Ollama are planned next, and you can register your own driver in di.xml in the meantime.

Do I need to know Laravel?

No. The API is inspired by the Laravel AI SDK, so it will feel familiar if you do, but it is plain Magento: interfaces, dependency injection, admin config and Magento events.

Is it ready for production?

It is a work in progress. Agents, tools, structured output, failover, middleware, events and fakes are built and unit-tested. Streaming, conversation memory, queueing, files, images and audio are not built yet.

What do I get when I claim it?

An account with the install commands and the full guide: configuration, agents, tools, middleware, failover, events, testing and writing your own driver.

Ship your first Magento agent.

Create a free account for the full guide, then install it with Composer like any other module.

  • A free account with the full setup guide
  • Installed with Composer from Packagist
  • Source on GitHub

Need this customised for your store, or a module that does not exist yet? I build and support Magento 2 stores as a freelance Magento developer.