# creating-internal-agents

creating-internal-agents — a skill for building an admin-side AI agent in Medusa: conversation models, module service, streamText() runtime, NDJSON route and a chat page.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 500 installs · ★ 237 repo stars
- Author: medusajs
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/medusajs/medusa-agent-skills/tree/HEAD/plugins/medusa-dev/skills/creating-internal-agents/SKILL.md
- Updated: 2026-10-21
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/creating-internal-agents

## What it does

The skill walks through the whole stack of an admin-side AI agent in Medusa: conversation models, a module service that holds the Anthropic client and a `stream()` method, the runtime built on `streamText()`, a POST route streaming NDJSON, and a chat page inside the dashboard.

Data work goes through MedusaExec, where the agent writes TypeScript and runs it. A custom tool earns its place only when code can't do the job, an outside API behind a secret key for instance. Every agent shares `AgentSession` and `AgentMessage`; the `agent_type` field keeps their sessions apart. Pass the container through `experimental_context` — importing services straight into tool files creates circular dependencies.

Admin auth is not optional. Routes sit under `src/api/admin/` and take `AuthenticatedMedusaRequest`, since MedusaExec executes arbitrary code with database access. An endpoint left open there means remote code execution. Model changes need migrations (`npx medusa db:generate agent && npx medusa db:migrate`), and the skill wants the matching reference file loaded before any code gets written.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add medusajs/medusa-agent-skills --skill creating-internal-agents -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/creating-internal-agents/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/creating-internal-agents/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add medusajs/medusa-agent-skills --skill creating-internal-agents -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/creating-internal-agents/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add medusajs/medusa-agent-skills --skill creating-internal-agents -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/creating-internal-agents/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install medusajs/medusa-agent-skills plugins/medusa-dev/skills/creating-internal-agents
```

2. **Manually: put the files in place**
- File: `.github/skills/creating-internal-agents/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add medusajs/medusa-agent-skills --skill creating-internal-agents -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/medusajs/medusa-agent-skills --path plugins/medusa-dev/skills/creating-internal-agents
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/creating-internal-agents/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add medusajs/medusa-agent-skills --skill creating-internal-agents -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/medusajs/medusa-agent-skills/tree/HEAD/plugins/medusa-dev/skills/creating-internal-agents/SKILL.md

## When to use it
- define conversation models for an admin chat agent in Medusa
- set up a module service with the Anthropic client and `stream()`
- stream an agent reply as NDJSON from a POST route
- add a chat page to the Medusa admin dashboard
- let the agent execute TypeScript through MedusaExec

## Example prompts
- Set up the `agent` module with `AgentSession` and `AgentMessage` plus an `agent_type` field
- Create the POST route under `src/api/admin/agent/` with `AuthenticatedMedusaRequest` and NDJSON streaming
- Add an admin chat page for a store operations agent

## Similar
- [creating-plugins](https://affpapa.org/en/nevibecode/skills/creating-plugins.md) — skill · 1600 installs
- [convex-agents](https://affpapa.org/en/nevibecode/skills/convex-agents.md) — skill · 1500 installs
- [medusa](https://affpapa.org/en/nevibecode/skills/medusa.md) — skill · 285 installs
- [mastra-hono](https://affpapa.org/en/nevibecode/skills/mastra-hono.md) — skill · 397 installs
- [convex](https://affpapa.org/en/nevibecode/skills/convex.md) — skill · 116100 installs
- [developing-genkit-js](https://affpapa.org/en/nevibecode/skills/developing-genkit-js.md) — skill · 3600 installs

From the same set: [medusajs/medusa-agent-skills](https://affpapa.org/en/nevibecode/by/medusajs/medusa-agent-skills.md) — 17 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
