# The management agent

> A Mue agent that runs your molted.net account by chat, what it can do, how to start it and how to stop it.

**Ask your management agent:**

- "What can you do for me?"
- "Create a Mue agent for my client Acme, size Small, tagged client=acme."
- "Show me what my instances cost this month."


The **management agent** is an agent that runs your account for you. Instead of clicking through the
dashboard or writing API calls, you ask it in plain words.

## What it can do

- **Create instances** for you or your clients, from a [template](templates.md), with the right size, runtime,
  [tags](organise-clients.md) and owner path.
- **Give access**: create [invite links](access-links.md) to send to a client, or sign-in links into your
  [branded app](branded-app.md).
- **Publish your branded app** and connect your own domain.
- **Diagnose an agent** that does not answer: status, events, alerts, logs, then restart if needed.
- **Turn an instance into a template** so new clients start from it.
- **Answer questions about your account**: balance, costs per instance, usage caps.

It asks for your confirmation before anything that costs money (creating an instance, changing a size) or
deletes something.

Examples of what to ask:

- "Create an agent for Acme from my sales template, Small, tagged client=acme, and send me the invite link."
- "Which of my agents cost the most this month?"
- "The agent of Dupont does not answer, what is going on?"
- "Publish my app on app.example.com."

## Starting it

Open your dashboard and click the round chat button at the bottom right, or choose **Start with Molted** on
the **Getting started** page. The first click creates the agent; the next ones open it.

- Only the account **owner** can start it.
- It is a Mue instance of size Large, billed like any other instance. Your account needs credit for its first
  day.
- It runs on the first AI account you connect to it (Claude or ChatGPT), and on Molted Flash until then.

## How it works

The management agent uses the molted.net [API](api-overview.md), like any program you would write. When it is
created, it receives an API key named **Management agent**, stored in its own [secrets vault](secrets.md).
You see this key in **Developers → API Keys**.

- **Revoke the key** to cut its access immediately. It is revoked automatically when you delete the management
  agent.
- **Delete the agent** like any other instance when you no longer need it.

## How it does the usual jobs

The recipes below are what the management agent follows. They are written for agents, and they are useful to
anyone who drives molted.net through the [API](api-overview.md). Calls go to `https://api.<region>.molted.net`
with the account's API key (`Authorization: Bearer …`).

### An agent for a client

1. **Say what will be created and wait for a yes**: the name, the size and its monthly price (for example
   Small, $2.88 a month).
2. **Create it**: `POST /v2/instances` with
   - `handle`: lowercase, taken from the name (`anna-dupont`);
   - `tenantId`;
   - `startAgent: true`;
   - `profile`: `{ "userName": "Anna", "language": "French", "timezone": "Europe/Paris" }`;
   - no `runtime`: Mue is the default.
3. **Give the invite link right away**, without waiting for the agent to start:
   `POST /v2/instances/{id}/invite-link` with `expiresInHours` up to 48. It works while the agent is starting.
   If it is opened too early, the page says the agent is starting and the invitation stays valid: it is used
   only once, when it actually opens the agent. molted.net sends nothing: show the message to the user, then
   send it with the user's own tools (their email, their chat) if they ask.
4. **Then wait** until its `status` is `running` (usually 1 to 3 minutes): `GET /v2/instances`.
5. **Tell the new agent who it works for**: read `workspace/USER.md` with
   `GET /v2/instances/{id}/fs/read?path=workspace/USER.md` (404 on a new agent), then write it with
   `PUT /v2/instances/{id}/fs/write`. Write facts only, and nothing about the client that the client should not
   read: the client will open this agent.
6. **To open it yourself instead**, once it is running: `POST /v2/instances/{id}/open-in-application` with
   `{"applicationId": "mue-web"}` (or your branded app's id), a sign-in link, single use, valid 10 minutes. It
   answers `409` while the instance is still starting.

### A template for a type of client

Template writes still go through v1; reads are in v2.

1. **Create the template**: `POST /v1/templates` with `name`, `runtime: "molted-runtime"`, `pathBase: "home"`,
   `mode: "replace"` and its files (paths relative to the agent's home directory):
   - `workspace/mue-pages/home.json`, the suggested missions of the home screen:
     ```json
     { "version": 1, "suggestions": [
       { "label": "Estimate a property", "text": "Estimate the property at…", "hint": "address, surface", "icon": "home" }
     ] }
     ```
     Up to 8 suggestions, `label` up to 60 characters. `icon` is one of `home`, `calendar`, `messages`, `list`,
     `chart`, `star`, `bolt`, `globe`, `folder`, or an emoji. `hint` and `icon` are optional.
   - `.agents/skills/<name>/SKILL.md`, one per skill, starting with a frontmatter that has `name` and
     `description`.
   - On request, the left bar, `workspace/mue-pages/sidebar.json`:
     ```json
     { "version": 1, "items": [ { "page": "routines" }, { "page": "terminal", "hidden": true } ] }
     ```
     and a custom page, `workspace/mue-pages/<id>/index.html` with its `page.json`.
2. **Variables**: a `{{NAME}}` written in a file is a template variable. Declare it on the template and fill it
   at creation, or don't write one: otherwise creating an agent from the template fails.
3. **Create an agent from it**: `templates: [{ "name": "…" }]` in `POST /v2/instances` (with `plainValues` for
   the variables).
4. **Check**: read `workspace/mue-pages/home.json` on the new agent (`fs/read`). The cards are on its home
   screen before its first conversation.

### An agent that needs attention, or a full disk

1. **Look**: `GET /v2/instances` (its `actualState`: heartbeat, memory, `diskUsagePercent`…), then
   `GET /v2/alerts` and keep the alerts of that instance.
2. **Explain** what is wrong in plain words.
3. **For a full disk, find what takes the space**: `POST /v1/instances/{id}/exec` with
   `{"command": "du -xh -d 2 /home/agent"}`. The command runs as is, **without a shell**: no pipes, no
   redirections, no `~`. Sort the result yourself and keep the largest entries.
4. **Propose the exact list** (path and size) of what to delete and wait for a yes. Delete only that, then
   check again.
   - Caches and build outputs: fine to propose.
   - Documents, `workspace/`, memory and conversations: never, unless you name them one by one and the user
     agrees.
5. If nothing can go, propose a [bigger size](sizes.md): it applies without a restart.

A stopped instance is **not free**: it costs 10 times less than a running one.

## Using your own agent instead

Any instance can play this role: tag it `role=management-agent` and give it an API key of your account. It is
then the one the dashboard opens. This is useful if you built your own management agent, on another runtime
or with your own instructions.

Your management agent, like any agent, can read this documentation at
[/docs/llms.txt](https://www.molted.net/docs/llms.txt).
