callrecord

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

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

Overview

Package callrecord encodes model call evidence and rebuilds exact requests. Stores retain opaque bodies; this package owns their deterministic JSON v2 format.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestMismatch means the rebuilt request differs from the recorded request.
	ErrRequestMismatch = errors.New("callrecord request rebuild mismatch")
)

Functions

func BuildRequest

func BuildRequest(ctx context.Context, store runstore.Store, scope string, req *model.Request, ref index.ViewRef, view []*model.Message) (RequestParts, MessageBytes, error)

BuildRequest stores content, encodes spans against the pre-policy view, and verifies the rebuild. Unstable messages and a mismatching rebuild use hashes.

func DecodeMessage

func DecodeMessage(data []byte) (*model.Message, error)

DecodeMessage restores a recorded message while preserving exact dynamic numeric tokens.

func DecodeRequest

func DecodeRequest(data []byte) (*model.Request, error)

DecodeRequest restores an exported request without a store or view renderer. Dynamic message and schema values retain exact numeric tokens, including integers above 2^53. This is the decoder for self-contained RunRecord exports.

func DecodeResponse

func DecodeResponse(data []byte) (*model.Response, error)

DecodeResponse restores recorded response content through the exact message decoder. Dynamic metadata and tool inputs retain numeric precision, and tool call payloads retain their original bytes. A JSON null response returns nil.

func Encode

func Encode(value any) ([]byte, error)

Encode returns deterministic JSON v2, preserving numeric tokens and durations. Reordering raw objects also sorts maps emitted by Message.MarshalJSON.

func Rebuild

func Rebuild(ctx context.Context, store runstore.Store, scope string, started Started, load ViewLoader) (*model.Request, error)

Rebuild resolves all parts and verifies the full exported request encoding. The unexported completion validator is intentionally outside this format.

func RequestDigest

func RequestDigest(req *model.Request) (runstore.Hash, error)

RequestDigest computes the verification-only hash of the canonical request. The complete encoding is never stored as addressed content.

func SnapshotMessages

func SnapshotMessages(messages []*model.Message) ([]*model.Message, error)

SnapshotMessages owns the exact encoded view before history policy can mutate it. It preserves dynamic numeric tokens without imposing model-request bounds on a view from which the planner may select only a small subset.

Types

type ActivityKind

type ActivityKind string

ActivityKind identifies the activity that owns a model call.

const (
	// ActivityPlanner identifies planner calls, including auxiliary calls.
	ActivityPlanner ActivityKind = "planner"
	// ActivitySummarize reserves the summarizer activity kind for K15.
	ActivitySummarize ActivityKind = "summarize"
)

type CallError

type CallError struct {
	Kind    string `json:"kind"`
	Message string `json:"message"`
}

CallError preserves the failure classification and diagnostic message.

type Completion

type Completion struct {
	Response *runstore.Hash               `json:"response"`
	Error    *CallError                   `json:"error"`
	Usage    model.TokenUsage             `json:"usage"`
	Latency  time.Duration                `json:"latency"`
	Facts    *contextmeasure.RequestFacts `json:"facts"`
}

Completion is the terminal outcome, written after storing any response.

func DecodeCompletion

func DecodeCompletion(data []byte) (Completion, error)

DecodeCompletion restores a completion body, including nanosecond latency.

type MessageBytes

type MessageBytes struct {
	Inside  int `json:"inside"`
	Outside int `json:"outside"`
}

MessageBytes measures encoded request messages inside and outside the view. Counts include repetitions; a hash segment contributes outside bytes.

type MessageSegment

type MessageSegment struct {
	ViewFrom int           `json:"view_from,omitzero"`
	ViewTo   int           `json:"view_to,omitzero"`
	Hash     runstore.Hash `json:"hash,omitzero"`
}

MessageSegment is either a zero-based half-open view span or one message hash. A nonempty Hash requires both positions to be zero.

type Params

type Params struct {
	RunID            string                  `json:"run_id"`
	Temperature      float32                 `json:"temperature"`
	ToolChoice       *model.ToolChoice       `json:"tool_choice"`
	MaxTokens        int                     `json:"max_tokens"`
	StructuredOutput *model.StructuredOutput `json:"structured_output"`
	Stream           bool                    `json:"stream"`
	Thinking         *model.ThinkingOptions  `json:"thinking"`
	Cache            *model.CacheOptions     `json:"cache"`
}

Params contains every request field outside messages, tools and provenance.

type RequestParts

type RequestParts struct {
	System   runstore.Hash    `json:"system"`
	Tools    runstore.Hash    `json:"tools"`
	View     *index.ViewRef   `json:"view"`
	Messages []MessageSegment `json:"messages"`
	Params   runstore.Hash    `json:"params"`
	// Request is the canonical verification digest, not stored content.
	Request runstore.Hash `json:"request"`
}

RequestParts names the request content and its ordered message segments. View is the committed reference used by spans, or nil when no spans exist.

type Started

type Started struct {
	Key      runstore.CallKey   `json:"key"`
	Activity ActivityKind       `json:"activity"`
	TurnID   string             `json:"turn_id"`
	Step     int                `json:"step"`
	Request  RequestParts       `json:"request"`
	Started  time.Time          `json:"started"`
	Model    string             `json:"model"`
	ModelID  string             `json:"model_id"`
	Class    model.ModelClass   `json:"class"`
	Context  string             `json:"context"`
	Prompts  []prompt.PromptRef `json:"prompts"`
}

Started is the immutable request and identity written before sending. Step is the planner step; TurnID remains the conversational turn.

func DecodeStarted

func DecodeStarted(data []byte) (Started, error)

DecodeStarted restores a started body using the codec's duration options.

type ViewLoader

type ViewLoader func(context.Context, index.ViewRef) ([]*model.Message, error)

ViewLoader resolves the recorded ViewRef, never the run's current view.

Jump to

Keyboard shortcuts

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