---
name: improve-select
description: "Choose the deployed agent (runtime) and the one version of it to improve, showing how many conversations each version had in the last 14 days. Use first when asked to fix or improve a deployed agent, but not its memory."
metadata:
  min-cli-version: "0.93.0"
  next: "improve-classify"
---

# Improve: select

Find which agent and which version of it to improve. Improve works on one version at a time, because each version's conversations are evidence about its own commit only.

Nothing in this step writes outside the build folder's `runs/improve/`, which is outside the repository. Each improve run starts it empty, in step 2, so nothing from an earlier run is read or mentioned.

## 1. Check the login

```sh
introspection whoami
```

Not logged in: ask the owner to run `introspection login` and say when they're done, then stop.

## 2. Choose the runtime

```sh
rm -rf runs/improve && mkdir -p runs/improve
introspection runtimes list -o json > runs/improve/runtimes.json
jq -r '[.[].slug] | unique[]' runs/improve/runtimes.json
```

- **No runtime:** there is nothing deployed to improve from. Say so and offer to deploy the agent first (`deploy-create`).
- **The request names one of the listed slugs:** use it. Only the slug itself names a runtime: "this agent" or an earlier session's files never do.
- **The build folder holds exactly one Recipe repository, and its name is exactly one of the slugs:** use that runtime, and say in one line which agent you're improving and why, so the owner can name another.
- **Otherwise:** ask the owner which one with `ask_user_question`, one option per slug. When the build folder holds a Recipe's repository whose name contains a slug, put that runtime first.

## 3. Choose the version

List the runtime's versions that had a conversation in the last 14 days, with their counts, in the order to offer them:

```sh
R=runs/improve; S=<slug>
introspection runtimes versions $S --conversations --lookback 14d -o json > $R/versions.json
jq -r '.[] | [.id, .recipe_ref, (.environments | join(",")), .git_commit_sha[0:7], .created_at, .conversations] | @tsv' $R/versions.json
```

Each row is a version with at least one conversation: its id, ref, lanes, short commit, when it was created, and its conversations over the 14 days, production first, then staging, then the rest newest first. Name each for the owner by what serves it:

- **Production:** `production`.
- **A branch:** its `recipe_ref`, such as `pr/24`, with ` (staging)` after it when its `environments` include `staging`.
- **Staging on `main`:** `staging`.
- **A version no lane serves any more:** its `recipe_ref`, such as `main`.

Name its conversations by the version, such as "2 conversations on staging", never by a purpose you guess, such as test chats.

- **The request names the version** (a branch, `staging` or `production`): use the row it names.
- **Otherwise:** ask the owner to pick exactly one with `ask_user_question`, asking exactly "Which version's conversations should the improvement be based on?", with no other sentence, and the first four rows as options, in the rows' order. Each option's label is the version's name, an em dash, then its short commit, its age from `created_at` and its conversations, with no description: `production — 5c85d7b · 1d ago · 15 conversations` (`1 conversation` for one).
- **No version has a conversation in 14 days:** there is no evidence to improve from. Say so and offer to test the agent (`deploy-test`).

## 4. Keep the chosen version

```sh
jq '.[] | select(.id == "<version-id>")' runs/improve/versions.json > runs/improve/version.json
```

It holds what the next steps need: the version's `id`, the commit it was built from (`git_commit_sha`), its `recipe_id` and `recipe_ref`, and the runtime's `slug`.

## Done when

- The owner has a runtime and exactly one version of it, shown with its conversation count.
- `runs/improve/` holds `versions.json` and `version.json`.

Then go straight on with `improve-classify`.
