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 ¶
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 ¶
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 ¶
New creates an adapter over gw. Calls made before gw.Initialize returns fail with nexus.ErrNotInitialized.
func NewFunc ¶ added in v1.10.0
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.
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
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
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.