AGENT SKILL

模型时延与成本分析

cost-latency-analysis

如何根据 PilotSwarm 数据计算模型时延和预估美元($)成本。在判定某个模型“慢”或“贵”之前请先阅读本文:大多数延迟源于编排开销,而除非引用公开的价格表(price card),否则成本只是猜测。

License 许可
MIT
最近更新
2026-11-15
Stars
★ 16
Forks
10

01 前言 Front Matter

name
cost-latency-analysis
description
How to compute model latency and estimated $ cost from PilotSwarm data. Read this before calling a model "slow" or "expensive": most slowness is orchestration overhead, and a cost is a guess unless it cites a published price card.

02 资源文件 1

03 SKILL.md 正文

Cost & Latency Analysis

You are the agent-manager. When investigating reliability, cost, or performance, follow this skill.

Latency: prefer assistant.usage.duration

PilotSwarm records two different "durations" per turn. Do not confuse them:

Source What it measures When to use
runTurn activity span (execution history) Total wall-clock time the activity ran, including dehydrate, hydrate, snapshot, blob I/O, scheduling. Operator-facing "how long did this turn take end-to-end". Useful for orchestration-overhead investigations.
assistant.usage.duration (assistant event) Time spent inside the model call itself as reported by the LLM provider. Model-latency comparisons. The only fair number to use when comparing models, providers, or context sizes.

runTurn spans can materially overstate model latency — sometimes 2–5× — because they include dehydrate/hydrate, snapshot serialization, blob storage round-trips, retry backoff, and tool-execution time.

Rule of thumb:

  • Comparing "is gpt-5.4 slower than gpt-5.4-mini?" → use assistant.usage.duration.
  • Investigating "why does this turn take 30 seconds?" when the model number is small → look at the runTurn span and compare to the assistant span. The delta is the orchestration overhead.

Where to read it from

  • Per-turn: read_agent_events filtered to event_types: ["assistant"], then read usage.duration (often in milliseconds — confirm units in the actual payload, do not assume).
  • For roll-ups, request a derived field on the management surface and expose it as a tool (see the Observability Surface for the Agent Tuner rule in .github/copilot-instructions.md). Do not summarize latency by averaging runTurn spans — it will mislead.

Cost: estimate, do not guess

Token counts come from read_session_metric_summary / read_fleet_stats and are reliable. Per-token prices change constantly and do not live in PilotSwarm. Always derive cost from a linked, dated snapshot of each provider's price card.

Default approach:

  1. Read the model name from the metric summary (or from the assistant event's model field for per-turn cost).
  2. Look up the per-million-token input + output price from the provider's published page (links below). Note the date you looked it up.
  3. Cost = (tokens_input × $/M-input + tokens_output × $/M-output) ÷ 1,000,000.
  4. If the model offers prompt caching (Claude, GPT-5.4 family), apply the discounted cache-read rate to tokens_cache_read. Cache writes are often billed at standard input rate.
  5. Report the price source and date alongside the dollar figure.

Stable price-card sources

These are the canonical pages to consult. Do not invent or memoize numbers — re-fetch on each report.

Example

session: 22013ffb
model:   azure-openai:gpt-5.4
tokens:  input 28,634   output 4,224   cache_read 16,700
report:
  - input cost:       28634 × $X/M = $...
  - output cost:      4224  × $Y/M = $...
  - cache-read cost:  16700 × $Z/M = $...
  total ≈ $0.0XX  (price source: openai.com/api/pricing, fetched <date>)

What to never do

  • Never quote a per-token dollar cost without naming the price source and the date you fetched it.
  • Never compare model latency using runTurn spans alone.
  • Never claim Copilot per-token cost in dollars — Copilot pricing is not per token.
  • Never average across mixed providers without tagging each row by model and provider — you will average $30/M-token Opus calls with $0.10/M-token nano calls and report a number that is meaningless.

04 同仓库更多 Skills

microsoft
microsoft/PilotSwarm

workflow-testing

Load before you test a Workflow with mocked effects — the test, test_respond and test_advance operations, fixtures, interception ids, valid answers, the virtual clock, test evidence and what a test run does not prove.

★ 16
microsoft
microsoft/PilotSwarm

workflow-tools

Every argument of the Workflow tools, testing a revision, package definitions and the refusals you can fix. Load when a Workflow tool's short description is not enough.

★ 16
microsoft
microsoft/PilotSwarm

workflow-reference

Field reference for Workflow YAML (root keys, every state type, bindings, outputs, runtime error codes), what the engine guarantees, and a review fan-out example. For design, call load_skill with name workflow-authoring.

★ 16
microsoft
microsoft/PilotSwarm

workflow-patterns

Load when one Workflow must run different nodes in its branches at the same time (a different prompt or model for each branch), or loops back to a state (a polling loop). Named branches, the router pattern, examples that compile.

★ 16
microsoft
microsoft/PilotSwarm

workflow-authoring

Load before you create, edit, publish or run a Workflow (pilotswarm.dev/v1) — choosing states, bounded graphs, bindings, typed contracts, agent and parallel states, the lifecycle and failure diagnosis.

★ 16
microsoft
microsoft/PilotSwarm

tla-formal-validation

Required for any change to the core orchestrations (the durable session orchestration, session hydration and dehydration, and the Workflow controller and store). Teaches how to model the change in TLA+, update the existing models, run TLC with the repo runner, read the results, turn a counterexample into a fix and a regression test, and record the binding to the code.

★ 16