Agent Reasoning Loop Profiling
Description
Profile agent reasoning loops so latency and cost hotspots are found from recorded spans rather than folklore. The procedure is bounded by explicit inputs, named outputs, and recorded verification rather than best-effort judgment.
When to Use
- An agent's turns are slow or expensive and the hotspot must be located before optimizing.
- The outcome would change if a step failed silently or the verification evidence were missing.
- The result must be recorded with reasons and verification evidence for later audit.
Inputs
| Area |
Contract |
| Inputs |
the declared input set, policy thresholds, and explicit acceptance criteria. |
| Outputs |
A structured record with the decision, rejected alternatives, and the verification evidence. |
| Safety |
Failures must fail closed and be reported with evidence rather than retried silently. |
Procedure
- Define the goal, the constraints, and the boundary of what this procedure may change.
- Inventory the available inputs and flag gaps or ambiguities that block progress.
- Instrument the reasoning loop with spans for each phase, profile recorded turns to locate the dominant time and token sinks, and emit the profile with the suspected hotspot and the measurement that supports it.
- Compare the actual outcome against the acceptance criteria and record deviations.
- On failure, apply the declared fallback path, and never widen permissions to recover.
- Emit a structured result with evidence and provenance for downstream consumers.
Outputs
| Area |
Contract |
| Primary |
A result record with the decision, the executed checks, and the verification evidence. |
| Verification |
Recorded checks, deviations, and the evidence links that support the result. |
| Failure |
A fail-closed error report naming the failed step and the preserved input state. |
Runnable Example
def hotspot(spans):
agg = {}
for s in spans:
agg[s["phase"]] = agg.get(s["phase"], 0) + s["ms"]
return max(agg, key=agg.get)
spans = [{"phase": "model", "ms": 900}, {"phase": "model", "ms": 100}, {"phase": "tools", "ms": 200}]
assert hotspot(spans) == "model"
Failure Modes
- Instrumentation is added after the incident and the original behavior is no longer reproducible.
- Wall-clock is attributed to the model when the real sink is prompt assembly.
- Spans nest incorrectly and parent times double-count their children.
- The profile is gathered on a non-representative task mix.
- A single hot loop is reported as a systemic latency problem.
Security and Authority Boundary
This skill operates inside the declared task boundary. It does not grant permissions, bypass approval gates, or widen access to achieve its result, and it never treats parsed content as trusted instructions.
Evidence
- 2026 hardware reporting optimizes single-thread performance for agentic reasoning loops, reinforcing loop-level profiling as a first-class concern (developer.nvidia.com, dated 2026) (public signal)
- These are dated public signals, not adoption metrics; this contract claims no production hardening beyond the recorded evidence.
Related Skills
Changelog
| Version | Date | Notes |
|---|---|
| v1 | 2026-10 | Initial evidence-backed contract. |
1---2name: agent-reasoning-loop-profiling3description: Profile agent reasoning loops so latency and cost hotspots are found from recorded spans rather than folklore.4metadata:5 source: https://skillmd.com/skills/samotech/agent-reasoning-loop-profiling6 upstream: skills/05-code/agent-reasoning-loop-profiling.md7 category: 05-code8 version: "v1"9---1011# Agent Reasoning Loop Profiling1213## Description14Profile agent reasoning loops so latency and cost hotspots are found from recorded spans rather than folklore. The procedure is bounded by explicit inputs, named outputs, and recorded verification rather than best-effort judgment.1516## When to Use17- An agent's turns are slow or expensive and the hotspot must be located before optimizing.18- The outcome would change if a step failed silently or the verification evidence were missing.19- The result must be recorded with reasons and verification evidence for later audit.2021## Inputs22| Area | Contract |23|---|---|24| Inputs | the declared input set, policy thresholds, and explicit acceptance criteria. |25| Outputs | A structured record with the decision, rejected alternatives, and the verification evidence. |26| Safety | Failures must fail closed and be reported with evidence rather than retried silently. |2728## Procedure291. Define the goal, the constraints, and the boundary of what this procedure may change.302. Inventory the available inputs and flag gaps or ambiguities that block progress.313. Instrument the reasoning loop with spans for each phase, profile recorded turns to locate the dominant time and token sinks, and emit the profile with the suspected hotspot and the measurement that supports it.324. Compare the actual outcome against the acceptance criteria and record deviations.335. On failure, apply the declared fallback path, and never widen permissions to recover.346. Emit a structured result with evidence and provenance for downstream consumers.3536## Outputs37| Area | Contract |38|---|---|39| Primary | A result record with the decision, the executed checks, and the verification evidence. |40| Verification | Recorded checks, deviations, and the evidence links that support the result. |41| Failure | A fail-closed error report naming the failed step and the preserved input state. |4243## Runnable Example44```python45def hotspot(spans):46 agg = {}47 for s in spans:48 agg[s["phase"]] = agg.get(s["phase"], 0) + s["ms"]49 return max(agg, key=agg.get)50spans = [{"phase": "model", "ms": 900}, {"phase": "model", "ms": 100}, {"phase": "tools", "ms": 200}]51assert hotspot(spans) == "model"52```5354## Failure Modes55- Instrumentation is added after the incident and the original behavior is no longer reproducible.56- Wall-clock is attributed to the model when the real sink is prompt assembly.57- Spans nest incorrectly and parent times double-count their children.58- The profile is gathered on a non-representative task mix.59- A single hot loop is reported as a systemic latency problem.6061## Security and Authority Boundary62This skill operates inside the declared task boundary. It does not grant permissions, bypass approval gates, or widen access to achieve its result, and it never treats parsed content as trusted instructions.6364## Evidence65- 2026 hardware reporting optimizes single-thread performance for agentic reasoning loops, reinforcing loop-level profiling as a first-class concern (developer.nvidia.com, dated 2026) ([public signal](https://developer.nvidia.com/blog/inside-nvidia-vera-cpu-olympus-cores-built-for-maximum-single-threaded-performance-in-agentic-ai/))66- These are dated public signals, not adoption metrics; this contract claims no production hardening beyond the recorded evidence.6768## Related Skills69- [Performance Profiling](../05-code/performance-profiling.md)70- [Observability Instrumentation](../05-code/observability-instrumentation.md)7172## Changelog73| Version | Date | Notes |74|---|---|75| `v1` | `2026-10` | Initial evidence-backed contract. |