Loading...
Loading...
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).
npx skill4agent add medusajs/medusa-agent-skills creating-agents-in-medusasrc/api/admin/AuthenticatedMedusaRequestsrc/api/admin/AgentSessionAgentMessageagent_typeMedusaContainerexperimental_contextContent-Type: application/x-ndjson\nnpx medusa db:generate agent && npx medusa db:migratetool()| Task | Load this file |
|---|---|
| Defining conversation models | |
| Setting up the module service | |
| Configuring tools, prompt, streamText | |
| Building the POST chat endpoint | |
| Implementing NDJSON streaming | |
| Building the admin chat UI | |
| Giving the agent code execution capability | |
building-with-medusabuilding-admin-dashboard-customizationssrc/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 MedusaExecMedusaRequestAuthenticatedMedusaRequestsrc/api/admin/AgentSessionAgentMessageagent_typeexperimental_contextres.end()Transfer-Encoding: chunkedContent-Type: application/x-ndjsonmedusa-config.tstool()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 tool wiring, system prompt, context passing
reference/api-route.md - POST route, session lifecycle, message persistence, streaming headers
reference/streaming.md - NDJSON emission, fullStream iteration, chunk types, client-side parsing
reference/admin-extension.md - React chat UI, streaming fetch, message rendering, tool call display, session sidebar
reference/medusa-exec.md - Executor setup, MedusaExec tool, query.graph() patterns, error codesnpx medusa developdefineRouteConfigContent-Type: application/x-ndjson[agent] tool_call[agent] step_finishagent_sessionagent_messageagent_type