llm

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package llm is the public LLM boundary of the SDD framework (20260830-234501-d-cpt-q6n): pure vocabulary plus one one-method interface. No dependencies, no I/O, no machinery — routing, observation, and timeouts compose around Runner instances at each host's composition site.

The guiding analogy is net/http: Runner is our RoundTripper. Attribution is response-carried (Result.Identity) rather than a method on the interface, because implementations may route.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Identity Identity
	Err      error
}

Error optionally attributes a failed call. An implementation that knows what it routed to wraps its error so failures measure like successes.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Identity

type Identity struct {
	Provider string
	Model    string
	// Variant is the behaviour-affecting configuration the model ran under —
	// a reasoning effort, a thinking budget — carried so calls at different
	// settings measure apart. Canonical form is comma-separated key=value in
	// sorted key order ("reasoning_effort=high"); empty at model defaults.
	//
	// The boundary is what the request carries, not what the setting means:
	// a value sent as its own field is a variant, a value inside the model
	// identifier is the model.
	Variant string
}

Identity names what served a call, reported per call on Result. It is never a static property of an implementation, because implementations may route.

func (Identity) String

func (i Identity) String() string

String renders the identity for display: model, then variant in parentheses.

type Purpose

type Purpose string

Purpose names what a call is for: a routing key for implementations and an observability dimension, the same value for both so they cannot drift. The set is closed: purposes are minted only by application operations. Hosts route on these constants and never invent values.

const (
	PurposePreflight    Purpose = "preflight"
	PurposeSummarize    Purpose = "summarize"
	PurposeWritingGuide Purpose = "writing-guide"
)

type Request

type Request struct {
	Purpose Purpose
	// SystemPrompt is the stable prefix, cacheable by providers that can.
	SystemPrompt string
	// UserPrompt is the per-call variable part.
	UserPrompt string
}

Request carries everything an implementation may route on: ctx (who) and Purpose (what for), plus the two-part prompt.

func (Request) Combined

func (r Request) Combined() string

Combined returns SystemPrompt followed by UserPrompt separated by a blank line when both are non-empty. Runners without native system-prompt support use this to flatten the Request into a single payload.

type Result

type Result struct {
	Text string
	// Identity is required on success: what actually served this call.
	Identity Identity
	Usage    Usage
}

Result reports what a call produced and what served it.

type Runner

type Runner interface {
	Run(ctx context.Context, req Request) (Result, error)
}

Runner is the single port. Contract, stated RoundTripper-style: fill Result.Identity on success; report Usage, never invent it; no internal retries (retry is caller policy); bound your own calls, because deadlines are configuration and configuration is host-private; ctx carries request-scoped facts a routing implementation may use (tenant, logger).

type RunnerFunc

type RunnerFunc func(context.Context, Request) (Result, error)

RunnerFunc adapts a function to Runner (test doubles, error stubs).

func (RunnerFunc) Run

func (f RunnerFunc) Run(ctx context.Context, req Request) (Result, error)

type Usage

type Usage struct {
	InputTokens       int
	OutputTokens      int
	CacheReadTokens   int
	CacheCreateTokens int
	CostUSD           float64
}

Usage is the common format for provider-reported consumption. A field the provider does not report stays zero: reported, never reconstructed.

Jump to

Keyboard shortcuts

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