Skip to main content

Observability overview

Three pillars, one entry point.

PillarGives youReference
EventsThe raw stream.Events
LoggingConsole line per event with configurable verbosity, plus pluggable sinks (NDJSON, your own).Log sinks · Logger options
TracingA read-after-run object: spans, token usage, cost, retries, tool calls.Tracing

The fluent setup​

AgentContext exposes two fluent extensions that wire everything for you. Call one, both, or neither — they share the event bus.

var ctx = new AgentContext()
.WithLogging(new LogicGridLoggerOptions { ShowLlmMessages = false })
.WithTracing(out var trace);

var output = await admin.RunAsync(input);

Console.WriteLine($"\nLLM calls : {trace.TotalLlmCalls}");
Console.WriteLine($"Tokens : {trace.TotalTokenUsage.TotalTokens}");
Console.WriteLine($"Cost : ${trace.TotalCost.TotalCostUsd:0.0000}");
Console.WriteLine($"Retries : {trace.TotalRetries}");

WithLogging(options, sinks…) defaults to a single ConsoleSink. Pass JsonSink(file) (or your own ILogSink) for structured logging.

WithTracing(out var trace) creates a fresh AgentRunTrace that adopts run identity from the first event it sees and populates as the run progresses. Read it after RunAsync completes.

Bring your own bus​

If you already have an IAgentEventBus (e.g. you're forwarding events into another telemetry system), set it directly:

var ctx = new AgentContext { EventBus = myBus };
// .WithLogging() / .WithTracing() will reuse it instead of creating a new one

External run correlation​

Pass your platform's request ID as runId and every log line + every span carries it:

var ctx = new AgentContext(
originalTask: "summarise daily report",
runId: HttpContext.TraceIdentifier)
.WithLogging()
.WithTracing(out var trace);

Where next​

  • Events — the full 22-event catalog.
  • Log sinks — Console, NDJSON, custom (e.g. Serilog bridge).
  • Logger options — every flag in LogicGridLoggerOptions.
  • Tracing — AgentRunTrace shape and how to ship it to your APM.
  • Cost & budget — MaxBudgetUsd, BudgetWarningEvent, BudgetExceededException.