Analyze a sequence of agent loop steps and return a diagnostic report detecting repeated actions, stuck reasoning, and slow steps.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement diagnose_trace(steps) that analyzes a list of agent loop step dicts and returns a diagnostic report dict.
Each step dict has keys:
- step_number (int)
- thought (str)
- action (str — tool name or "Final Answer")
- arguments (dict)
- observation (str)
- duration_ms (int)
Return a dict:
{
"total_steps": len(steps),
"total_duration_ms": <sum of all duration_ms>,
"tool_call_count": <number of steps where action is not "Final Answer">,
"error_count": <number of steps where observation contains "error" (case-insensitive) or action is "error">,
"repeated_actions": <list of action names that appear 3+ times consecutively, deduplicated>,
"stuck_reasoning": <True if any thought appears 3+ times consecutively, else False>,
"slow_steps": <list of step numbers where duration_ms > 2000>,
"has_final_answer": <True if any action is "Final Answer", else False>
}
Edge cases:
- If steps is None or empty, return a zeroed report (total_steps: 0, all counts 0, empty lists).
- A step with missing keys should be skipped (not counted in any metric).
- repeated_actions only catches consecutive repeats (e.g. ["search", "search", "search"]), not non-consecutive ones.
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def diagnose_trace(steps):
"""Analyze agent trace steps and return a diagnostic report."""Implement trace diagnostic logic
Already have Pro access? Sign in