nexus

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package nexus adapts the Nexus LLM gateway to the cortex llm.Client interface.

Every call goes out under a nexus tenant and carries usage metadata: the tenant comes from the context (pipeline.WithTenantID) or from a cortex.TenantFunc over the context's scope, and the metadata names the scope levels and the run and agent the engine put on the request. A call with no tenant is refused before anything is sent.

Index

Constants

This section is empty.

Variables

View Source
var ErrToolCallWithoutID = errors.New("llm: tool-call fragment without an id")

ErrToolCallWithoutID reports a streamed tool-call fragment that names no call and follows no fragment that did, so it cannot be attached to one.

Functions

func EngineOption

func EngineOption(c vessel.Vessel, opts ...Option) engine.Option

EngineOption returns an engine.Option that finds a *nexus.Gateway in the DI container (nexus's Forge extension provides one) and makes an adapter over it, with opts, the engine's LLM client. With no gateway in the container it does nothing, so it is safe to always include.

Types

type Adapter

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

Adapter implements llm.Client by delegating to a nexus gateway's engine.

func New

func New(gw *nexus.Gateway, opts ...Option) *Adapter

New creates an adapter over gw. Calls made before gw.Initialize returns fail with nexus.ErrNotInitialized.

func NewFunc added in v1.10.0

func NewFunc(gw func() *nexus.Gateway, opts ...Option) *Adapter

NewFunc creates an adapter that asks gw for the gateway on every call, for a gateway that does not exist yet when the adapter is built, such as the one a nexus Forge extension creates when it starts. While gw returns nil, calls fail with nexus.ErrNotInitialized.

func (*Adapter) Complete

func (a *Adapter) Complete(ctx context.Context, req *llm.Request) (*llm.Response, error)

Complete sends a synchronous completion request via the Nexus pipeline.

func (*Adapter) CompleteStream

func (a *Adapter) CompleteStream(ctx context.Context, req *llm.Request) (llm.Stream, error)

CompleteStream sends a streaming completion request via the Nexus pipeline.

type Option added in v1.10.0

type Option func(*Adapter)

Option configures an Adapter.

func WithMetadata added in v1.10.0

func WithMetadata(f func(ctx context.Context, s cortex.Scope, md map[string]string) map[string]string) Option

WithMetadata replaces how the adapter builds a call's usage metadata. f gets the context's scope and a copy of the request's Metadata (the run and agent the engine set). The default returns one pair per scope level, level key to value, plus those pairs. Whatever f returns is then cut to nexus's rules: pairs with a key outside ^[A-Za-z0-9_-]{1,64}$ or a value over 256 bytes are dropped, and at most 16 are kept, run and agent first.

func WithProvider added in v1.10.0

func WithProvider(f func(ctx context.Context, s cortex.Scope) string) Option

WithProvider names the nexus provider a call goes to, from the context's scope. An empty result leaves the choice to nexus, which routes by alias and then by the providers that list the model, so a model id two providers share can go to either.

func WithSamplingUnsupported added in v1.10.0

func WithSamplingUnsupported(f func(model string) bool) Option

WithSamplingUnsupported sets which models reject sampling parameters. For those the adapter sends no temperature (and it never sends top_p). The default knows claude-opus-5-5, claude-sonnet-5-5 and claude-haiku-5-5; a host that calls models through nexus aliases passes a predicate that knows what each alias points at.

func WithTenant added in v1.10.0

func WithTenant(f cortex.TenantFunc) Option

WithTenant sets how the adapter names the nexus tenant for a call whose context carries none (pipeline.WithTenantID wins when it is set). The result must be a nexus tenant ID. The default is cortex.RootTenant, the value of the scope's first level, which only works when that value is the nexus tenant ID.

Jump to

Keyboard shortcuts

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