> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage agents: create, connect, and rotate API keys

> An agent is the unit of organization in Mortem — one agent maps to one bot or strategy. Learn how to create agents, connect the SDK, and manage API keys.

An agent represents a single trading bot or strategy instance in Mortem. Every trace Mortem records belongs to an agent, and every SDK credential you give your bot is scoped to that agent. Creating an agent generates the API key your bot uses to send traces. Managing agents is where you rotate leaked keys, check connection status, and remove bots you no longer run.

## Agent list

Your agent list lives at `/app`. It shows every agent in your workspace — display name, environment (devnet or mainnet), verification status, and the date each agent was created. Click any row to open the agent detail page.

## Creating an agent

The onboarding wizard at `/app/agents/new` walks you through four steps. Each step stays visible so you can refer back to earlier credentials while you work.

<Warning>
  The API key and verify token are shown exactly once — during step 1 of the wizard. Copy both values before you leave the page. There is no way to retrieve the plaintext key after the wizard advances.
</Warning>

<Steps>
  <Step title="Name your agent">
    Enter a display name for the agent — for example `yield-hunter-v2`. Names cannot contain spaces. Click **Create agent**.

    The wizard reveals two one-time credentials:

    * `MORTEM_API_KEY` — your bot's ingest credential
    * `MORTEM_VERIFY_TOKEN` — a one-time proof-of-control token

    Copy both immediately. The verify token is single-use; once Mortem confirms your agent has connected, you can delete it from your codebase.
  </Step>

  <Step title="Install the SDK">
    Install `@mortemlabs/sdk` in your agent project:

    ```bash theme={null}
    npm install @mortemlabs/sdk
    # or
    pnpm add @mortemlabs/sdk
    ```

    The wizard pre-fills an `.env` block with all four required variables:

    ```dotenv theme={null}
    MORTEM_API_KEY=mtm_...
    MORTEM_AGENT_ID=01J...
    MORTEM_VERIFY_TOKEN=mrt_verify_...
    MORTEM_INGEST_URL=https://ingest.mortem.dev
    ```

    Add these to your agent's environment before running it.
  </Step>

  <Step title="Wrap your agent">
    The wizard provides integration snippets for OpenAI, Anthropic, Vercel AI SDK, and LangChain. Select the tab that matches your agent's LLM client and paste the snippet into your agent's entry point.

    If you prefer, expand the **Using an AI coding assistant?** section to copy a ready-made prompt for Claude Code or Codex. Paste it into your assistant and it will add the wrappers for you without touching any other agent logic.

    <Tip>
      If your agent submits Solana transactions, also wrap your connection:

      ```typescript theme={null}
      const connection = mortem.wrapConnection(new Connection(process.env.RPC_URL!))
      ```
    </Tip>
  </Step>

  <Step title="Verify the connection">
    Run your agent once. The wizard polls every four seconds and waits up to four minutes for two signals:

    1. **Connected** — Mortem received the first trace from your agent.
    2. **Verified** — the ingest service matched the `MORTEM_VERIFY_TOKEN` you included.

    When both signals arrive, the wizard shows a success state and links you to the first trace. At this point, remove `MORTEM_VERIFY_TOKEN` from your agent's environment and code — it is no longer needed.

    <Note>
      If four minutes pass without a connection, the wizard shows a troubleshooting checklist. Confirm `MORTEM_API_KEY`, `MORTEM_VERIFY_TOKEN`, and `MORTEM_INGEST_URL` are set correctly, then click **Try again**.
    </Note>
  </Step>
</Steps>

## Agent detail page

Open an agent at `/app/agents/[id]` to see two panels side by side:

* **Agent dossier** — display name, agent ID, network (devnet or mainnet), trace retention window, and quick links to the Traces list and Settings.
* **Live stream** — an SSE-backed feed of traces arriving from your bot in real time. Each row in the stream shows the trace status, ID, input summary, event count, token total, and receipt time. Click any row to open the full trace detail page.

The live stream filter accepts trace IDs, status values, and summary text. Press `/` to focus the filter, `j` and `k` to move between rows, and `Space` to toggle auto-scroll.

<Note>
  If your agent is unverified, a **Complete setup** link appears on the dossier. Click it to resume the onboarding wizard at the verification step.
</Note>

## Agent settings

Navigate to **Settings** from the agent detail page, or go directly to `/app/agents/[id]/settings`. The settings page has two functional sections and a danger zone.

### API key

The settings page shows a truncated SHA-256 hash of your current API key — never the plaintext key. Use this hash to confirm which key your bot is using without exposing the value.

To generate a new key, click **Rotate key**. The new plaintext key appears once in the settings panel. Copy it and update your bot's `MORTEM_API_KEY` environment variable before the key is dismissed.

<Warning>
  Rotating the API key immediately invalidates the old key. Any bot still using the old key will receive rejected ingest requests until you update its environment.
</Warning>

### Retention

The retention panel shows how many days Mortem retains trace payloads for this agent before cleanup. This value is set at agent creation and is read-only from the settings page.

### Deleting an agent

The **Delete agent** button in the danger zone removes the agent record and all of its linked traces. The first click changes the button to **Confirm delete** — click it again to proceed. Deletion is permanent and cannot be undone.

## Related pages

<CardGroup cols={2}>
  <Card title="Traces" icon="list" href="/dashboard/traces">
    Browse and inspect every run captured for an agent.
  </Card>

  <Card title="Analysis" icon="magnifying-glass" href="/dashboard/analysis">
    Understand the LLM-powered autopsy that appears after each trace completes.
  </Card>
</CardGroup>
