Blog

Medusa builds e-commerce agents with Mastra

MedusaJS is the most popular open-source Javascript e-commerce framework, with over 29K stars on Github, and helps companies build custom online stores. Founded in 2021 and headquartered in Copenhagen, Denmark, the 15 person team has raised $9M across two funding rounds, including an $8M seed round in 2022 led by Dawn Capital.

Choosing Mastra to iterate quickly

Co-founders Oli & Seb wanted to quickly test different agent architectures for a new "AI solutions engineer" that would allow users to ask an agent to build features into stores end-to-end. Because they were a Typescript framework, Mastra was the natural choice.

Mastra's built-in eval framework and local development environment allowed the team to prototype different agent configurations, while the workflow visualization helped them understand how different architectures performed in practice

"Mastra's TypeScript framework enabled us to quickly experiment with different architectures using the primitives and the dashboard gave us easy visibility into execution state and memory persistence. We used multiple eval frameworks to determine which configurations best handled feature generation requests."

Senior Software Engineer Riqwan Thamir demonstrates the MedusaJS AI solutions engineer agent in the Mastra Cloud

First approach: multi-agent

Using Mastra's workflow primitives, the team built their first architecture with separate agents handling different parts of the e-commerce feature pipeline

"We started out with a fleet of agents because we thought, well, for every component that we need to do, let's have an agent that does it," said Oli Juhl, co-founder and CTO. Mastra made it simple to set up different agent configurations and test coordination patterns. Medusa built separate agents for database models, API endpoints, frontend components, and business logic.

The initial results were mixed. "We were having some problems with the accuracy and the transferable knowledge between the agents and the latency between all the agents and the different tools they were using," explained Senior Software Engineer Adrien De Peretti.

The agents couldn't maintain context about how different parts of the system connected. An agent generating a database model didn't understand how frontend components would consume the data, leading to mismatched interfaces and integration problems.

The successful approach: single-agent architecture

But because Mastra has single-agent, multi–agent, and workflow primitives, when multi-agent didn't work as expected, the team could pivot quickly to test a completely different architecture with only minor code changes.

"The best results we have seen have come from using one agent…with the entire code base fed into the context," Juhl explained. "Both the storefront and the entire Medusa repo into the context using Gemini."

Putting the whole codebase in context made an immediate difference. "If we provide everything like the entire code base of both projects, we are able to build end to end features with some pretty strict guardrails included in the prompt," Juhl noted.

The single-agent approach generated code that imported existing modules correctly, followed established patterns, and integrated with database schemas. "Even the simplest prompts actually give very good results," Juhl observed. "We can write something as simple as 'build me a product review feature for my e-commerce store' and it builds it end-to-end."

"The developer experience is pretty fantastic," Juhl noted. "We were able to set up and test quickly with your framework which I really love" and quickly made the decision to release this agent as an experimental feature to certain customers.

A successful rollout

Medusa notes impressive initial results from the "solutions engineer" agent with external users. According to Juhl, "PRs have been validated and merged into repositories - we're moving forward with a greater rollout as we speak!" The success of these production deployments has led Medusa to open access to more developers, and begin integration work to ship alongside existing tools.

Share

Stay up to date