# Evaluate an agent from the command line with the MorganaBench CLI

In this tutorial we will evaluate an agent's answers against a MorganaBench benchmark, entirely from the command line using the `mb` CLI. We will start from a file of agent responses, submit it for scoring, watch the evaluation run, and download a results file containing per-metric scores. Along the way we will become familiar with the `mb login`, `mb metrics list`, `mb eval create`, `mb eval get`, and `mb eval download` commands.

By the end of this tutorial, you will have a `results.json` file containing the evaluation scores for an agent that answered questions about U.S. presidential inaugural speeches.

## Prerequisites

- The MorganaBench CLI installed (`mb`). If you don't have it yet, install it with:

    ```bash
    curl -fsSL https://raw.githubusercontent.com/morganalabs/mb-cli/main/install.sh | bash
    ```
    !!! note
        You will probably need to enter your machine's password to authorize the installation.

- A MorganaBench account (email as username and password).
- The URL of your MorganaBench server, e.g., `https://morganabench.example.com`.

## Step 1: Confirm the CLI is installed

First, check that the `mb` binary is on your path:

```bash
mb version
```

The output should look something like:

```
api:                 {
    "git_hash": "a12916e9",
    "version": "0.1.0"
  }
cli_version:         0.2.4
commit:              bcf8dcafa1a17ee535241fcff070ce48c3f8cb8d
date:                2026-04-05T10:22:01Z
server_url:          https://morganabench.morganalabs.ai
```

