Documentation
¶
Overview ¶
Package llm defines the export format for model-call telemetry. It contains no provider wrappers or agent plugins.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecordBatch ¶
RecordBatch exports the model-attempt events recorded by AgentCore.
func TraceIDFrom ¶
TraceIDFrom reads the correlation id set by WithTraceID ("" when absent, e.g. a classifier call made outside any run).
Types ¶
type FileSink ¶
type FileSink struct {
// contains filtered or unexported fields
}
FileSink appends one JSON object per line (JSONL) to an open file. Safe for concurrent runs. Close it when the process shuts down.
func NewFileSink ¶
NewFileSink opens (creating/appending) a JSONL trace file at path.
func (*FileSink) Record ¶
func (s *FileSink) Record(r TraceRecord)
Record writes one JSONL line. Encoding/IO errors are dropped — tracing must never break a run.
type MultiSink ¶
type MultiSink []Sink
MultiSink fans one record out to several sinks (e.g. file + stdout).
func (MultiSink) Record ¶
func (m MultiSink) Record(r TraceRecord)
type Sink ¶
type Sink interface {
Record(TraceRecord)
}
Sink receives a TraceRecord per LLM call. Implementations fan out to a file, stdout, or an analytics store. It never computes or changes usage.
type SinkFunc ¶
type SinkFunc func(TraceRecord)
SinkFunc adapts a function to a Sink.
func (SinkFunc) Record ¶
func (f SinkFunc) Record(r TraceRecord)
type TraceRecord ¶
type TraceRecord struct {
// NativeTrace holds the authoritative native request, response, and spans.
// Messages and Response remain a display projection for legacy consumers.
NativeTrace json.RawMessage `json:"native_trace,omitempty"`
TraceID string `json:"trace_id,omitempty"` // correlation id (the run id), set via WithTraceID
// SessionKey identifies WHICH agent made the call — the run's own session,
// or a spawned child's derived session. A parent and its children share one
// provider and one ctx chain, so without this their calls are one
// undifferentiated stream. Empty outside a durable run.
SessionKey string `json:"session_key,omitempty"`
// Depth is the delegation depth of the caller: 0 for the top-level run.
Depth int `json:"depth,omitempty"`
Timestamp time.Time `json:"timestamp"`
Provider string `json:"provider"`
Model string `json:"model"`
Messages []protocol.Message `json:"messages"` // the request sent to the model
Tools []string `json:"tools,omitempty"` // tool names advertised this turn
Response string `json:"response,omitempty"` // assistant text returned
// ReasoningBlocks carries opaque provider replay state (for example,
// Anthropic signed thinking). It is recorded separately from Response so it
// can be replayed without ever rendering it as user-visible assistant text.
ReasoningBlocks []protocol.ReasoningBlock `json:"reasoning_blocks,omitempty"`
ToolCalls []protocol.ToolCall `json:"tool_calls,omitempty"` // tool calls the model requested
StopReason string `json:"stop_reason,omitempty"`
Usage protocol.Usage `json:"usage"` // tokens + computed CostUSD
LatencyMS int64 `json:"latency_ms"`
Streamed bool `json:"streamed"`
Err string `json:"error,omitempty"`
}
TraceRecord is one observed LLM call: what was sent, what came back, what it cost, and how long it took. It is the durable, debuggable unit behind an agent run — the "message sent to the LLM + est. fee" trace. Emitted once per Chat or streamed turn.
func ParseNative ¶
func ParseNative(raw json.RawMessage, meta Metadata) (TraceRecord, error)
ParseNative projects native telemetry for storage/display. NativeTrace keeps the original request and response; projections must never restore history.