microsoft/agentic-optimization
Analyze AI agent telemetry from Application Insights, including anomaly detection, trend analysis, and performance statistics. Use this when asked to analyze AI agent performance, detect anomalies in agent telemetry, or review agent trace data.
npx skills add https://github.com/microsoft/code-optimizations-skills --skill agentic-optimization
This skill analyzes AI agent telemetry traces from Application Insights using the aira.exe CLI tool. It performs anomaly detection, trend analysis, and generates performance statistics to help identify issues in AI agent behavior.
az login)Follow the Standard Skill Preamble to check for existing investigation context and gather inputs.
In addition to the standard App ID, this skill requires the following Application Insights identity fields:
These are typically available in investigation-notes.md. If only a Resource ID is available, parse the subscription ID, resource group, and component name from the ARM resource ID format:
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/microsoft.insights/components/{componentName}
If none of the above are available, follow Identify Application Insights Resource to locate the resource.
Optional inputs — ask the user if they want to narrow the analysis:
If investigation-notes.md does not already exist in the working directory, create it now with the resource context gathered in steps 1–2. This ensures downstream skills (especially deep-analysis) can pick up the context without re-asking the user.
Write the following fields to investigation-notes.md using the format defined in investigation-notes.md:
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/microsoft.insights/components/{componentName})If the file already exists, verify the resource context matches and update if needed.
Run the script in run-analyze.md to execute the aira.exe analyze command. The script acquires a fresh access token, invokes the CLI with JSON output, and post-processes the results into a readable summary with operation IDs extracted — all in a single run.
> Access token: This skill uses the Application Insights data-plane token (https://api.applicationinsights.io), which is different from the profiler dataplane token used by other skills. The script handles token acquisition automatically.
> Execution time: The analysis may take a while depending on the volume of telemetry data. Inform the user that this may take some time, especially with large --limit values or wide time ranges.
The script output contains everything needed to present results and offer deep-dive. Present it to the user with the following interpretation:
invoke_agent — overall agent invocation (parent span)chat — LLM model calls (check latency and token counts)execute_tool — tool/API calls (often the bottleneck; check byTool breakdown)deep-analysis skill handoff)> Raw JSON: The script saves the full JSON to aira-output.json in the working directory. Let the user know they can inspect this file for the complete data.
If the anomaly operations table has entries, write the key findings to investigation-notes.md before handing off:
Then ask the user which operation to investigate further:
deep-analysis skill to trace the operation across downstream services (tools, APIs, databases) and see where time was spent. The operation ID and resource context will be available in investigation-notes.md.aira.exe response-context --response-id <responseId> to see the full agent conversation flow for that operation. Important: use the responseId field (not the operationId) as the --response-id argument — these are different identifiers. The anomaly table output includes both.aira.exe compare-versions.If the anomaly operations table is empty (no spikes detected), suggest:
aira-output.json) for lower-severity anomalies that didn't meet the thresholdBeyond the deep-dive, offer these follow-up options based on findings:
--agent-name and/or --agent-version filters to focus on a specific agentperf-optimization skill to correlate with profiler traces-o json) with post-processing that extracts a readable summary and operation IDs in one pass. The raw JSON is saved to aira-output.json for user inspection.--limit parameter caps the number of telemetry records analyzed. The CLI defaults to 1000. For thorough analysis, increase up to 50,000.For the investigation notes format and read/write protocol, see:
For finding the Application Insights resource, see:
For the full CLI specification (all available commands), see:
Take microsoft/agentic-optimization from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.