Debugging a cuga agent run
Trajectory viewer
Every run is logged to a trajectory data directory (<cuga log dir>/trajectory_data). Inspect it visually:
cuga viz
Launches a web dashboard for browsing execution trajectories: what the reasoning engine decided at each step, which tools it called with what arguments, and what came back. Start here before reading raw logs — it's usually faster to spot the wrong branch/tool call visually than to grep JSON.
Environment sanity check
cuga doctor
Run this first if the agent won't even start, or behaves inconsistently across environments — it validates the environment/dependency setup.
cuga status
cuga status <service|all>
Confirms whether the service you expect to be running actually is, before chasing a bug that's really just "nothing is listening on that port."
Common failure patterns
- Tool "not found" or never called — check the tool actually got passed to
CugaAgent(tools=[...]), or (for OpenAPI/MCP tools) that the registry service (cuga start registry, or the registry bundled in ademo_*/managerservice) picked up yourmcp_servers.yamlchange — those are build-time, not hot-reloaded. - Request silently redirected/blocked with no obvious reason — an
intent_guardpolicy may be matching. Check.cuga/guards/(or policies added viaagent.policies.add_intent_guard) for a guard whosetriggers/intent_examplesoverlap the query, and checkpriority— guards default to high priority (90-100) and are checked before other policies. Seecuga-author-policy. - Response in the wrong shape — an
output_formatterpolicy may be firing (or not firing when expected) based on itstriggers.natural_languagekeywords andthreshold. Lower/raise the threshold or adjust keywords. - Tool paused waiting on nothing — a
tool_approvalpolicy is likely gating that tool; check.cuga/approvals/forrequired_tools/required_appsmatches andauto_approve_after. thread_idconfusion — state (conversation history, session-scoped knowledge) is isolated perthread_id. If a run seems to have "forgotten" something from a previous call, confirm the samethread_idwas passed both times.- Multi-agent: wrong sub-agent picked — the
CugaSupervisorroutes based on each sub-agent's.description. Vague or overlapping descriptions between sub-agents cause misrouting — make them distinct and specific.
Policy-level test coverage
If you're debugging policy interaction bugs specifically, the policy engine's own integration tests are a good reference for expected behavior: src/cuga/backend/cuga_graph/policy/tests/ in a cuga-agent checkout (covers intent guard blocking/priority resolution, playbook guidance injection, and more).