If instead you see `command not found: mb`, the CLI is not installed yet — return to the [CLI Guide](../cli-guide/index.md#installation) and install it before continuing.

## Step 2: Log in

Now, log in with your email and password:

```bash
mb login --url https://morganabench.example.com \
    --email you@example.com --password your-password
```

The output should look something like:

```
Login successful
  Email:   you@example.com
  Profile: default
  URL:     https://morganabench.example.com
  Token expires in: 86400s
```

You will notice a new file appears at `~/.morganabench/tokens.yaml`. This holds your access token, so every command from here on authenticates automatically — you won't need to pass your password again.

Let's check that the login worked:

```bash
mb whoami
```

The output includes several of your credentials and should look something like:

```
created_at:          2026-05-03T05:33:52.965234Z
email:               you@example.com
full_name:           your name
id:                  <your id>
last_login_at:       2026-07-21T08:07:33.355992Z
organization_id:     <your organization id>
role:                your role
server_url:          https://morganabench.example.com
status:              active
updated_at:          2026-07-21T08:07:33.355992Z
```

## Step 3: Get the agent's answers

For this tutorial we will use a ready-made file of agent responses so you can focus on the evaluation itself. The file contains 50 test cases about U.S. inaugural speeches, each already answered by an agent (see [agent response](./mb-eval-ui.md#example-implementation-agent-execution-and-response-collection-steps-2-and-3) for a simple agent execution for generating the file).

Download it into your current directory:

```bash
curl -o Inaugural_speeches_benchmark_executed.jsonl \
    https://raw.githubusercontent.com/morganalabs/mb-resources/refs/heads/main/Inaugural_speeches_benchmark_executed.jsonl
```

Let's check that the file arrived and see how many cases it holds:

```bash
wc -l Inaugural_speeches_benchmark_executed.jsonl
```

The output should look something like:

```
      50 Inaugural_speeches_benchmark_executed.jsonl
```

Notice that there are ~50 lines — each line is one test case, in JSONL format (one JSON object per line). Let's peek at the very first one:

```bash
head -n 1 Inaugural_speeches_benchmark_executed.jsonl | python3 -m json.tool
```

You will notice each case has three important parts:

- `inputs` — the question that was asked
- `expectations` — the reference (ground-truth) answer
- `outputs` — the answer **the agent produced**

That last part, `outputs.response`, is what we are about to have MorganaBench score.

## Step 4: See which metrics are available

Before we score anything, let's see the metrics MorganaBench can measure:

```bash
mb metrics list
```

The output should look something like:

```
Built-in metrics:
id                          name                        direction         range
-------------------------------------------------------------------------------
ground_truth_alignment      ground_truth_alignment      higher_is_better  0-1
ground_truth_contradiction  ground_truth_contradiction  lower_is_better   0-1
faithfulness                faithfulness                higher_is_better  0-1
query_relevance             query_relevance             higher_is_better  0-1
context_sufficiency         context_sufficiency         higher_is_better  0-1
refusal                     refusal                     lower_is_better   0-1
tool_call_correctness       tool_call_correctness       higher_is_better  0-1
no_tool_call_correctness    no_tool_call_correctness    higher_is_better  0-1

Custom metrics:
No items found.

Total: 8
```

The built-in metrics are the ones MorganaBench ships; custom metrics are the ones your organization has authored, so yours may list some. To see what each metric measures, add `--output json`: every row then carries a `description`.

For this tutorial we will use two of them. `ground_truth_alignment`: The degree to which the reference answer is covered by the response. It is scored from `0.0` to `1.0`, and higher is better. `refusal`: The rate at which the agent refuses requests it was expected to answer. Each case scores `0` or `1`, and lower is better. For a full description of each metric and how to read its scores, see [Metrics](../reference/metrics.md).

## Step 5: Create the evaluation

Now for the main event. We will submit the file for scoring against our two chosen metrics:

```bash
mb eval create "Inaugural speeches CLI eval" \
    --file Inaugural_speeches_benchmark_executed.jsonl \
    --metrics ground_truth_alignment,refusal
```

The command will print progress to your terminal while it works. You will notice that it does **not** return immediately — by default `mb eval create` waits, polling the server until scoring finishes. This may take a few minutes, since the server is scoring all 50 cases across both metrics.

When it completes, the output should look something like:

```
Uploading Inaugural_speeches_benchmark_executed.jsonl...
Evaluation created: cde79124223a48ecb923c7265063197a
Waiting for evaluation cde79124223a48ecb923c7265063197a...
  Status: pending
  Status: processing
  Status: processing
  ...
  Status: processing
  Status: ready
```

Notice the status line marching through `pending → processing → ready`. That final `ready` is the signal that scoring is complete.

Copy that evaluation ID — we will use it in the next steps. To keep it handy, run the command again capturing the ID into a shell variable:

```bash
EVAL_ID=$(mb eval create "Inaugural speeches CLI eval 2" \
    --file Inaugural_speeches_benchmark_executed.jsonl \
    --metrics ground_truth_alignment,refusal \
    --output json --quiet | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])')

echo "$EVAL_ID"
```
!!! note
    If your session has expired since you logged in (the token lasts 24 hours), run `mb login` again to renew it before continuing.

You will notice this run is quieter — the `--quiet` flag suppresses the progress lines, and `--output json` gives us machine-readable output we can pull the ID from. The `echo` prints just the bare ID, which should look something like:

```
a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d
```

## Step 6: Look at the scores

Let's check the results. Ask for the evaluation by its ID:

```bash
mb eval get "$EVAL_ID"
```

The `results` field of the output should look something like:

```json
  {
    "ground_truth_alignment": {
      "confidence_interval": [
        0.5244326316839827,
        0.7585091164438398
      ],
      "mean_score": 0.6414708740639112,
      "n_errors": 1,
      "n_ineligible": 0,
      "n_scored": 49,
      "n_total": 50
    },
    "refusal": {
      "confidence_interval": [
        0,
        0
      ],
      "mean_score": 0,
      "n_errors": 0,
      "n_ineligible": 0,
      "n_scored": 50,
      "n_total": 50
    }
  }
```

Notice the two numbers that matter most:

- `ground_truth_alignment` mean score is `~0.641` — on average, the agent's responses were a fairly good match for the reference answers (scores run from `0.0` to `1.0`).
- `refusal` mean score is `0.000` — the agent never refused a request it was expected to answer.

Remember that for `ground_truth_alignment` higher is better, while for `refusal` lower is better. Our agent did well on both.

## Step 7: Download the detailed results

The summary is useful, but the full results — including a score and explanation for *every individual case* — live in a downloadable file. Let's get it:

```bash
mb eval download "$EVAL_ID" -o results.json
```

The output should look something like:

```
Downloaded to results.json
```

Let's check what's inside. Look at the scores for the first case:

```bash
head -n 1 results.json | python3 -c 'import json,sys; print(json.dumps(json.loads(sys.stdin.readline())["assessments"], indent=2, ensure_ascii=False))'
```

You will notice each case now carries an `assessments` object, with one entry per metric, which should look something like:

```json
[
  {
    "name": "ground_truth_alignment",
    "value": 0.7058823529411765,
    "error": null,
    "ineligible": null,
    "source": {
      "source_type": "JUDGE_LLM",
      "source_id": null
    },
    "rationale": "The agent correctly identified both the telegraph and steam as the two methods. The response is accurate and directly answers the question, with only minor formatting differences from the reference.",
    "fragments": null
  },
  {
    "name": "refusal",
    "value": 0.0,
    "error": null,
    "ineligible": null,
    "source": {
      "source_type": "JUDGE_LLM",
      "source_id": null
    },
    "rationale": "The agent provided a substantive answer without refusing.",
    "fragments": null
  }
]
```

Notice that every score may come with an `rationale` telling you *why* it was assigned. This is where you go to understand individual successes and failures, not just the averages. If `rationale` is `null`, no explanation was recorded for that score.

## Conclusion

You have evaluated an agent end to end from the command line interface (CLI). Starting from a file of agent answers, you logged in, chose your metrics, submitted the file for scoring, read the summary scores, and downloaded a detailed `results.json` with a score and explanation for every case — all without leaving your terminal.

This same sequence — `mb eval create → mb eval get → mb eval download` — is exactly what you would drop into a CI pipeline to score your agent automatically on every change.

## Next steps

- Score your own agent's answers by pointing `--file` at your own executed benchmark. To produce one, see [Evaluate your agent via the web UI](mb-eval-ui.md#step-2-run-your-agent-on-the-benchmark), which walks through running an agent and collecting its responses.
- Learn what each metric measures and how to read confidence intervals in [Metrics](../reference/metrics.md).
- Automate the whole flow — corpus, benchmark, and evaluation — with the [CI pipeline example](../cli-guide/index.md#ci-pipeline-scripted).
- Explore every `mb eval` flag in the [CLI Guide: Evaluation](../cli-guide/evaluation.md).