microsoft / microsoft/GitHub-Copilot-for-Azure
Replace microsoft-foundry skill Tracing Insights API fetch with a script
@tmeschter is already working on this.
Since Jul 6, 2026.
- Dominant language
- Python
- Stars
- 250
- Forks
- 204
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 67
Description
## Summary
Copilot has identified a portion of a skill that is a good candidate for replacement with a script.
The candidate is the **Tracing Insights API fetch** in the `microsoft-foundry` skill (`foundry-agent/trace/references/tracing-insights-api.md`) — a token → URL-encode → POST → parse → relatedSpans-loop REST flow with no agent branching.
## Candidate description
To fetch tracing insights and the traces they flag, the skill runs a deterministic REST sequence:
1. `az account get-access-token --resource https://ai.azure.com` to acquire a token.
2. URL-encode `agent` and `projectId` (the latter contains slashes) and assemble the `:insights` URI with required query params.
3. `POST` with the mandatory empty `{}` body (omitting it returns 400) and parse the JSON.
4. For each `operationId` in `relatedSpans[]`, run the fixed KQL to pull input/output/tokens for that trace.
This is a strong script candidate because it is:
- **Fully deterministic with no branching** — the pitfalls it documents (empty body required, projectId must be URL-encoded, region-agnostic `eastus2` default) are exactly the mechanical detail a script encodes once.
- **A fixed loop** over a known `relatedSpans` list.
- **Sharing a recurring token idiom** — `az account get-access-token --resource https://ai.azure.com --query accessToken -o tsv` also appears in `troubleshoot.md` (L63) and `direct-code-deployment.md` (L253), suggesting a shared auth helper.
**Sketch — `fetch-tracing-insights.{sh,ps1}`:**
- **Input:** `--agent`, `--project-id`, optional `--region` (default `eastus2`), optional `--analysis-window`.
- **Output:** the parsed insights plus, for each related span, the user query / agent response / token usage.
> Choosing the analysis window and interpreting/triaging the returned insights (severity, evaluator, shift magnitude) and deciding which traces to drill into stay in prose. The fetch + relatedSpans expansion is mechanical.
## Affected file and lines
- [`foundry-agent/trace/references/tracing-insights-api.md` — token + encode + POST insights (L30–L47)](https://github.com/microsoft/GitHub-Copilot-for-Azure/blob/3890cbfb65c548ce8daa96cabd1d8de63f7bbcca/plugin/skills/microsoft-foundry/foundry-agent/trace/references/tracing-insights-api.md#L30-L47)
- [`foundry-agent/trace/references/tracing-insights-api.md` — relatedSpans trace pull (L77–L90)](https://github.com/microsoft/GitHub-Copilot-for-Azure/blob/3890cbfb65c548ce8daa96cabd1d8de63f7bbcca/plugin/skills/microsoft-foundry/foundry-agent/trace/references/tracing-insights-api.md#L77-L90)
## Next steps
1. **Evaluate the candidate** — confirm the steps are stable and parameterizable, and that the script captures everything the skill needs.
2. **Create both a bash _and_ a PowerShell version** of the script so the skill works across platforms.
3. **Run integration tests** to verify the scripts behave correctly and the skill still completes end-to-end.
## Background Information
### Why replace regular steps with scripts
Replacing a regular, well-defined series of steps with a script can:
- **Reduce token usage** — the skill no longer needs to spell out each command and parse large command output inline; the agent invokes one script and reads a compact result.
- **Improve reliability** — the logic is written and tested once, instead of being re-derived by the agent on every run.
- **Improve determinism** — the same inputs always produce the same steps and output, removing run-to-run variation.
- **Improve speed of execution** — a single script call replaces multiple round-trips of command generation, execution, and large-output parsing.
### Authoring notes for the scripts
- **Reference scripts with markdown links**, not just a bare path to the script file.
- **Include examples** in the skill showing how to run each script (sample invocation with arguments).
- **Briefly explain what each script does** where it is referenced.
- **The script output should explain what it did**, so the agent and user can understand the result without re-inspecting raw command output.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.