Documentation
¶
Overview ¶
Package llama is the graduated local coding-node runtime: a persistent, workspace-scoped inference session that keeps a stable prefix's KV hot and re-prefills only the changed suffix (the live warm-reuse hot path), distinct from the toy fixed-constant `local` provider.
This package defines the backend-neutral session contract. The native adapter (the CGO llama.cpp session) now lives behind the modeld boundary and implements runtime/transport; no backend is registered in this build, so SessionAvailable reports false and the provider returns "unavailable". Product code talks to Session, never to llama.cpp or OpenVINO concepts. The hot coding loop is EnsurePrefix -> PrefillSuffix -> Decode on a live session.
Index ¶
- Variables
- func EmbedAvailable() bool
- func HashTokenIDs(tokens []int) string
- func NewContextOverflowError(stage string, resident, additional, numCtx int) error
- func NewManifestMismatchError(reason string) error
- func NewProviderForTarget(name, modelDir string, caps modelrepo.CapabilityConfig, ...) modelrepo.Provider
- func NewUnsupportedFeatureError(feature string) error
- func SessionAvailable() bool
- func SetEmbedFunc(f EmbedFunc)
- func SetSessionFactory(f SessionFactory)
- type AdapterSpec
- type Config
- type ContextManifest
- type ContextOverflowError
- type ContextReport
- type DecodeConfig
- type EmbedFunc
- type ManifestMismatchError
- type ManifestSegment
- type PrefixInput
- type PrefixStatus
- type Session
- type SessionFactory
- type SessionSnapshot
- type StreamChunk
- type SuffixInput
- type SuffixStatus
- type TokenizeFunc
- type ToolCall
- type UnsupportedFeatureError
Constants ¶
This section is empty.
Variables ¶
var ( // this binary. ErrSessionUnavailable = errors.New("llama: session backend unavailable") // ErrSessionClosed means the caller used a closed persistent session. ErrSessionClosed = errors.New("llama: session closed") // ErrContextOverflow means a prefix, suffix, or decode would exceed NumCtx. ErrContextOverflow = errors.New("llama: context overflow") // ErrUnsupportedFeature marks explicit product-surface gaps such as tools. ErrUnsupportedFeature = errors.New("llama: unsupported feature") // ErrSessionFatal means the backend marked the session unusable and callers // must evict it instead of trying to reuse resident KV. ErrSessionFatal = errors.New("llama: session fatal") )
var ErrManifestMismatch = contextasm.ErrManifestMismatch
Functions ¶
func EmbedAvailable ¶
func EmbedAvailable() bool
EmbedAvailable reports whether llama embeddings can be served: either a native embedding backend is registered (tests / CGO builds), or the modeld daemon serves the llama backend. It mirrors SessionAvailable so embeddings advertise the same way chat does — using modeldconn.ServeableBackend so a brief lease gap during a daemon restart does not momentarily drop the capability.
func HashTokenIDs ¶
func NewContextOverflowError ¶
func NewProviderForTarget ¶ added in v0.34.0
func NewProviderForTarget(name, modelDir string, caps modelrepo.CapabilityConfig, target modeldconn.ModeldTarget) modelrepo.Provider
NewProviderForTarget is used when constructing providers backed by a specific (possibly remote) modeld node. modelDir may be empty (remote resolves by name/digest).
func SessionAvailable ¶
func SessionAvailable() bool
SessionAvailable reports whether local llama inference can be served: either a test factory is registered, or the modeld daemon serves the llama backend. It uses modeldconn.ServeableBackend (not the strict Backend) so a brief lease gap during a daemon restart does not momentarily drop llama models from capability advertisement / the model picker. A daemon running in a different mode (e.g. openvino) advertises no llama capability. The actual open confirms reachability.
func SetEmbedFunc ¶
func SetEmbedFunc(f EmbedFunc)
SetEmbedFunc registers the native embedding backend.
func SetSessionFactory ¶
func SetSessionFactory(f SessionFactory)
SetSessionFactory registers the backend that creates sessions. The native CGO adapter has moved behind the modeld boundary; nothing registers a factory in this build, so the indirection stays but SessionAvailable reports false.
Types ¶
type AdapterSpec ¶ added in v0.32.8
type AdapterSpec = transport.AdapterSpec
AdapterSpec is one LoRA adapter applied to a session. Its digest and scale are part of the session/manifest cache identity: base+A and base+B must not share warm KV (see docs/development/blueprints/modeld/lora-adapters.md).
type Config ¶
Config is the explicit runtime configuration for a local session — every knob is a tested setting, not a magic default.
type ContextManifest ¶
type ContextManifest = contextasm.ContextManifest
type ContextOverflowError ¶
type ContextOverflowError struct {
Stage string
ResidentTokens int
AdditionalTokens int
NumCtx int
}
ContextOverflowError carries token counts for an overflow at a specific primitive boundary.
func (*ContextOverflowError) Error ¶
func (e *ContextOverflowError) Error() string
func (*ContextOverflowError) Is ¶
func (e *ContextOverflowError) Is(target error) bool
func (*ContextOverflowError) OverflowDetail ¶ added in v0.33.0
func (e *ContextOverflowError) OverflowDetail() transport.ContextOverflowDetail
type ContextReport ¶
type ContextReport = transport.ContextReport
ContextReport explains the session's resident context (explain-context). It aliases the transport wire type for the same anti-drift reason as the inputs above.
type DecodeConfig ¶
type DecodeConfig struct {
MaxTokens int
Temperature *float64
TopP *float64
TopK int
Seed *int
ParserProtocols []string
ReasoningFormat string
StructuredOutput transport.StructuredOutputConfig
}
DecodeConfig controls a single decode pass.
type EmbedFunc ¶
type EmbedFunc func(ctx context.Context, modelPath string, cfg Config, input string) ([]float64, error)
EmbedFunc computes a single embedding via the native backend. The llama.cpp adapter registers one from its init when built with the 'llamanode' tag.
type ManifestMismatchError ¶
type ManifestMismatchError = contextasm.ManifestMismatchError
type ManifestSegment ¶
type ManifestSegment = contextasm.ManifestSegment
type PrefixInput ¶
type PrefixInput = transport.PrefixInput
PrefixInput is the stable prefix text plus the manifest that makes reuse valid (tokenizer, template, runtime config, BOS policy, and model identity are part of the cache key — byte equality alone is not enough).
type PrefixStatus ¶
type PrefixStatus = transport.PrefixStatus
PrefixStatus reports what EnsurePrefix reused versus (re)computed — the live-reuse signal: ReusedTokens > 0 means a warm hit.
type Session ¶
type Session interface {
// EnsurePrefix makes the resident KV equal `prefix`, reusing the longest
// already-resident matching token prefix and prefilling only the divergent
// tail (this also drops any previous suffix and generated tokens).
EnsurePrefix(ctx context.Context, prefix PrefixInput) (PrefixStatus, error)
// PrefillSuffix prefills the volatile suffix (diff / test output / user turn)
// after the stable prefix, leaving the stable KV untouched.
PrefillSuffix(ctx context.Context, suffix SuffixInput) (SuffixStatus, error)
// Decode streams generated text from the current resident state.
Decode(ctx context.Context, cfg DecodeConfig) (<-chan StreamChunk, error)
// ExplainContext reports the resident context for observability.
ExplainContext() ContextReport
// Snapshot captures backend state for durability, branching, and benchmark
// reproducibility.
Snapshot(ctx context.Context) (SessionSnapshot, error)
// Restore replaces resident state from a compatible snapshot.
Restore(ctx context.Context, snap SessionSnapshot) error
// Close releases the session's resources.
Close() error
}
Session is a persistent, workspace-scoped inference session.
The hot coding loop is: keep the stable prefix's KV hot, prefill only the changed suffix, decode. EnsurePrefix does token-level longest-common-prefix reuse, so an unchanged stable workspace context stays warm across turns and only the divergent tail is recomputed.
type SessionFactory ¶
SessionFactory creates a backend session for a model with explicit config.
type SessionSnapshot ¶ added in v0.32.4
type SessionSnapshot = transport.SessionSnapshot
type StreamChunk ¶
StreamChunk is a decoded text delta, parsed model output, or a terminal error.
type SuffixInput ¶
type SuffixInput = transport.SuffixInput
SuffixInput is the volatile text appended after the stable prefix, carrying the same manifest so a suffix cannot be prefilled against resident KV from a different profile/template/runtime.
type SuffixStatus ¶
type SuffixStatus = transport.SuffixStatus
SuffixStatus reports the volatile suffix added after the stable prefix.
type TokenizeFunc ¶
type TokenizeFunc = contextasm.TokenizeFunc
type UnsupportedFeatureError ¶
type UnsupportedFeatureError struct {
Feature string
}
UnsupportedFeatureError describes a deliberately unsupported surface.
func (*UnsupportedFeatureError) Error ¶
func (e *UnsupportedFeatureError) Error() string
func (*UnsupportedFeatureError) Is ¶
func (e *UnsupportedFeatureError) Is(target error) bool