trace

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRecordingLLM

func NewRecordingLLM(inner cogito.LLM, rec *Recorder, model, agentID string) cogito.LLM

NewRecordingLLM wraps inner so each LLM call is appended to rec. model labels the records (cogito builds requests without a model; the underlying client fills it in), and agentID tags the source ("" for the main session).

Types

type Record

type Record struct {
	Timestamp time.Time                      `json:"timestamp"`
	Provider  string                         `json:"provider"` // always "openai"
	Model     string                         `json:"model"`
	AgentID   string                         `json:"agent_id,omitempty"` // "" = main session
	Method    string                         `json:"method"`             // chat_completion | ask | stream
	Request   *openai.ChatCompletionRequest  `json:"request"`
	Response  *openai.ChatCompletionResponse `json:"response,omitempty"` // omitted on error
	Error     string                         `json:"error,omitempty"`
}

Record is one captured LLM call, serialized as a single NDJSON line. The first five fields mirror voro/claudemaster's trace.Call so the transcript is directly consumable by its export pipeline; Request/Response are go-openai types and therefore already in the OpenAI-chat shape that pipeline targets.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder appends LLM call records to <dir>/trace.ndjson. It is safe for concurrent use: each Record call is serialized under a mutex so lines never interleave. One unbuffered write syscall per record means a process crash leaves a valid prefix of complete lines.

func NewRecorder

func NewRecorder(dir string) (*Recorder, error)

NewRecorder creates dir if needed and opens the transcript for appending.

func (*Recorder) Close

func (r *Recorder) Close() error

Close closes the underlying file. Safe to call on a nil Recorder (tracing disabled).

func (*Recorder) Record

func (r *Recorder) Record(rec Record) error

Record marshals rec to a single JSON line and appends it, defaulting the timestamp and provider when the caller left them unset.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL