Trace Class
Trace Class
Details
Root container for a full agent run. A trace contains multiple spans representing individual operations like LLM calls, tool executions, and guardrail checks.
Public fields
nameName of the trace.
trace_idUnique identifier for the trace.
metadataArbitrary metadata attached to the trace.
statusCurrent status: "running", "completed", or "error".
resourceResource attributes for this trace.
Methods
Method summary()
Print a formatted summary of the trace.
Examples
# Create and use a trace
tr <- Trace$new("my-agent-run", metadata = list(user = "test"))
tr$start()
# Add a span to the trace
span <- Span$new("llm-call", type = "llm")
span$start()
span$set_tokens(input = 100L, output = 50L)
span$end()
tr$add_span(span)
tr$end()
tr$status
#> [1] "completed"
tr$duration()
#> [1] 0.002908945
tr$summary()
#> Trace: my-agent-run (completed) ID: ec1d6ada44bc15ee3f1285a6f4585e9f Duration:
#> 0.00s Spans: 1 Tokens: 100 input, 50 output Cost: $0.000000
# Serialize to list for export
trace_list <- tr$to_list()
trace_list$name
#> [1] "my-agent-run"