AI agents are increasingly orchestrating multi‑day or multi‑week activities together with users, tools, and system resources. To improve quality, safety, and cost efficiency, developers must pinpoint failure locations, understand triggers of unsafe effects, and identify the most budget‑intensive tasks for targeted optimization. In systems software, profiling aggregates resource consumption and attributes it to specific code paths to reveal hotspots. Existing agent observability tools, however, focus on per‑execution debugging and tracing, lacking cross‑run, long‑term profiling, which makes these questions hard to answer at scale.
Profiling agents is challenging because the responsible entities are task intents (e.g., diagnose authentication, compare branches) rather than code paths, and stable identifiers for aggregation are absent. We propose a semantic operation stack model that abstracts all activities into uniform operations and replaces the runtime call stack with an operation stack, enabling hierarchical attribution at various granularities. Observing that a task occupies a contiguous span in a trajectory and decomposes into subtasks, we introduce recursive operation segmentation, which recursively splits trajectories at task boundaries.
AgentPProf aggregates agent trajectories into pprof‑compatible profiles, supporting flame‑graph visualization and analysis. Experiments show that AgentPProf achieves 0.764 $B^3$ F1 against human annotations on CodeTraceBench, and raises MAP by up to 56% on three problem‑localization benchmarks, demonstrating effective resource attribution, problem localization, and token‑cost optimization at practical profiling overhead. The source code is available at https://github.com/eunomia-bpf/agentsight.
Review