◉ANTIGRAVITY LABJP
Articles/Agents & Manager
◈ Agents & Manager/2026-04-26Advanced

Designing Antigravity Agent Traces That Tell You Why It Failed — Observability in Practice

How to add OpenTelemetry spans to your own agent loop so a failure can be read in a few lines. Covers span structure, what to keep and drop in attributes, a failure_class taxonomy, a retry table, three dashboard views, cost attributes, and PII handling — with code that runs.

Antigravity422agents152observability19tracing3operations33OpenTelemetry

✦ Premium Article

The agent ran overnight and had failed by morning. The log held a single error line, and nothing in it said which cycle, which tool call, or why. I had been scattering console.log calls and scrolling from the top, and that stopped working the moment the number of runs grew.

This article is the line I drew after that. It is not a write-up of measured results — only the design that made me feel "if the cycle boundary is recorded, failures read differently."

One premise first. I cannot reach inside Antigravity itself, so the instrumentation here goes into an agent loop you write yourself — a script, a worker, or the tools the agent calls. Antigravity does not emit this span structure out of the box.

Why agents end up in the "I can't tell why it failed" hole

I think the causes cluster into three.

The first is fuzzy step boundaries. An agent cycles through "tool call → LLM inference → state update," and if that boundary is not recorded you cannot tell which step of which cycle broke. A flat, time-stamped log does not show the structure between cycles.

The second is opaque inputs and outputs. The LLM call itself is logged, but the context passed in and the raw response that came back are not. The failure ends as "the LLM said something odd" and cannot be reproduced.

The third is no failure taxonomy. Errors are logged, yet afterward you cannot tell whether a failure was retryable, worth telling the user about, or a plain bug. That leads straight to alert fatigue and a retry policy that falls apart.

Observability design means wiring these three into a structure before you need it.

The base unit of a trace — pick a span structure

I align with OpenTelemetry semantics and represent agent execution like this. The shape is generic, not Antigravity-specific, but adding a "cycle" level is what makes it work for agents.

- agent.run               (root span: one full agent execution)
  - agent.cycle           (one reason-and-act cycle)
    - agent.plan          (LLM decides the next action)
    - agent.tool_call     (tool execution, one span per tool)
    - agent.observe       (fold the result back into context)
  - agent.cycle
    - ...

The reason to make agent.cycle its own span is simple. If the agent runs eight cycles and fails in the fifth, without a per-cycle span a person has to read logs by eye to extract "the tool died in cycle five."

The implementation is a single call at the start of each cycle. In Python it looks like this — note that running out of cycles is also recorded as a classified failure.

from opentelemetry import trace
from opentelemetry.trace import Status, StatusCode
 
tracer = trace.get_tracer("antigravity.agent")
 
class AgentError(Exception):
    def __init__(self, message, failure_class):
        super().__init__(message)
        self.failure_class = failure_class
 
def run_agent(task):
    with tracer.start_as_current_span("agent.run") as run_span:
        run_span.set_attribute("task.id", task.id)
        run_span.set_attribute("task.kind", task.kind)
        run_span.set_attribute("agent.policy", task.policy_name)
        run_span.set_attribute("agent.tools_available", list(task.tools))
 
        try:
            for cycle_idx in range(MAX_CYCLES):
                with tracer.start_as_current_span("agent.cycle") as cycle_span:
                    cycle_span.set_attribute("cycle.index", cycle_idx)
                    action = plan_next_action(task)
                    if action is None:
                        cycle_span.set_attribute("cycle.terminated", True)
                        run_span.set_attribute("run.cycle_count", cycle_idx + 1)
                        run_span.set_attribute("result.status", "success")
                        return success(task)
 
                    cycle_span.set_attribute("cycle.action_type", action.kind)
                    result = execute_tool(action)
                    observe(task, result)
 
            # Exhausting the loop is also a failure worth classifying
            raise AgentError("max cycles exceeded", "cycle_budget_exceeded")
        except AgentError as e:
            run_span.set_status(Status(StatusCode.ERROR, str(e)))
            run_span.set_attribute("run.cycle_count", MAX_CYCLES)
            run_span.set_attribute("result.status", "failure")
            run_span.set_attribute("result.failure_class", e.failure_class)
            raise

When an exception escapes a with block, the OpenTelemetry Python SDK records it on the span and sets the status to ERROR by default. You still have to attach failure_class yourself, because the SDK cannot know what a failure means.

In TypeScript (Node.js), the same structure with @opentelemetry/api. A span handed to startActiveSpan is not closed automatically, so call end() in a finally.

import { trace, SpanStatusCode } from "@opentelemetry/api";
 
const tracer = trace.getTracer("antigravity.agent");
 
export async function runAgent(task: Task): Promise<Result> {
  return await tracer.startActiveSpan("agent.run", async (runSpan) => {
    runSpan.setAttribute("task.id", task.id);
    runSpan.setAttribute("task.kind", task.kind);
    runSpan.setAttribute("agent.policy", task.policyName);
 
    try {
      for (let cycleIdx = 0; cycleIdx < MAX_CYCLES; cycleIdx++) {
        const done = await tracer.startActiveSpan(
          "agent.cycle",
          async (cycleSpan) => {
            try {
              cycleSpan.setAttribute("cycle.index", cycleIdx);
              const action = await planNextAction(task);
              if (action === null) {
                cycleSpan.setAttribute("cycle.terminated", true);
                return true;
              }
              cycleSpan.setAttribute("cycle.action_type", action.kind);
              const result = await executeTool(action);
              observe(task, result);
              return false;
            } finally {
              cycleSpan.end();
            }
          }
        );
        if (done) {
          runSpan.setAttribute("run.cycle_count", cycleIdx + 1);
          runSpan.setAttribute("result.status", "success");
          return success(task);
        }
      }
      throw new AgentError("max cycles exceeded", "cycle_budget_exceeded");
    } catch (e) {
      runSpan.setStatus({ code: SpanStatusCode.ERROR, message: String(e) });
      runSpan.setAttribute("result.status", "failure");
      runSpan.setAttribute("result.failure_class", classify(e));
      throw e;
    } finally {
      runSpan.end();
    }
  });
}

Always put cycle.index on agent.cycle. Sooner or later you will want a query like "show me only what happened in cycle three."

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦An OpenTelemetry-aligned four-level span structure (agent.run / agent.cycle / agent.plan / agent.tool_call) with Python and TypeScript implementations
✦An eight-class failure_class taxonomy, and a single table that holds retry and notification policy in one place
✦Three dashboard query examples, plus a storage design that keeps raw I/O and PII out of the trace itself
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◈ Agents & Manager2026-09-06
With scheduled agents, I now look for runs that never happened before I look for failures
My run ledger showed a 100% success rate while the evening slot had not fired for two weeks. Here is the reconciliation I now run against an expected-fire table, with measured notes on cron expansion, exit codes, and how the ledger itself gets written.
◈ Agents & Manager2026-10-22
17 Dead References in My Handover Docs Turned Out to Be 2 Files, and the Real Risk Was a Different Site's Playbook Mixed In
The full Python script I use to check the root .md files an agent reads. My naive version counted 17 dead references; fixed, it was 7 across 2 files. Then it missed the real problem. Here is how I found it.
◈ Agents & Manager2026-10-16
Before Handing an Agent a .zip: Dropping .git Cut 29 MB to 15 MB, and 28 Secret Warnings Turned Out to Be Noise
Antigravity app v2.23.0 lets you attach a .zip. I packed my own repository to count what .git weighs and how many secret-scan warnings are false alarms, and I leave the full Python script that excludes, scans, and writes a manifest.