the short answer
Measure cost per successful task and p50 and p95 latency for each task type, not only cost per model call or average response time. In Failproof AI, query complete production sessions by agent and environment, save the results to dashboards and alert when a budget is exceeded. Then audit the affected sessions to find recurring causes such as retry loops, oversized context, unnecessary tool calls or a slow dependency, fix the agent and keep the same measurements running to verify recovery.
- Cost
- Total session spend divided by completed tasks and successful tasks.
- Latency
- p50 for the typical run and p95 for the slow experience users notice.
- Scope
- Separate budgets by task type, agent and environment.
- Outcome
- Find and fix the behavior causing the expensive or slow tail.
Measure the Task, Not One Model Call
An agent can return the right answer and still fail economically. A support resolution that takes forty tool calls, repeated retries and several minutes may cost more than the work it replaces. Cost and latency therefore belong beside task completion and quality, not in a separate infrastructure report.
Measure the complete session. Include every model call, tool call and failed attempt used to complete the task. Report both cost per attempted task and cost per successful task because failed sessions still consume tokens and infrastructure.
| Measure | What it answers |
|---|---|
| Cost per task | What does an average attempt cost? |
| Cost per successful task | What does a useful outcome cost after failed attempts are included? |
| p50 latency | How long does a typical task take? |
| p95 latency | How slow is the experience for the worst common cases? |
| Tool calls and retries | Which agent behavior is driving cost or delay? |
1. Set a Budget for Each Task Type
Do not use one threshold for every agent session. An interactive support answer, a code change and a background research task have different acceptable costs and response times. Identify the task type in session metadata, then define a cost, latency and step budget for each one.
| Task type | Useful starting measures |
|---|---|
| Interactive answer | p50 and p95 response time, cost per answer, success rate |
| Support resolution | Cost per resolved case, p95 resolution time, tool retries |
| Coding task | Cost per accepted change, elapsed time, model turns, test retries |
| Background research | Cost per completed report, total duration, source and tool-call count |
Start by observing the current distribution. A baseline tells you how large the gap is, but it should not define what “good” means when current performance is already unacceptable.
2. Ask Failproof Where Cost and Latency Are Going
Send complete sessions to Failproof AI and identify the agent and environment consistently. Use Analyze → Queries to calculate task-level cost, latency and success measures from production traces. Queries are read-only SQL, and saved queries can be added directly to dashboards.
You can also ask the Failproof agent to investigate in plain language. Start with a broad question, inspect the generated result and save the useful query so the team uses the same definition every time.
fp agent ask "Show cost per successful task and p95 latency by agent and environment for the last seven days"
fp agent ask "Which production sessions exceeded their latency budget, and what did they have in common?"
fp query run <query-id>Break the results down by agent, environment, task type and time period. An overall average can hide one workflow that is becoming slower or one agent version that is consuming far more tokens than the rest.
3. Read Cost, Latency and Quality Together
A cheaper agent is not better if it completes fewer tasks, and a faster agent is not better if it skips verification. Put cost and latency beside the evaluations that measure task completion, correctness and required behavior.
| Pattern | Likely interpretation |
|---|---|
| Cost falls and quality holds | A genuine efficiency improvement |
| Cost falls and completion falls | The agent may be stopping too early or doing less work |
| Latency rises while tool errors rise | A dependency or retry loop may be slowing the agent |
| p50 holds while p95 rises | A smaller group of sessions has developed a severe slow path |
| Quality holds while steps rise | The agent is reaching the same result less efficiently |
Keep each measure visible rather than blending everything into one score. Separate signals make the trade-off clear and preserve the evidence needed to choose a fix.
4. Build Dashboards and Alert on Budget Breaches
Save the queries that define cost per successful task, p50 and p95 latency, over-budget session rate, tool-call count and quality. Build a dashboard from those saved queries so product and engineering teams see the same trend and can open the sessions behind a change.
Create alerts for metric thresholds, evaluation-score changes, compound conditions or custom SQL. A useful alert identifies the affected agent and environment and links to the sessions, instead of announcing only that a global average moved. Route alerts to email, Slack, a webhook or the Failproof dashboard.
Avoid paging on every slow session. Alert on sustained budget-breach rates or a meaningful increase from baseline, then retain individual sessions for investigation.
5. Find What Is Causing the Expensive Tail
A dashboard tells you that cost or latency changed. An audit helps explain why. Scope a Failproof audit to the affected agent, environment and time window with a goal such as “find recurring behaviors in sessions that exceed the cost or latency budget.”
The audit analyzes traces, evaluation results and related evidence, then groups similar sessions into findings. Common causes include repeated tool retries, oversized tool results, unnecessary model turns, growing context, a slow dependency or a workflow that sends simple tasks through an expensive path.
fp audits findings --status open --limit 20Review the affected sessions and recommendation, assign the issue and fix the actual cause. That may mean changing the prompt, routing a task to a smaller model, truncating stale context, repairing a tool, reducing retries or splitting one workflow into clearer steps.
6. Verify the Improvement in Production
Keep the original queries, evaluations, dashboards and audit goal running after the change. Compare the same agent and task type before and after deployment. The fix is successful only if cost or latency improves without lowering completion or quality and the original failure pattern stops recurring.
Re-baseline budgets after a deliberate model or workflow change, but preserve the earlier dashboard long enough to show the effect. Otherwise a new threshold can make a regression disappear on paper.
FAQ
How do I calculate AI agent cost per task?
Add the model and infrastructure cost across the complete session, including failed attempts. Divide total spend by all tasks for cost per attempt and by successful tasks for cost per successful outcome.
Should I track average or p95 agent latency?
Track p50 and p95 for user experience and keep the mean for aggregate forecasting. The p95 exposes the slow tail that an average can hide.
Can Failproof AI analyze agent cost and latency?
Yes. Use native read-only queries or ask the Failproof agent to analyze production sessions, save the resulting queries to dashboards, alert on thresholds and audit over-budget sessions to find recurring causes.
What is a good latency budget for an AI agent?
It depends on the task. Set the budget from how long the user can reasonably wait and what the successful task is worth, then compare it with the current p95. Interactive work may require seconds while background work can tolerate minutes.
Get Started
Failproof AI is free to start. It finds recurring failure modes across agent sessions using code-based and LLM-based evaluations, groups the evidence into findings, and recommends fixes. Bring the eval suite you already have, alert the right owner when behavior drifts, and turn a tested fix into a policy that prevents the failure from recurring. See pricing for the tiers.
Sources
Products change; if a detail here is out of date, tell us at support@befailproof.ai.
- Failproof AI docs: Queries
- Failproof AI docs: Dashboards
- Failproof AI docs: Alerts
- Failproof AI docs: Audits