recorder

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ThoughtSourceThinking         = "thinking"
	ThoughtSourceReasoningSummary = "reasoning_summary"
	ThoughtSourceCommentary       = "commentary"
)

Model thought source constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncRecorder

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

AsyncRecorder calls Recorder methods asynchronously and logs any errors which may occur.

func NewAsyncRecorder

func NewAsyncRecorder(logger slog.Logger, wrapped Recorder, timeout time.Duration) *AsyncRecorder

func (*AsyncRecorder) RecordInterception

func (a *AsyncRecorder) RecordInterception(ctx context.Context, req *InterceptionRecord) error

RecordInterception must NOT be called asynchronously. If an interception cannot be recorded, the whole request should fail.

func (*AsyncRecorder) RecordInterceptionEnded

func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error

func (*AsyncRecorder) RecordModelThought added in v1.1.0

func (a *AsyncRecorder) RecordModelThought(ctx context.Context, req *ModelThoughtRecord) error

func (*AsyncRecorder) RecordPromptUsage

func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error

func (*AsyncRecorder) RecordTokenUsage

func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error

func (*AsyncRecorder) RecordToolUsage

func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error

func (*AsyncRecorder) Wait

func (a *AsyncRecorder) Wait()

func (*AsyncRecorder) WithClient added in v1.1.0

func (a *AsyncRecorder) WithClient(client string)

func (*AsyncRecorder) WithInitiatorID

func (a *AsyncRecorder) WithInitiatorID(initiatorID string)

func (*AsyncRecorder) WithMetrics

func (a *AsyncRecorder) WithMetrics(m any)

func (*AsyncRecorder) WithModel

func (a *AsyncRecorder) WithModel(model string)

func (*AsyncRecorder) WithProvider

func (a *AsyncRecorder) WithProvider(provider string)

type InterceptionRecord

type InterceptionRecord struct {
	ID                    string
	InitiatorID           string
	Metadata              Metadata
	Model                 string
	Provider              string
	ProviderName          string
	StartedAt             time.Time
	ClientSessionID       *string
	Client                string
	UserAgent             string
	CorrelatingToolCallID *string
}

type InterceptionRecordEnded

type InterceptionRecordEnded struct {
	ID      string
	EndedAt time.Time
}

type Metadata

type Metadata map[string]any

type ModelThoughtRecord added in v1.1.0

type ModelThoughtRecord struct {
	InterceptionID string
	Content        string
	Metadata       Metadata
	CreatedAt      time.Time
}

type PromptUsageRecord

type PromptUsageRecord struct {
	InterceptionID string
	MsgID          string
	Prompt         string
	Metadata       Metadata
	CreatedAt      time.Time
}

type Recorder

type Recorder interface {
	// RecordInterception records metadata about an interception with an upstream AI provider.
	RecordInterception(ctx context.Context, req *InterceptionRecord) error
	// RecordInterceptionEnded records that given interception has completed.
	RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error
	// RecordTokenUsage records the tokens used in an interception with an upstream AI provider.
	RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error
	// RecordPromptUsage records the prompts used in an interception with an upstream AI provider.
	RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error
	// RecordToolUsage records the tools used in an interception with an upstream AI provider.
	RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error
	// RecordModelThought records model thoughts produced in an interception with an upstream AI provider.
	RecordModelThought(ctx context.Context, req *ModelThoughtRecord) error
}

Recorder describes all the possible usage information we need to capture during interactions with AI providers. Additionally, it introduces the concept of an "Interception", which includes information about which provider/model was used and by whom. All usage records should reference this Interception by ID.

type RecorderWrapper

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

RecorderWrapper is a convenience struct which implements RecorderClient and resolves a client before calling each method. It also sets the start/creation time of each record.

func NewRecorder

func NewRecorder(logger slog.Logger, tracer trace.Tracer, clientFn func() (Recorder, error)) *RecorderWrapper

func (*RecorderWrapper) RecordInterception

func (r *RecorderWrapper) RecordInterception(ctx context.Context, req *InterceptionRecord) (outErr error)

func (*RecorderWrapper) RecordInterceptionEnded

func (r *RecorderWrapper) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) (outErr error)

func (*RecorderWrapper) RecordModelThought added in v1.1.0

func (r *RecorderWrapper) RecordModelThought(ctx context.Context, req *ModelThoughtRecord) (outErr error)

func (*RecorderWrapper) RecordPromptUsage

func (r *RecorderWrapper) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) (outErr error)

func (*RecorderWrapper) RecordTokenUsage

func (r *RecorderWrapper) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) (outErr error)

func (*RecorderWrapper) RecordToolUsage

func (r *RecorderWrapper) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) (outErr error)

type TokenUsageRecord

type TokenUsageRecord struct {
	InterceptionID        string
	MsgID                 string
	Input                 int64
	Output                int64
	CacheReadInputTokens  int64
	CacheWriteInputTokens int64
	// ExtraTokenTypes holds token types which *may* exist over and above input/output.
	// These should ultimately get merged into [Metadata], but it's useful to keep these
	// with their actual type (int64) since [Metadata] is a map[string]any.
	ExtraTokenTypes map[string]int64
	Metadata        Metadata
	CreatedAt       time.Time
}

type ToolArgs

type ToolArgs any

type ToolUsageRecord

type ToolUsageRecord struct {
	InterceptionID  string
	MsgID           string
	Tool            string
	ToolCallID      string
	ServerURL       *string
	Args            ToolArgs
	Injected        bool
	InvocationError error
	Metadata        Metadata
	CreatedAt       time.Time
}

Jump to

Keyboard shortcuts

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