# Test an AI Agent

> Test an AI Agent with representative input, choose which runs share memory, and check tool results before retrying.

Run an isolated test in **Preview** to verify reasoning and tool calls before sending live writes. Both **Preview** and **Live test** use the real model and bill Glow AI tokens.

 }}) and {{ N.estimatedCreditsUsed }}"
  verifiedAt="Oct 30, 2026"
/>

## [Preview or Live test](https://docs.getglow.ai/build/ai-features/ai-agent-testing#run-an-isolated-test)

Open AI Agent → Test & Debug → Preview or Live test → Run Test

**Preview** (Default safe mode)

- Runs the real model and read-only actions (find email, list users).
- Marks write actions and external MCP tools as Proposed · not sent.
- Starts fresh without reading or saving Conversational Memory.
- Uses model credits with no confirmation dialog.

**Live test** (Real external effects)

- Dispatches real app actions and external MCP tools.
- Pauses on approval-gated actions until you Approve or Reject.
- Reads and saves Conversational Memory for the active key.
- Prompts once (Switch to Live test?) and uses model and Step credits.

> **Switch back to Preview.** The toggle stays on **Live test** in your open tab
> until you switch it back.

## What the agent works on

Tests resolve **Instructions** using the latest output or **Testing data** of earlier Steps. Edit an upstream Step's **Testing data** (**Test & Debug** → **Testing data**) or paste sample text in the prompt.

## Approve or reject an action

When a **Live test** or run hits an approval-gated tool:

### Open the pending decision

Open **Executions** on the agent to see `1 action needs a decision before the agent can continue.`

### Inspect prepared inputs

Expand **Prepared inputs** to check recipients and fields. Secret values are hidden.

### Approve or reject

Click **Approve**, **Reject**, or **Open in Approvals** to continue.

## Read the result

**Inspect the Trace**

Each test logs three sections in **Test & Debug**:

- **Output:** Final answer as **Formatted** or **Raw JSON** (`{{ N.result }}` or `{{ N.result.field }}`).
- **Agent activity:** Model and tool calls with status (`Succeeded`, `Proposed`, `Awaiting approval`, `Failed`) and timing.
- **Detailed usage & metrics:** Tokens and `{{ N.estimatedCreditsUsed }}`.

| Activity label                                            | Meaning                                                                                              |
| :-------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- |
| **Search the web** / **Read a web page** / **Run code**   | Built-in helper call.                                                                                |
| **Recall this conversation** / **Search reference files** | Context lookup in memory or attached files.                                                          |
| `Run workflow: {name}` / `{MCP connection} · {tool}`      | Subflow call or external MCP tool call.                                                              |
| **Look up values: …**                                     | Option lookup, not a write ([details](https://docs.getglow.ai/build/ai-features/ai-agent#looking-up-values-for-an-action)). |

**When a Test Fails**

### When a test fails

| You see                                         | Cause                        | Fix                                                                 |
| :---------------------------------------------- | :--------------------------- | :------------------------------------------------------------------ |
| `The AI agent reached its iterations limit (1)` | Runtime cap reached          | Raise the cap under **Advanced runtime limits** or simplify task.   |
| `(No final response)`                           | Stopped before answering     | Check the last tool call in **Agent activity**.                     |
| Unexpected proposed action                      | Prompt or input asked for it | Remove the action from **Tools** or require approval.               |
| **Separate fields** check failed                | Answer missed schema shape   | Enable **Ask the AI to fix a wrong shape** or tighten instructions. |

## Choose which runs share memory

**Conversational Memory** is off by default. Enable it in **Context** or on the **Memory** tile (Glow-managed Gemini models) and set **Memory Instructions**.

Memory is scoped to the workspace, automation, and Agent Step:

```mermaid
flowchart LR
    subgraph Scoped["Per-Thread Key: {{ 1.threadId }}"]
      R1[Run: thread_101] --> M1[(Memory: thread_101)]
      R2[Run: thread_202] --> M2[(Memory: thread_202)]
    end
    subgraph Shared["Shared Key: default"]
      R3[All runs of this Step] --> M3[(Shared default memory)]
    end
```

| Memory key option                           | Best for                                    | Who shares context                                |
| :------------------------------------------ | :------------------------------------------ | :------------------------------------------------ |
| **Earlier-Step field** (`{{ 1.threadId }}`) | Support tickets, chat threads, per-customer | Runs with the same thread, ticket, or customer ID |
| **Share one conversation across all runs**  | Personal assistants or team digests         | Every run of this Agent Step (`default` key)      |
| **Custom memory key**                       | Composite keys (`{{ 1.org }}-qa`)           | Runs whose resolved custom key matches            |

Missing required memory IDs stop the Step before calling AI.

> **Isolate customer context.** Never share one static Conversation ID across
> customers. Leave **Conversational Memory** off when unused.

### Upgrade earlier shared memory

Older Agent Steps show **Upgrade Memory**, which starts clean memory without importing prior history.

### Credentials and conversation memory

Glow blocks workspace Secrets and API keys (`{{ $secret.* }}`, `{{ $key.* }}`) from AI prompts and strips known secrets from memory. Authenticate via connected accounts or [HTTP Request](https://docs.getglow.ai/build/action-steps/http-request) auth fields ([variable safety](https://docs.getglow.ai/reference/variable-syntax#team-variables-and-secrets)).

## Check the answer shape

In **Output**, **Separate fields** validates the reply against your schema ([What it passes on](https://docs.getglow.ai/build/ai-features/ai-agent#what-it-passes-on)). **Ask the AI to fix a wrong shape** allows one extra model call to repair invalid JSON without re-running tools (`{{ N.result.field }}`).

## Recover from a failed run

Check **Executions** to see which tool calls finished, and wire an **Error Path** to a fallback ([Error Handling](https://docs.getglow.ai/build/core-concepts/error-handling)).

### Check external writes before retrying

Resuming an approved call verifies dispatch state and ownership so that action never runs twice. A new run does not undo writes and can duplicate external actions, so check the external app first.

> **Error branches do not check reasoning.** Require approval in **Tools** for
> agent writes, or add a [Human Review](https://docs.getglow.ai/build/action-steps/user-approval) Step
> before downstream writes.

## Example configurations

Adapt these prompts and **Output → Separate fields** (`Advanced (JSON Schema)`) schemas. Boolean fields like `requires_human_review` are plain data and do not pause a run by itself.

**B2B Prospect Research**

### [B2B Company & Prospect Research](https://docs.getglow.ai/build/ai-features/ai-agent-testing#b2b-company--prospect-research)

Uses **Search the web** and **Read a URL you give it** on public URLs (`Identity`: B2B researcher; `Dos/Don'ts`: check company site first, return `null` when unknown).

```
Research "{{ 1.email | extract_domain }}" with web search.
Find value proposition, target customer, headcount, and 90-day news.
Email: {{ 1.email }} · Lead: {{ 1.name | capitalize }}
```

```json
{
  "type": "object",
  "properties": {
    "company_name": { "type": "string" },
    "industry": { "type": "string" },
    "value_proposition": { "type": "string" },
    "target_market": {
      "type": "string",
      "enum": ["SMB", "Mid-Market", "Enterprise"]
    },
    "recent_news": { "type": ["string", "null"] },
    "recommended_outreach_angle": { "type": "string" }
  },
  "required": [
    "company_name",
    "industry",
    "value_proposition",
    "target_market",
    "recommended_outreach_angle"
  ]
}
```

**Support Triage Router**

### [Customer Support Triage & Sentiment Router](https://docs.getglow.ai/build/ai-features/ai-agent-testing#customer-support-triage--sentiment-router)

Uses CRM lookup actions for a [Switch](https://docs.getglow.ai/build/action-steps/switch) Step (`Identity`: SaaS support triage; `Safety`: never promise timelines or SLA credits; escalate legal or churn threats).

```
Customer: {{ 1.name }} ({{ 1.email | lower }})
Message: {{ 1.message | strip_html | trim }}
1. Look up ({{ 1.email | extract_domain }}) in HubSpot for tier.
2. Classify urgency, category, and draft a reply.
```

```json
{
  "type": "object",
  "properties": {
    "urgency": { "type": "string", "enum": ["Critical", "Normal", "Low"] },
    "category": {
      "type": "string",
      "enum": ["Billing", "Authentication", "Bug", "Feature Request", "How-To"]
    },
    "tier": { "type": "string", "enum": ["Enterprise", "Standard", "Free"] },
    "sentiment": {
      "type": "string",
      "enum": ["Frustrated", "Neutral", "Delighted"]
    },
    "draft_reply": { "type": "string" },
    "requires_human_review": { "type": "boolean" }
  },
  "required": [
    "urgency",
    "category",
    "tier",
    "sentiment",
    "draft_reply",
    "requires_human_review"
  ]
}
```

**DevOps Incident Analyzer**

### [DevOps Incident & Log Analyzer](https://docs.getglow.ai/build/ai-features/ai-agent-testing#devops-incident--log-analyzer)

Uses **GitHub** and **Jira** actions on webhook error logs (**Body only** on Step 1, or `1.body` paths; `Identity`: SRE log triage assistant).

```
Service: {{ 1.service_name }} · Error: {{ 1.error_message }}
Stack Trace: {{ 1.stack_trace | limit:2000 }}
1. Identify root cause module and search GitHub for open issues.
2. Return issue number or draft a Jira summary.
```

```json
{
  "type": "object",
  "properties": {
    "severity": { "type": "string", "enum": ["P1", "P2", "P3"] },
    "root_cause_module": { "type": "string" },
    "is_known_bug": { "type": "boolean" },
    "jira_summary": { "type": "string" },
    "jira_description": { "type": "string" },
    "recommended_fix": { "type": "string" }
  },
  "required": [
    "severity",
    "root_cause_module",
    "is_known_bug",
    "jira_summary",
    "jira_description"
  ]
}
```

**Verify it works**

- **Run:** Open AI Agent → Tests tab, keep Preview selected, and click Run test
- **You should see:** Read-only tools run live, writes stay Proposed, and the trace logs tool calls and tokens.

## What's Next?

- [Debug a Run](https://docs.getglow.ai/reference/debug-a-run): trace a failed Step and inspect its results.
- [Human Review](https://docs.getglow.ai/build/action-steps/user-approval): require approval before a downstream action.
- [AI Agent](https://docs.getglow.ai/build/ai-features/ai-agent): change the agent's tools, instructions, or Answer format.
