Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/troubleshoot/troubleshoot.md
1# Foundry Agent Troubleshoot23Troubleshoot and debug Foundry agents by collecting hosted-agent session logs, discovering observability connections, and querying Application Insights telemetry.45## Quick Reference67| Property | Value |8|----------|-------|9| Agent types | Prompt (LLM-based), Hosted |10| MCP servers | `azure` |11| Key Foundry MCP tools | `agent_get` |12| Related skills | `trace` (telemetry analysis) |13| Preferred query tool | `monitor_resource_log_query` (Azure MCP) — preferred over `azure-kusto` for App Insights |14| CLI references | `az cognitiveservices account connection`, `az rest`, `curl` |1516## When to Use This Skill1718- Agent is not responding or returning errors19- Hosted agent version is not becoming active20- Need to view hosted-agent session logs21- Diagnose latency or timeout issues22- Query Application Insights for agent traces and exceptions23- Investigate agent runtime failures2425## MCP Tools2627| Tool | Description | Parameters |28|------|-------------|------------|29| `agent_get` | Get agent details to determine type and inspect agent/version status | `projectEndpoint` (required), `agentName` (optional) |3031## Workflow3233### Step 1: Collect Agent Information3435Use the project endpoint and agent name from the project context (see Common: Project Context Resolution). Ask the user only for values not already resolved:36- **Project endpoint** — AI Foundry project endpoint URL37- **Agent name** — Name of the agent to troubleshoot3839### Step 2: Determine Agent Type4041Use `agent_get` with `projectEndpoint` and `agentName` to retrieve the agent definition. Check the `kind` field:42- `"hosted"` → Proceed to Step 343- `"prompt"` → Skip to Step 4 (Discover Observability Connections)4445### Step 3: Retrieve Logs (Hosted Agents Only)4647Hosted-agent logs are scoped to individual **sessions** (sandbox instances).48491. **Check agent version status** — Use `agent_get` to verify the agent version status is `active`. If it is not active, the agent may still be provisioning or may have failed to become active.50512. **List sessions** — Hosted-agent logs require a `sessionId`. If the user does not have one, list available sessions:52```bash53az rest --method GET \54--url "<projectEndpoint>/agents/<agentName>/sessions?api-version=2025-11-15-preview" \55--headers "Foundry-Features=HostedAgents=V1Preview" \56--resource "https://ai.azure.com"57```58593. **Retrieve session logs** — The log stream endpoint uses Server-Sent Events (SSE). Use `curl` with a timeout:60```bash61TOKEN=$(az account get-access-token --resource "https://ai.azure.com" --query accessToken -o tsv)62curl -s --max-time 15 \63-H "Authorization: Bearer $TOKEN" \64-H "Accept: text/event-stream" \65-H "Foundry-Features: HostedAgents=V1Preview" \66"<projectEndpoint>/agents/<agentName>/sessions/<sessionId>:logstream?api-version=2025-11-15-preview"67```6869> ⚠️ **404 is expected** if the session sandbox has not been created yet. Advise the user to send a message to the agent first to trigger sandbox creation, then retry.70714. **Interpret the logs** — Each SSE frame is `event: log\ndata: {...}\n\n`:72- **Preamble** (first event): JSON with `session_state`, `session_id`, `agent`, `version`, `last_accessed`73- **Log lines** (subsequent events): JSON with `stream` (`stdout`/`stderr`/`status`), `message`, and `timestamp`74- **Error events**: `event: error` frames indicate server-side errors within the session sandbox7576Present the logs to the user and highlight any errors or warnings found.7778### Step 4: Discover Observability Connections7980List the project connections to find Application Insights or Azure Monitor resources using the Azure CLI command documented at:81[az cognitiveservices account connection](https://learn.microsoft.com/en-us/cli/azure/cognitiveservices/account/connection?view=azure-cli-latest)8283Refer to the documentation above for the exact command syntax and parameters. Look for connections of type `ApplicationInsights` or `AzureMonitor` in the output.8485If no observability connection is found, inform the user and suggest setting up Application Insights for the project. Ask if they want to proceed without telemetry data.8687### Step 5: Query Application Insights Telemetry8889Use **`monitor_resource_log_query`** (Azure MCP tool) to run KQL queries against the Application Insights resource discovered in Step 4. This is preferred over delegating to the `azure-kusto` skill. Pass the App Insights resource ID and the KQL query directly.9091> ⚠️ **Always pass `subscription` explicitly** to Azure MCP tools like `monitor_resource_log_query` — they don't extract it from resource IDs.9293Use `* contains "<response_id>"` or `* contains "<agent_name>"` filters to narrow down results to the specific agent instance.9495### Step 6: Summarize Findings9697Present a summary to the user including:98- **Agent type and status** — hosted or prompt; hosted agent version status when relevant99- **Log errors** — key errors from hosted-agent session logs100- **Telemetry insights** — exceptions, failed requests, latency trends101- **Recommended actions** — specific steps to resolve identified issues102103## Error Handling104105| Error | Cause | Resolution |106|-------|-------|------------|107| Agent not found | Invalid agent name or project endpoint | Use `agent_get` to list available agents and verify name |108| Hosted agent not active | Hosted agent is still provisioning or failed | Check that the ACR image was pushed correctly and agent identity permissions are assigned; wait and re-check status |109| Session logs 404 | Session sandbox has not been created yet | The sandbox is created on first invocation — send a message to the agent to trigger sandbox creation, then retry |110| SSE error event | Server-side error within the session sandbox | Check the error event `data` field for details |111| No session ID | User does not know which session to troubleshoot | List sessions via REST API (see Step 3) |112| No observability connection | Application Insights not configured for the project | Suggest configuring Application Insights for the Foundry project |113| Kusto query failed | Invalid cluster/database or insufficient permissions | Verify Application Insights resource details and reader permissions |114| No telemetry data | Agent not instrumented or too recent | Check if Application Insights SDK is configured; data may take a few minutes to appear |115116## Additional Resources117118- [Foundry Hosted Agents](https://learn.microsoft.com/azure/ai-foundry/agents/concepts/hosted-agents?view=foundry)119- [Account Connection CLI Reference](https://learn.microsoft.com/en-us/cli/azure/cognitiveservices/account/connection?view=azure-cli-latest)120- [KQL Quick Reference](https://learn.microsoft.com/azure/data-explorer/kusto/query/kql-quick-reference)121- [Foundry Samples](https://github.com/microsoft-foundry/foundry-samples)122