/creating-internal-agents
Use when building an internal admin-facing AI agent in a Medusa project. These agents are operated by merchants and store operators — not customers. Covers data models, module service, agent runtime (tools, system prompt, streamText), streaming API routes (NDJSON), and admin UI
$ npx -y skills add medusajs/medusa-agent-skills --skill creating-internal-agents --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/creating-internal-agents
Context preview
The summary Claude sees to decide when to auto-load this skill.
Use when building an internal admin-facing AI agent in a Medusa project. These agents are operated by merchants and store operators — not customers. Covers data models, module service, agent runtime (tools, system prompt, streamText), streaming API routes (NDJSON), and admin UI
SKILL.md
creating-internal-agents.SKILL.mdname: creating-agents-in-medusa
description: "Use when building an internal admin-facing AI agent in a Medusa project. These agents are operated by merchants and store operators — not customers. Covers data models, module service, agent runtime (tools, system prompt, streamText), streaming API routes (NDJSON), and admin UI chat extensions. Load for any internal agent type: store operations assistant, product audit, cohort analysis, customer service tooling for support staff, etc. Do NOT use for customer-facing agents (storefront chatbots, buyer-side assistants)."
Creating Agents in Medusa
This skill covers the full stack for adding an **internal, admin-facing** AI agent to a Medusa project. These agents are used by merchants and store operators through the Medusa admin dashboard — not by customers on a storefront. For customer-facing agents (e.g. a storefront chatbot), a different architecture is needed: public API routes, no MedusaExec, and storefront auth.
Constraints
- **Internal use only** — this architecture is for admin users (merchants, operators, support staff), not customers. Routes live under `src/api/admin/`, the UI lives in the Medusa admin dashboard, and access is gated by admin authentication throughout.
- **Authentication is non-negotiable** — MedusaExec runs arbitrary TypeScript with full database access. All agent routes must use `AuthenticatedMedusaRequest` and live under `src/api/admin/`. An unauthenticated endpoint is a remote code execution vulnerability.
- **Use MedusaExec, not custom tools** — for any data operation, the agent writes TypeScript and executes it via MedusaExec. Only build a custom tool for capabilities that cannot be expressed as executable TypeScript (e.g. calling an external API with a secret key).
- **One shared module, multiple agents** — `AgentSession` and `AgentMessage` are shared infrastructure. Use `agent_type` to distinguish sessions per agent. Never create separate models per agent.
- **Pass `MedusaContainer` via `experimental_context`** — never import services directly in tool files; that causes circular dependencies.
- **Stream format is NDJSON** — `Content-Type: application/x-ndjson`, one JSON object per line followed by `\n`.
- **Run migrations** after adding or changing models (`npx medusa db:generate agent && npx medusa db:migrate`).
- **Tool descriptions live in config**, not inline in `tool()` — the config object overrides them at runtime.
CRITICAL: Load Reference Files When Needed
**⚠️ The quick reference below is NOT sufficient for implementation.** Load the relevant reference file before writing any code.
| Task | Load this file | |------|---------------| | Defining conversation models | `reference/data-models.md` | | Setting up the module service | `reference/service.md` | | Configuring tools, prompt, streamText | `reference/agent-setup.md` | | Building the POST chat endpoint | `reference/api-route.md` | | Implementing NDJSON streaming | `reference/streaming.md` | | Building the admin chat UI | `reference/admin-extension.md` | | Giving the agent code execution capability | `reference/medusa-exec.md` |
**Minimum requirement:** Load at least the reference file matching your current task before writing code.
Related Skills
Load these alongside this skill when relevant:
- **`building-with-medusa`** — Medusa module patterns, workflows, data model conventions. Load when implementing the module service or custom backend logic.
- **`building-admin-dashboard-customizations`** — Admin UI component patterns, TanStack Query, route registration. Load when building or extending the admin chat UI.
Architecture Overview
src/modules/agent/
index.ts ← Module() export + AGENT_MODULE constant
service.ts ← MedusaService + Anthropic client + stream(messages, container, config)
models/
session.ts ← AgentSession (shared across all agents, filtered by agent_type)
message.ts ← AgentMessage
agents/index.ts ← streamText() orchestration
tools/
medusa-exec.ts ← MedusaExec tool (primary tool for all data operations)
todo-write.ts ← TodoWrite tool
config/
<agent-type>.ts ← per-agent system prompt + tool descriptions
src/api/admin/agent/<agent-type>/
route.ts ← POST (AuthenticatedMedusaRequest, session lifecycle, NDJSON stream)
sessions/route.ts ← GET session list (filtered by agent_type)
sessions/[id]/route.ts ← GET messages for a session
src/admin/routes/<agent-type>/
page.tsx ← React chat UI (admin extension)
src/lib/code-mode/
executor.ts ← sandboxed TypeScript executor used by MedusaExecCommon Mistakes
Verify you are NOT doing these:
**Security:**
- [ ] Agent route uses `MedusaRequest` instead of `AuthenticatedMedusaRequest`
- [ ] Agent route placed outside `src/api/admin/`
**Architecture:**
- [ ] Creating separate `AgentSession`/`AgentMessage` models per agent instead of using `agent_type`
- [ ] Importing services directly in tool files instead of resolving from `experimental_context`
- [ ] Building a custom tool for a data operation instead of using MedusaExec
**Streaming:**
- [ ] Missing `res.end()` after the stream loop (response never closes)
- [ ] Missing `Transfer-Encoding: chunked` or `Content-Type: application/x-ndjson` headers
- [ ] Not buffering incomplete lines on the client (JSON parse errors on split packets)
**Module:**
- [ ] Forgetting to register the module in `medusa-config.ts`
- [ ] Forgetting to run migrations after changing models
- [ ] Hardcoding tool descriptions in `tool()` instead of the config object
Reference Files Available
reference/data-models.md - model.define(), agent_type discriminator, relationships, migrations
reference/service.md - MedusaService extension, Anthropic init, stream(), module index, config registration
reference/agent-setup.md - streamText(), MedusaExec to
Read more
name: creating-agents-in-medusa description: "Use when building an internal admin-facing AI agent in a Medusa project. These agents are operated by merchants and store operators — not customers. Covers data models, module service, agent runtime (tools, system prompt, streamText), streaming API routes (NDJSON), and admin UI chat extensions. Load for any internal agent type: store operations assistant, product audit, cohort analysis, customer service tooling for support staff, etc. Do NOT use for customer-facing agents (storefront chatbots, buyer-side assistants)."
Creating Agents in Medusa
This skill covers the full stack for adding an **internal, admin-facing** AI agent to a Medusa project. These agents are used by merchants and store operators through the Medusa admin dashboard — not by customers on a storefront. For customer-facing agents (e.g. a storefront chatbot), a different architecture is needed: public API routes, no MedusaExec, and storefront auth.
Constraints
- **Internal use only** — this architecture is for admin users (merchants, operators, support staff), not customers. Routes live under `src/api/admin/`, the UI lives in the Medusa admin dashboard, and access is gated by admin authentication throughout.
- **Authentication is non-negotiable** — MedusaExec runs arbitrary TypeScript with full database access. All agent routes must use `AuthenticatedMedusaRequest` and live under `src/api/admin/`. An unauthenticated endpoint is a remote code execution vulnerability.
- **Use MedusaExec, not custom tools** — for any data operation, the agent writes TypeScript and executes it via MedusaExec. Only build a custom tool for capabilities that cannot be expressed as executable TypeScript (e.g. calling an external API with a secret key).
- **One shared module, multiple agents** — `AgentSession` and `AgentMessage` are shared infrastructure. Use `agent_type` to distinguish sessions per agent. Never create separate models per agent.
- **Pass `MedusaContainer` via `experimental_context`** — never import services directly in tool files; that causes circular dependencies.
- **Stream format is NDJSON** — `Content-Type: application/x-ndjson`, one JSON object per line followed by `\n`.
- **Run migrations** after adding or changing models (`npx medusa db:generate agent && npx medusa db:migrate`).
- **Tool descriptions live in config**, not inline in `tool()` — the config object overrides them at runtime.
CRITICAL: Load Reference Files When Needed
**⚠️ The quick reference below is NOT sufficient for implementation.** Load the relevant reference file before writing any code.
| Task | Load this file | |------|---------------| | Defining conversation models | `reference/data-models.md` | | Setting up the module service | `reference/service.md` | | Configuring tools, prompt, streamText | `reference/agent-setup.md` | | Building the POST chat endpoint | `reference/api-route.md` | | Implementing NDJSON streaming | `reference/streaming.md` | | Building the admin chat UI | `reference/admin-extension.md` | | Giving the agent code execution capability | `reference/medusa-exec.md` |
**Minimum requirement:** Load at least the reference file matching your current task before writing code.
Related Skills
Load these alongside this skill when relevant:
- **`building-with-medusa`** — Medusa module patterns, workflows, data model conventions. Load when implementing the module service or custom backend logic.
- **`building-admin-dashboard-customizations`** — Admin UI component patterns, TanStack Query, route registration. Load when building or extending the admin chat UI.
Architecture Overview
src/modules/agent/
index.ts ← Module() export + AGENT_MODULE constant
service.ts ← MedusaService + Anthropic client + stream(messages, container, config)
models/
session.ts ← AgentSession (shared across all agents, filtered by agent_type)
message.ts ← AgentMessage
agents/index.ts ← streamText() orchestration
tools/
medusa-exec.ts ← MedusaExec tool (primary tool for all data operations)
todo-write.ts ← TodoWrite tool
config/
<agent-type>.ts ← per-agent system prompt + tool descriptions
src/api/admin/agent/<agent-type>/
route.ts ← POST (AuthenticatedMedusaRequest, session lifecycle, NDJSON stream)
sessions/route.ts ← GET session list (filtered by agent_type)
sessions/[id]/route.ts ← GET messages for a session
src/admin/routes/<agent-type>/
page.tsx ← React chat UI (admin extension)
src/lib/code-mode/
executor.ts ← sandboxed TypeScript executor used by MedusaExecCommon Mistakes
Verify you are NOT doing these:
**Security:**
- [ ] Agent route uses `MedusaRequest` instead of `AuthenticatedMedusaRequest`
- [ ] Agent route placed outside `src/api/admin/`
**Architecture:**
- [ ] Creating separate `AgentSession`/`AgentMessage` models per agent instead of using `agent_type`
- [ ] Importing services directly in tool files instead of resolving from `experimental_context`
- [ ] Building a custom tool for a data operation instead of using MedusaExec
**Streaming:**
- [ ] Missing `res.end()` after the stream loop (response never closes)
- [ ] Missing `Transfer-Encoding: chunked` or `Content-Type: application/x-ndjson` headers
- [ ] Not buffering incomplete lines on the client (JSON parse errors on split packets)
**Module:**
- [ ] Forgetting to register the module in `medusa-config.ts`
- [ ] Forgetting to run migrations after changing models
- [ ] Hardcoding tool descriptions in `tool()` instead of the config object
Reference Files Available
reference/data-models.md - model.define(), agent_type discriminator, relationships, migrations reference/service.md - MedusaService extension, Anthropic init, stream(), module index, config registration reference/agent-setup.md - streamText(), MedusaExec to
A collection of skills composed as Claude Code plugins for building Medusa applications with best practices and architectural patterns. These skills can be used with any agent, as explained in the Usage with Other Agents section.
Repo: medusajs/medusa-agent-skills
Other skills on medusa-agent-skills.
- /storefront-best-practices
ALWAYS use this skill when working on ecommerce storefronts, online stores, shopping sites. Use for ANY storefront component including checkout pages, cart, payment flows, product pages, product listings, navigation, homepage, or ANY page/component in a storefront. CRITICAL for
Open skill - /learning-medusa
Load automatically when user asks to learn Medusa development (e.g., "teach me how to build with medusa", "guide me through medusa", "I want to learn medusa"). Interactive guided tutorial where Claude acts as a coding bootcamp instructor, teaching step-by-step with checkpoints
Open skill - /mcloud-auth
Execute mcloud authentication and context commands: login, logout, whoami, use, version, and signup. Use when setting up the CLI, switching accounts, verifying auth state, setting the active org/project/environment context, or checking the CLI version.
Open skill - /mcloud-deployments
Execute mcloud deployments commands to list deployments, retrieve deployment details, and fetch build logs. Use when listing deployments, checking deployment status, or reading build output for debugging build failures.
Open skill - /mcloud-environments
Execute mcloud environments commands to list, get, create, delete, redeploy, or trigger builds for Cloud environments. Use when managing environment lifecycle, redeploying after variable changes, or starting new builds from source.
Open skill - /mcloud-local
Execute mcloud local build to reproduce a Cloud build on the local machine. Use when debugging a build-failed deployment without pushing to the tracked branch, iterating on a build fix, or testing build-variable changes locally. Requires Docker and must run inside the project's
Open skill

