# Pendo: Fix an AI Agent Issue

Requires the Pendo MCP server connected (tools like `listAiAgents`, `listTrackedIssues`, a tracked-issue deep-dive tool, `getAgentConfig`). Tool names have changed before (`ai_agent_*` → `agent_analytics_*`) — **before assuming a name, check what's actually available** via the client's tool list rather than hardcoding one. If a call fails with "tool not found", look for a renamed sibling before giving up.

---

## Step 1 — Resolve inputs

- Get `agentId`/`appId` via `listAiAgents` if not already known (match by name).
- Determine mode:
  - **Exploration** — user gave only an agent (± date range): find the highest-impact issue yourself.
  - **Targeted** — user named a specific tracked issue: resolve it by name.

---

## Step 2 — List tracked issues (defensively)

Tracked-issue listing embeds full conversationId/eventId arrays with no output cap. On a busy agent, a 30-day (or even 14–15 day) window can fail outright ("too much data") or time out.

- Start with the requested range. If it fails:
  1. Split into ~10-day absolute sub-windows and call each **sequentially** (not in parallel — concurrent heavy queries appear to contend and time out together).
  2. Merge results by tracked-issue id: sum `numConversations`, union `conversationIds`/`eventIds` (dedup — sub-windows are non-overlapping so no double-counting, but don't assume that if you change the split).
- In exploration mode, rank merged results by `numConversations` and pick the top one.

---

## Step 3 — Check size before the deep-dive

The deep-dive tool builds a filter with one clause per conversationId/eventId server-side — no input cap (tracked as a known bug). If the merged `conversationIds` count is large (four figures+), expect it to be slow; say so up front rather than letting the user think it's hung. Don't try to manually truncate the IDs — a partial/arbitrary sample changes what's being analyzed. If it doesn't return in a couple minutes, tell the user the issue's real size and ask whether to keep waiting, narrow the date range, or proceed with the summary-only fields from step 2.

---

## Step 4 — Deep-dive

Call the tracked/detected-issue deep-dive tool with the resolved `agentId`/`appId`/`trackedIssueId`/`name`/`conversationIds`/`eventIds`/`dateRange`. This returns: visitor/account lists, sampled issue explanations, tools/models used, and sample prompt text.

---

## Step 5 — Agent config

Call `getAgentConfig` for the same agent/date range to get its system prompt and runtime tool inventory. If the tools section comes back empty, note that explicitly rather than silently omitting it — it's a real finding (config drift or an instrumentation gap), not nothing to report.

---

## Step 6 — Write the fix brief

Produce exactly this structure, using only what steps 2–5 actually returned (if step 3/4 was skipped or partial, say so instead of inventing content):

```
## Fix Brief: [Issue Name]

### Issue Summary
- Issue type, affected conversations, affected visitors/accounts
- Representative explanations

### Root Cause Analysis
[Grounded in the agent's system prompt + sampled prompts/explanations —
 mark as a hypothesis if the deep-dive step didn't complete]

### Recommended Fix
[Specific, targeted delta — e.g. system prompt addition, tool description
 update, KB content fix — not a generic suggestion]

### Supporting Evidence
- Prompt samples, tools involved, agent config context
- Note any steps that failed or were skipped, and why

### Implementation
[Concrete next step for a coding agent or engineer]
```
