Leia em português: Microsoft Foundry Agent Service: como medir o custo por tarefa concluída
Picture a support agent that handles refund requests and account-detail changes, and a finance team asking how much each resolved request costs. The dashboard answers something else: an estimated cost per agent, a run count and a success rate. The scenario is illustrative, but the pattern is in the documentation: on the pages I read on November 6, 2026, the Foundry Agent Service bills per token, per session, per transaction, per GB per day and per vCPU-hour and GiB-hour, and I did not find a cost-per-completed-task metric. Working that out is left to whoever operates the agent.
The missing unit
What is the cost per completed task in the Foundry Agent Service?
The cost per completed task is what the agent spent on every attempt, plus the cost of measuring, divided by the number of tasks with a completed verdict. The numerator includes the attempts that failed, the repeated ones and those of tasks that never completed, plus what is not tokens (tools and the hosted agent’s container) and the cost of measuring (judge and telemetry). The denominator counts tasks completed according to a verdict that you define, not calls, runs, turns or conversations. The completion rate goes alongside: a low cost with half of the tasks failing is a different problem.
The platform has no such unit: the runtime components page talks about agents, conversations and responses. A task is a business unit, and you are the one who defines it. The July 21 article covered the cost per call with caching, the August 13 one batch, model router and PTU, and the October 27 one reasoning tokens. The scope here is the cost per completed task of an agent, not the cost per call or the reasoning tokens.
| Meter | What is billed | Where the documentation says it shows up |
|---|---|---|
| Model tokens | The tokens of each call | The agent’s Estimated cost column, based on the number of tokens consumed |
| Tools | File search: GB of vector storage per day, with 1 GB free; Code Interpreter: per session; web search: per 1,000 transactions | The tool pages and the pricing page; they do not say whether the estimate includes them |
| Hosted agent container | vCPU-hour and GiB-hour, on consumption in active sessions | The pricing and hosted agents pages; they do not say whether the estimate includes it |
| Evaluation judge | The tokens of the deployment that gives the verdict (deployment_name) |
The intelligent sampling page mentions the inference cost of the evaluation; I did not see where it shows up |
| Telemetry | Data in Application Insights and Azure Monitor, by volume and retention | In that service and at the subscription level; for Azure Monitor Logs and alerts, it does not show up when scoped to the Foundry resource alone |
Sources checked on November 6, 2026. The table summarizes the documentation read on that date, and what it describes was not executed: nothing here was measured in a real Foundry project, with a real agent or on an invoice.
The problem it solves
The map below avoids three mistakes. The first is dividing by what is easy to count: the dashboard counts runs, and a run without an error is not a task that the user considers resolved. The second is adding up only the tokens: the dashboard estimate is based on tokens, and Code Interpreter sessions, the hosted container, the judge and telemetry are other meters. The third is throwing away what did not complete: the attempt that failed and the abandoned task spent the same, and leaving them out makes the cost look smaller than it is. My reading: it is the mistake that misleads the most, because the number left looks clean; in the example, it comes out 60% below the reference.

The measurement architecture
Measuring the cost per completed task means walking through five layers, and each one only exists because the previous one left a usable trail. In execution, the request becomes attempts. In telemetry, each attempt becomes a span. In evaluation, the set of attempts becomes a verdict. In calculation, the verdict becomes a denominator. In reconciling, the number meets the invoice. The drawing below follows that path, layer by layer, with what goes in, what the layer does and what goes out to the next one.

