---
name: cortex-test
description: Run a Ninjo agent through fixed, scripted conversations (deterministic lead messages, no user-side LLM inference) via the cortex-gateway generate_synthetic_conversations tool, then review the transcripts. Fast, reproducible flow checks against the live config. Use when the user wants to test, smoke-test, or sanity-check an agent's behavior on specific inputs. Does NOT deploy.
---

# cortex-test — scripted scenario testing (MCP-first)

Play an agent through a handful of **scripted** conversations: you write the exact lead
messages, the gateway replays them against the deployed agent, and only the agent side is
generated. Deterministic and reproducible — the opposite of persona-driven synthetic runs.
**This skill never deploys** — hand fixes to `/cortex-iterate`.

## 1. Load context
- `agents/<name>/meta.md` → **Agent ID** and **Influencer ID**. If Agent ID is `PENDING`, stop:
  the agent must be deployed first (`/cortex-create`).
- `get_agent_config(agent_id)` — read the live flow, keyword triggers, and happy path so the
  scenarios exercise the agent's **real** entry points and steps (this is how the local runner
  grounds scenarios in the SDK).

## 2. Design scenarios
Write **4–6** scripted scenarios as fixed lead-message sequences covering the paths that matter:
- keyword/first-message entry → discovery → CTA/booking (the happy path)
- price or objection first
- minimal/cold lead (one-word replies)
- any agent-specific critical flow surfaced in the config

Each scenario:
```json
{ "name": "keyword-hashimoto", "stage": "keyword → booking",
  "messages": ["hashimoto", "si hace 3 años", "dale, cuanto sale?", "listo, ya agendé"] }
```
`messages` are the exact lead turns, in order (strings, or `{ "text": "..." }`). Optional
`history` seeds prior turns (`[role, content]` pairs). Keep it minimal — a few high-signal
scripts beat many. Save them to `agents/<name>/synthetic/scenarios-<YYYY-MM-DD>.json` for reuse
and show them to the user before running.

## 3. Run via MCP
Call `generate_synthetic_conversations`:
- `agent_id`, `agent_name` = `<name>`, `influencer_id` (from meta)
- `scripted_scenarios`: the array from step 2
- `max_turns`: ≥ the longest scenario's message count
- `min_turns`: **1** — scripted scenarios are short; the default (3) would silently drop them
- `env`: **`prod`** — this workspace's gateway/JWT are prod-only. The prod gateway role is **not**
  authorized to invoke the `stag` replicant Lambda, so a `stag` run fails with an IAM error. Only use
  `stag` if the user explicitly has a stag-authorized connection.

Returns `{ conversations: [{ turns, markdown, ... }], test_run_ids, ... }`. Each conversation
replays your exact lead turns; only the agent responses are generated.

## 4. Review
Read each transcript and flag **concrete** issues with quotes: ignored keyword / first message,
link-before-text or unsolicited link, premature pitch, skipped discovery step, `NO_RESPONSE`
misuse, tone or persona drift, or a reasoning leak (the agent narrating its internal logic). Give a one-line pass/concern verdict per scenario, then a short
summary. No deploys — route fixes to `/cortex-iterate`.

## When a tool fails or a capability is missing
Follow `knowledge/self-sufficiency.md`. Skill-specific: `generate_synthetic_conversations` runs on **prod** only —
a `stag` env returns an IAM error (don't retry on stag; switch to prod). If a run times out, retry with fewer/shorter
scenarios rather than abandoning the check.