The piece that crosses all five layers is the task ID. Foundry uses OpenTelemetry semantic conventions: the invoke_agent span opens the agent run and execute_tool records a tool execution. Neither of them knows what your task is. The ID is an attribute you add, and the tracing page asks for consistent span attributes across all agents and tools — and forbids storing secrets, credentials or tokens in prompts, tool arguments or span attributes. My reading: the task ID is an identifier you generate, not user data; if it needs masking, it is wrong.
| Layer | What it produces | Where that lives |
|---|---|---|
| Execution | Attempts of the same task, successful or not | In the Foundry service: agents, conversations and responses |
| Telemetry | Spans with input, output, tools, latency and token consumption | In the Application Insights connected to the project |
| Evaluation | One verdict per task, pass or fail | In the evaluation run, over a sample of traces |
| Calculation | The cost per completed task and the completion rate | In the spreadsheet, query or dashboard that is yours |
| Reconciling | The close in money | In Cost Management and the billed charges |
Two constraints weigh more than the drawing. The first is access: server-side tracing turns on by itself once Application Insights is connected to the project, with no code changes, but querying the telemetry requires a role assigned on the connected resource. The second is the bill: Foundry stores the traces in that Application Insights, and retention and billing follow its configuration and that of Log Analytics. My reading: telemetry is the only layer you pay to keep standing even when nobody is looking at the cost.
How it works — step by step
- Define the task and the completed verdict before looking at the cost: what counts as delivered and who decides. Task Completion, a Foundry evaluator in preview, measures whether the agent completed the task with a usable result that meets all the requirements; it is one verdict option, not the business definition.
- Tag every attempt with the task ID. The Traces tab shows one entry per call to the agent, with Trace ID and Conversation ID, and the tracing page recommends consistent span attributes. My reading: the task ID is an attribute you add, and it is what ties the attempts together; the October 19 article covers the path of a response.
- Add up the spend of every attempt of each task, across all meters, including the attempts that failed and the tasks that never completed.
- Add up the cost of measuring: the tokens of the deployment that acts as judge and the telemetry in Application Insights.
- Divide the total by the completed tasks, not by calls, runs, turns or conversations.
- Report the completion rate next to the cost and say what went into the calculation and what stayed out.
- Reconcile with the invoice: according to the cost page, Estimated cost is for near-real-time monitoring, and Cost Management and invoiced charges are for financial reconciliation.
What the bill and the dashboard measure
The Estimated cost tile shows estimates for the agents of the selected projects and, according to the cost page, does not include prompt agents or non-Foundry agents; the estimates do not reflect discounts or contracted pricing and cover only standard deployments, not provisioned throughput. In the control plane agents table, the Estimated cost column is the estimated cost of the last month’s runs, based on the number of tokens consumed; Runs and Error rate count runs and the share of failures, and all three require observability to be configured. The pages I read do not say whether tools, container, judge and telemetry are part of the estimate, and this article does not claim that they are or that they are not. My reading: treat the dashboard estimate as a floor, not as the cost of the task.
Foundry cost is only a subset of the application cost: sending data to Azure Monitor Logs and creating alerts shows up in those services and at the subscription level, not when scoped to the Foundry resource alone. Per-project attribution, in preview, tags usage with the project tag and applies to models sold by Azure, not to Marketplace ones. The path of reconciling the estimate with the invoice, with the export and with per-project attribution was not executed.
Without Application Insights, the agent has no health metrics, cost tracking or detailed traces. Tracing captures inputs, outputs, tool usage, retries, latencies and costs of a run, and can incur costs based on volume and retention: measuring the cost per task costs money too.
A successful run is not a completed task
The Run success rate is the percentage of runs that finish successfully, and the dashboard page says a rate below 95% calls for investigation. It measures the run, not the user’s request. Task Completion is a different verdict: agent evaluators work like unit tests and return pass or fail; this one, in preview, evaluates by turn or by conversation and requires a deployment_name.
In the example, 10 of 12 runs finished well, 83%, and only 6 of 10 tasks were completed, 60%: four tasks had at least one successful run and never completed. The turn is not the conversation either: 11 of 17 turns passed, t09 is completed with a failed turn, and t04, t06 and t08 are not completed with passing turns. My reading: the Run success rate serves the health of the agent and the verdict serves the cost; an agent with 95% of runs successful can have a much lower completion rate.
The judge and the sample cost money too
Giving the verdict costs money: Task Completion requires a deployment_name, the deployment that judges, and the intelligent sampling page says the evaluation itself incurs inference cost. In the example, the judge is a call of 1,200 input tokens and 60 output tokens, 2,880 units; the 10 evaluations add up to 28,800, or 4,800 per completed task.
For live traffic, continuous evaluation accepts Random or Intelligent sampling, with a default limit of 100 runs per hour, adjustable in max_hourly_runs. Intelligent sampling reduces the cost and preserves diversity: it uses a MinHash farthest-first algorithm, which gives more lexical diversity than random sampling, including rare, hard and novel cases, and runs on local compute, with no extra API calls.
The example’s diverse_sample imitates that diversity from afar, one of each kind before repeating, and is not the platform’s algorithm. My reading: a sample built to be diverse does not carry the pass rate of the population; to project the completion rate and the cost per completed task, use a random sample, and leave the intelligent one to find the hard case. The judge path, with sampling over real traffic, was not executed: the example calls no model.
Stamp, query and judge: three examples
Between the dashboard and the cost per completed task three pieces are missing: the stamp that joins the attempts, the query that groups them and the verdict that decides the denominator. The three blocks below show the shape of each one, in the structures that appear on the pages I read on November 6, 2026. That path was not executed: there is no agent, project or Application Insights in this package, and the resource names are made up.
Stamp. Each attempt opens a span with the task ID and the attempt number. That pair is what joins the first attempt, the retry and the failed one in the same calculation:
from opentelemetry import trace
tracer = trace.get_tracer("agent.task")
def attempt(task_id, attempt_number, question):
with tracer.start_as_current_span("task.attempt") as span:
span.set_attribute("task.id", task_id)
span.set_attribute("task.attempt", attempt_number)
return run_agent(question)
run_agent is your call to the agent. My reading: the attribute is short and predictable on purpose, because it is a grouping key and not a content field: the user question, the document and the credential do not go in there.
Query. With the attribute on the span, a query in Application Insights groups the attempts by task. The shape comes from the sample query in the documentation, which reads the dependencies table and takes the agent identifier from customDimensions:
dependencies
| where timestamp between (ago(24h) .. now())
| extend agent_id = tostring(customDimensions["gen_ai.agent.id"])
| where agent_id == "refunds-agent"
| extend task_id = tostring(customDimensions["task.id"])
| where isnotempty(task_id)
| summarize traces = dcount(operation_Id), spans = count() by task_id
| summarize tasks = dcount(task_id), traces = sum(traces), spans = sum(spans)
It answers the denominator question: how many distinct tasks, how many traces per task and how many spans. The numerator is the same query adding up what each attempt spent. My reading: an attribute of yours, such as task.id, is not on the list of seven content attributes that change tables from September 30, 2026, so this grouping does not depend on the change; whoever reads prompts and responses to audit the verdict is the one who changes tables.
Judge. Evaluation over traffic already captured uses the azure_ai_traces data source: the service filters invoke_agent spans by the gen_ai.agent.id attribute, samples up to max_traces unique trace IDs within the lookback_hours window and evaluates every span of those traces. The testing criterion points to the evaluator and to the deployment that judges:
data_source = {
"type": "azure_ai_traces",
"agent_id": "refunds-agent",
"max_traces": 50,
"lookback_hours": 24,
}
testing_criteria = [
{
"type": "azure_ai_evaluator",
"name": "output_quality",
"evaluator_name": "builtin.output_quality",
"initialization_parameters": {
"deployment_name": "judge-deployment",
"evaluation_level": "conversation",
},
"data_mapping": {
"query": "{{item.query}}",
"response": "{{item.response}}",
"tool_definitions": "{{item.tool_definitions}}",
},
},
]
Two fields of that block are cost decisions, not configuration details. max_traces is the sample size, and it is what decides how much judge you pay for. evaluation_level chooses between scoring a turn and scoring the whole interaction — the same choice of unit that, in the local example, moves the number from 44,871 per completed task to 26,308 per passing turn. The composite builtin.output_quality batches Fluency, Coherence, Intent Resolution, Task Adherence, Groundedness and Task Completion into one judge call, to reduce cost and latency while keeping a score and a reason for each dimension. My reading: if your verdict is only completed or not completed, the composite charges one call and delivers five answers you did not ask for; if you want to calibrate the judge, those five come along with no extra call.
In practice: from the call to the completed task
The example prices ten hypothetical tasks of an agent, adds up the five meters, climbs from the call to the completed task and compares five decisions. It did not run with a real agent or in a Foundry project: it runs locally, with only the Python standard library, on hypothetical prices, calls, seconds, sessions and verdicts, in units. It shows the shape of the calculation, not the behavior of an agent or of an invoice. The code stays in English in both languages.
I ran it with Python 3.12.10. Unlike the three illustrative blocks of the previous section, the four blocks below form a single program that runs: save them to a file, in order, and run it with python.
The first block fixes the prices, the container of 1 vCPU and 2 GiB, the judge call, the fixed costs of the period and the sample size, and lists the ten tasks. Each call is a tuple with the input tokens, the ones that come from the cache (part of the input, cheaper) and the output tokens. My reading: the prompt grows with every call of a run because I assumed the history comes back as input; no page I read says so literally, and it is an assumption of the example.
import json
PRICE = {
"input": 2, "cached": 1, "output": 8,
"code_session": 3_000, "web_search": 25,
"vcpu_second": 2, "gib_second": 1,
}
CONTAINER = {"vcpu": 1, "gib": 2}
JUDGE_CALL = (1_200, 0, 60)
STANDING = {"file_search_storage": 6_000, "telemetry": 9_000}
SAMPLE_SIZE = 6
def attempt(succeeded, seconds, calls, code_sessions=0, web_searches=0):
return {"succeeded": succeeded, "seconds": seconds, "calls": calls,
"code_sessions": code_sessions, "web_searches": web_searches}
TASKS = [
{"id": "t01", "kind": "lookup", "done": True, "turns": [True],
"attempts": [attempt(True, 20, [(2_400, 1_600, 150)])]},
{"id": "t02", "kind": "update", "done": True, "turns": [True, True],
"attempts": [attempt(True, 90, [(3_000, 2_000, 200), (4_200, 3_000, 220), (5_400, 4_000, 300)])]},
{"id": "t03", "kind": "lookup", "done": True, "turns": [True],
"attempts": [attempt(True, 20, [(2_500, 1_600, 180)])]},
{"id": "t04", "kind": "analysis", "done": False, "turns": [True, False, False],
"attempts": [attempt(False, 120, [(3_500, 2_000, 300), (5_000, 3_500, 380)], 1, 2),
attempt(True, 240, [(3_500, 2_000, 320), (5_200, 3_500, 400), (7_000, 5_000, 450),
(9_000, 6_500, 520)], 1, 3)]},
{"id": "t05", "kind": "lookup", "done": False, "turns": [False],
"attempts": [attempt(True, 20, [(2_400, 1_600, 160)])]},
{"id": "t06", "kind": "update", "done": False, "turns": [True, False],
"attempts": [attempt(True, 90, [(3_100, 2_000, 210), (4_300, 3_000, 230), (5_600, 4_000, 320)])]},
{"id": "t07", "kind": "lookup", "done": True, "turns": [True],
"attempts": [attempt(True, 20, [(2_450, 1_600, 140)])]},
{"id": "t08", "kind": "analysis", "done": False, "turns": [True, True, False],
"attempts": [attempt(True, 240, [(3_600, 2_000, 330), (5_400, 3_500, 410), (7_300, 5_000, 460),
(9_500, 6_500, 540)], 1, 4)]},
{"id": "t09", "kind": "update", "done": True, "turns": [False, True],
"attempts": [attempt(False, 60, [(3_000, 2_000, 200), (4_100, 3_000, 0)]),
attempt(True, 90, [(3_000, 2_000, 200), (4_200, 3_000, 230), (5_500, 4_000, 310)])]},
{"id": "t10", "kind": "lookup", "done": True, "turns": [True],
"attempts": [attempt(True, 20, [(2_400, 1_600, 150)])]},
]
The second block computes the cost of one call, the cost of one run by meter and the sum of all of them; the container costs the active seconds times 4 units. per and percent divide with integers, round half up and return None when the denominator is zero.
def call_cost(call):
prompt, cached, output = call
return (prompt - cached) * PRICE["input"] + cached * PRICE["cached"] + output * PRICE["output"]
def attempt_costs(run):
container_rate = CONTAINER["vcpu"] * PRICE["vcpu_second"] + CONTAINER["gib"] * PRICE["gib_second"]
return {
"tokens": sum(call_cost(call) for call in run["calls"]),
"tools": run["code_sessions"] * PRICE["code_session"] + run["web_searches"] * PRICE["web_search"],
"container": run["seconds"] * container_rate,
}
def spend(tasks):
totals = dict.fromkeys(("tokens", "tools", "container"), 0)
for task in tasks:
for run in task["attempts"]:
for name, value in attempt_costs(run).items():
totals[name] += value
return totals
def evaluation_cost(evaluations):
return evaluations * call_cost(JUDGE_CALL)
def per(total, count):
return None if count == 0 else (2 * total + count) // (2 * count)
def percent(part, whole):
return None if whole == 0 else (200 * part + whole) // (2 * whole)
The third block groups the spend into the five meters, with file search storage and telemetry as fixed costs of the period, climbs the ladder in climb and computes the five decisions in decisions.
def buckets(tasks, evaluations):
spent = spend(tasks)
return {
"tokens": spent["tokens"],
"tools": spent["tools"] + STANDING["file_search_storage"],
"container": spent["container"],
"judge": evaluation_cost(evaluations),
"telemetry": STANDING["telemetry"],
}
def climb(parts, completed):
running, steps = 0, {}
for name, value in parts.items():
running += value
steps[name] = per(running, completed)
return steps
def diverse_sample(tasks, size):
seen, ranked = {}, []
for task in tasks:
seen[task["kind"]] = seen.get(task["kind"], 0) + 1
ranked.append((seen[task["kind"]], task))
return [task for _, task in sorted(ranked, key=lambda pair: pair[0])[:size]]
def decisions(tasks, sample_size):
completed = sum(task["done"] for task in tasks)
finished = [task for task in tasks if task["done"]]
turns = sum(len(task["turns"]) for task in tasks)
passed = sum(sum(task["turns"]) for task in tasks)
sample = diverse_sample(tasks, sample_size)
sample_done = sum(task["done"] for task in sample)
sampled = sum(buckets(tasks, len(sample)).values())
return {
"all_attempts": per(sum(buckets(tasks, len(tasks)).values()), completed),
"completed_tasks_only": per(sum(buckets(finished, len(finished)).values()), completed),
"passed_turns": per(sum(buckets(tasks, turns).values()), passed),
"diverse_sample": per(sampled * len(sample), len(tasks) * sample_done),
"random_sample": per(sampled, completed),
}
The fourth block builds the report and prints the JSON, one key per line:
def report():
runs = [run for task in TASKS for run in task["attempts"]]
calls = [call for run in runs for call in run["calls"]]
completed = sum(task["done"] for task in TASKS)
parts = buckets(TASKS, len(TASKS))
sample = diverse_sample(TASKS, SAMPLE_SIZE)
return {
"counts": {"tasks": len(TASKS), "completed": completed, "runs": len(runs),
"runs_succeeded": sum(run["succeeded"] for run in runs), "calls": len(calls),
"turns": sum(len(task["turns"]) for task in TASKS),
"passed_turns": sum(sum(task["turns"]) for task in TASKS)},
"spend": {**parts, "total": sum(parts.values())},
"per_call": per(parts["tokens"], len(calls)),
"per_run": per(parts["tokens"], len(runs)),
"climb": climb(parts, completed),
"rates": {"run_success": percent(sum(run["succeeded"] for run in runs), len(runs)),
"task_completion": percent(completed, len(TASKS)),
"diverse_sample": percent(sum(task["done"] for task in sample), len(sample))},
"decisions": decisions(TASKS, SAMPLE_SIZE),
}
def main():
print("{")
print(",\n".join(f' "{key}": {json.dumps(value)}' for key, value in report().items()))
print("}")
if __name__ == "__main__":
main()
The output of main():
{
"counts": {"tasks": 10, "completed": 6, "runs": 12, "runs_succeeded": 10, "calls": 26, "turns": 17, "passed_turns": 11},
"spend": {"tokens": 212080, "tools": 15225, "container": 4120, "judge": 28800, "telemetry": 9000, "total": 269225},
"per_call": 8157,
"per_run": 17673,
"climb": {"tokens": 35347, "tools": 37884, "container": 38571, "judge": 43371, "telemetry": 44871},
"rates": {"run_success": 83, "task_completion": 60, "diverse_sample": 50},
"decisions": {"all_attempts": 44871, "completed_tasks_only": 17783, "passed_turns": 26308, "diverse_sample": 51541, "random_sample": 42951}
}
The first table is the ladder from the call to the completed task, with per_call, per_run and climb:
| Unit | Cost | What goes into the calculation |
|---|---|---|
| Per call | 8,157 | Tokens ÷ 26 calls |
| Per run | 17,673 | Tokens ÷ 12 runs |
| Per completed task, tokens only | 35,347 | Tokens of every attempt ÷ 6 completed tasks |
| + tools | 37,884 | Code Interpreter, web searches and storage |
| + container | 38,571 | Active seconds of the hosted agent |
| + judge | 43,371 | 10 evaluations, one per task |
| + telemetry | 44,871 | Fixed telemetry cost for the period |
Each step changes the question, and the last unit, 44,871, is more than five times the first, 8,157; from 17,673 to 35,347 the cost doubles because the 12 runs spend tokens and only 6 tasks completed. What is not tokens weighs: it adds 9,524 per completed task, 27% on top of the 35,347 of tokens alone, with the judge, 4,800, the biggest addition.
The second table shows what each decision does to the number, against the reference of 44,871:
| Decision | Cost per completed task | Against the reference |
|---|---|---|
| Every attempt and every meter | 44,871 | reference |
| Only the completed tasks | 17,783 | −60% |
| Passing turn as the unit | 26,308 | −41% |
| Diverse sample, projected rate | 51,541 | +15% |
| Random sample, population rate | 42,951 | −4% |
Throwing away what did not complete takes off 60%: the four tasks that did not complete account for more than half of the spend. Counting turns changes the unit: with 11 passing turns instead of 6 tasks the cost goes to 26,308, and the judge is paid 17 times, 48,960 against 28,800. Sampling saves little and distorts a lot: evaluating 6 of the 10 tasks saves 11,520 of judge, 4% of the total spend, but the diverse sample, with a completion rate of 50% projected onto the 10 tasks, takes the cost to 51,541, against 42,951 for the random one; that distance, 8,590, is larger than the saving per completed task, 1,920.
What the number does not solve
- It is not a price or a statistic. The prices are hypothetical units, and ten tasks show only the shape of the calculation.
- Fixed cost is spread over these ten tasks only. File search storage, 6,000, and telemetry, 9,000, are costs of the period, and in production the allocation is your choice.
- The example charges the input of a call that failed, as in
t09; if yours fails before reaching the model, the real bill is lower. - The container counts only the seconds of work. The pages give the idle timeout range of the hosted agent, from 2 to 240 minutes with 15 by default, and say that each request resets the timer, but do not say whether the window is billed. My reading: if the window counts as an active session, the container cost per task starts to depend on the interval between requests.
- The verdict is a measurement, and measurements err. Calibrate the judge with a sample reviewed by people.
- Memory is another meter. In preview, it bills the chat and embedding models you configure, and it was not part of the example.
Production best practices
- Write the verdict before measuring the cost. Without a definition of completed, the denominator is opinion.
- Tag every attempt with the task ID, as a span attribute, across all agents and tools.
- Add up every attempt, including the repeated ones and those of tasks that never completed.
- Separate the cost of serving from the cost of measuring, in their own lines, to sample the judge without touching the rest.
- Treat the dashboard estimate as a floor and reconcile it with Cost Management and the invoice.
- Check that your queries already read
AppGenAIContent. September 30, 2026 has passed, and the documentation says to read the content attributes from it and to update your own dashboards and alerts. - Report the completion rate next to the cost, with the number of tasks, the unit of the verdict and what went into the calculation.
- Project the rate with a random sample, and leave the intelligent one to find the hard case.
- Size the container and the tool list. Oversizing multiplies the cost by the concurrency, and every tool definition adds input tokens.
- Recalculate the number at every change of model, tool, prompt, judge or sampling.
What has to be in place
The order below is causal, not chronological: each stage exists because the previous one is in place.
Foundation — the task has a verdict. Each kind of task has a definition of completed, who decides and an ID that travels through all the attempts.
It is in place when you can answer, for each kind of task, what completed means, who decides and how the attempts are tied together.
Production with context — the cost reaches the task. The spend of every attempt and every meter is added up per task, the cost of measuring gets its own lines and the completion rate shows up alongside.
It is in place when the cost per completed task comes out with the completion rate, the sample size and what went into the calculation.
Scale and efficiency — the number is reviewed at every change. The dashboard estimate is reconciled with the invoice, the sample is designed for what you want to project and the number is recalculated at every change of model, tool, prompt, judge or container.
It is in place when swapping a model, a tool or the container size shows, in the same report, how much the cost per completed task changed.
Frequently asked questions (FAQ)
Does the Foundry Agent Service report the cost per completed task?
On the pages I read on November 6, 2026, I did not find a cost-per-completed-task metric: the documentation shows the estimated cost per agent, based on tokens, and the counts of runs and errors. On those pages, the calculation is yours.
Why not divide the cost by the successful runs?
Because a successful run and a completed task are different verdicts: the Run success rate says the run finished without an error, and Task Completion evaluates whether the requested task was completed with a usable result. In the example, 83% of the runs finished well and 60% of the tasks were completed.
Does the judge cost go into the cost per completed task?
It does, if the number is meant to decide whether the agent is worth what it costs, because a task only counts as completed after the verdict: in the example, 4,800 per completed task. If the judge only runs in testing, report both lines, with and without it.
Do I need to evaluate every task or can I sample?
It depends on what you want to project. Continuous evaluation accepts Random or Intelligent sampling, with a default limit of 100 runs per hour, adjustable in max_hourly_runs. The intelligent one finds the rare case; to project the completion rate and the cost per completed task, the random one does not pull the number toward the hard cases.
Does the hosted agent container go into the cost of each task?
It does, for those who use a hosted agent: billing is by CPU and memory consumption in active sessions. The pages I read do not say whether the idle timeout window is billed, and the example counts only the seconds of work.
Do I need to instrument the agent to measure the cost per task?
It depends on where the number is born. Server-side tracing turns on by itself once Application Insights is connected to the project, with no code changes, and Foundry stores the traces in that resource, with retention and billing following its configuration and that of Log Analytics. What does not come ready is the task ID: that attribute is yours. To query the telemetry you need the Log Analytics Reader role on the connected resource, and protected tables also ask for the Privileged Monitoring Data Reader role.
What changes in my queries from September 30, 2026?
The date has passed, but the page I read on November 6, 2026 still describes it in the future, and I did not check the effect in any project. According to it, from September 30, 2026 Application Insights stops writing the value of seven generative AI content attributes to the AppDependencies, AppTraces and AppEvents tables for new data: the keys stay, with a pointer to AppGenAIContent. What was ingested before remains queryable, and the documentation asks you to update your own queries, alert rules, dashboards and reports. Whoever needs more time can register the feature flag optOutProtectGenAISensitiveData, which keeps the current routing; according to the page, it is temporary and ends on September 30, 2027. My reading: whoever groups cost by an attribute of their own is not affected; whoever reads prompts and responses to audit the verdict changes tables.
How do I attribute cost to a project or a task?
Per-project attribution is in preview: it tags usage with the project tag. Per task, I did not find a native feature on the pages I read. My reading: tag every attempt with the task ID as a span attribute, compute the cost of each one from the tokens the traces record, add up the tools and the container that you measure outside, and check against the invoice.
Conclusion
A completed task costs what every attempt and every meter spent to get there, plus what it cost to prove it got there, and, on the pages I read, the platform does not hand you that calculation ready-made. Define the verdict, tag every attempt, add up what is not tokens and divide only by the completed ones, saying what went in. My reading: the biggest gain is in making visible what the tasks that did not complete cost, not in making the token cheaper. It is a reading of the documentation and of a local example, not of an agent in production. The cost of the call, the FinOps choices and the reasoning tokens are in the articles of July 21, August 13 and October 27.
Official references
- Foundry Agent Service: pricing page.
- Foundry Agent Service: overview and agent types.
- Foundry Agent Service: runtime components.
- Foundry: plan and manage costs.
- Foundry control plane: manage agents.
- Foundry control plane: monitor the agent fleet.
- Foundry: agent monitoring dashboard.
- Foundry: cloud evaluation of deployed interactions.
- Foundry: agent evaluators.
- Foundry: agent tracing, concepts.
- Foundry: set up agent tracing.
- Foundry: sensitive content in traces.
- Foundry Agent Service: File search tool.
- Foundry Agent Service: Code Interpreter tool.
- Foundry Agent Service: Web search tool.
- Foundry Agent Service: tool catalog.
- Foundry Agent Service: hosted agents.
- Foundry Agent Service: memory.
👉 If you have an agent in production and finance asks how much each resolved request costs, start with the verdict: write down what completed means and tag every attempt with the task ID before looking at the dashboard. Want to talk about agent cost? Reach out on LinkedIn.
