inference

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 33 Imported by: 0 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 inference owns provider validation, credential shapes, and runtime rendering for the tenant inference plane.

Index

Constants

View Source
const (

	// SandboxByProviderIndex indexes Sandboxes by referenced provider ID.
	SandboxByProviderIndex = "spec.inference.models.provider"
	// SandboxByProviderModelIndex indexes Sandboxes by provider and model ID.
	SandboxByProviderModelIndex = "spec.inference.models.providerModel"
)
View Source
const (
	// PoolLabel identifies resources owned by an InferencePool.
	PoolLabel = "agentz.accuknox.com/inference-pool"
	// PoolByProviderIndex indexes Pools by referenced provider ID.
	PoolByProviderIndex = "spec.members.provider"
	// SandboxByPoolIndex indexes Sandboxes by referenced Pool ID.
	SandboxByPoolIndex = "spec.inference.models.pool"
)
View Source
const (
	// ProviderLabel identifies resources owned by an InferenceProvider.
	ProviderLabel = "agentz.accuknox.com/inference-provider"
	// ProviderKindLabel identifies the provider implementation of a resource.
	ProviderKindLabel = "agentz.accuknox.com/inference-provider-kind"

	// SubscriptionCredentialPathDir isolates subscription tokens from API-key
	// credentials so extAuth can receive the narrowest possible OpenBao policy.
	SubscriptionCredentialPathDir = "inference-subscriptions"
	// OpenAICodexClientID is OpenAI's public Codex OAuth client identifier.
	OpenAICodexClientID = "app_EMoamEEZ73f0CkXaXp7hrann"
	// OpenAICodexTokenEndpoint exchanges and refreshes Codex tokens.
	OpenAICodexTokenEndpoint = "https://auth.openai.com/oauth/token"
	// OpenAICodexModelsEndpoint serves the authenticated Codex model catalog.
	OpenAICodexModelsEndpoint = "https://chatgpt.com/backend-api/codex/models"
)
View Source
const (
	// GatewayName is the namespace-local inference Gateway and Service name.
	GatewayName = "inference"
	// ParametersName configures only the inference Gateway deployment.
	ParametersName = "inference-clusterip"
	// SandboxLabel identifies the Sandbox that owns an inference route.
	SandboxLabel = "agentz.accuknox.com/inference-sandbox"
	// SandboxHeader carries controller-owned route identity to extAuth.
	SandboxHeader = "x-agentz-inference-sandbox"
	// SandboxNamespaceHeader binds the route to its source Workspace.
	SandboxNamespaceHeader = "x-agentz-inference-sandbox-namespace"
)

Variables

This section is empty.

Functions

func AgentRoutePath added in v0.31.0

func AgentRoutePath(namespace, name, path string) string

AgentRoutePath binds an inference target to the caller's workspace and agent. The gateway network policy permits each agent to use only its own prefix.

func CredentialPath

func CredentialPath(namespace, name string, kind agentzv1alpha1.InferenceProviderKind) string

CredentialPath returns the OpenBao path for one provider's credential kind.

func CredentialsForCreate

func CredentialsForCreate(spec agentzv1alpha1.InferenceProviderSpec, values CredentialValues) (map[string]any, error)

CredentialsForCreate validates and returns the complete OpenBao record for a newly created provider. A nil record means credentials are not required.

func CredentialsForUpdate

func CredentialsForUpdate(spec agentzv1alpha1.InferenceProviderSpec, values CredentialValues) (map[string]any, bool, error)

CredentialsForUpdate validates complete replacement semantics. A nil record and false changed result means the stored record must remain untouched.

func DelegatedProviderEndpoints added in v0.29.0

func DelegatedProviderEndpoints(kind agentzv1alpha1.InferenceProviderKind) []string

DelegatedProviderEndpoints returns the client APIs that Agentgateway can translate to the provider's configured format. Routes alone do not establish support: Responses cannot be translated to Anthropic Messages or Gemini.

func Gateway

func Gateway(namespace string) *gwv1.Gateway

Gateway returns the isolated namespace-local inference Gateway.

func IndexPools

func IndexPools(ctx context.Context, idx client.FieldIndexer) error

IndexPools registers Pool/provider and Sandbox/Pool reference indexes.

func IndexSandboxes

func IndexSandboxes(ctx context.Context, idx client.FieldIndexer) error

IndexSandboxes registers provider and provider/model reference indexes.

func PoolProviderSecretName

func PoolProviderSecretName(pool, provider string) string

PoolProviderSecretName returns the Pool-local credential projection name for an inherited Organisation provider.

func ProviderAPI

ProviderAPI returns the native request format used by a provider model.

func ProviderProtocol

ProviderProtocol returns the request family used by a provider kind.

func RenderInferenceAuthPolicy

func RenderInferenceAuthPolicy(namespace, backend string, section *gwv1.SectionName, provider, pool string) *agentgatewayv1alpha1.AgentgatewayPolicy

RenderInferenceAuthPolicy applies fail-closed target authorization and credential injection to a direct provider or one named Pool member.

func RenderPoolBackend

RenderPoolBackend composes one ordered AgentGateway priority group per Pool member. Passive eviction changes only subsequent request selection.

func ResolvePool

func ResolvePool(ctx context.Context, reader client.Reader, pool *agentzv1alpha1.InferencePool) (PoolDefinition, []Issue, error)

ResolvePool validates references and derives the conservative Pool contract.

func SandboxPoolPath

func SandboxPoolPath(sandboxName, poolName string) string

SandboxPoolPath returns the controller-owned prefix for one Sandbox/Pool pair.

func SandboxProviderPath

func SandboxProviderPath(sandboxName, providerName string) string

SandboxProviderPath returns the controller-owned OpenAI-compatible prefix for one Sandbox/provider pair.

func SandboxProviderRuntimeName

func SandboxProviderRuntimeName(sandboxName, providerName string) string

SandboxProviderRuntimeName returns the bounded stable identity shared by a route and its authorization policy.

func SubscriptionRecordData

func SubscriptionRecordData(record SubscriptionRecord) (map[string]any, error)

SubscriptionRecordData encodes a typed subscription record for OpenBao.

func SupportsPoolAPI

func SupportsPoolAPI(poolAPI, memberAPI agentzv1alpha1.InferenceModelAPI) bool

SupportsPoolAPI reports whether AgentGateway can translate the Pool request format to a member's native format.

Types

type Catalog

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

Catalog fetches and retains a parsed Models.dev projection.

func NewCatalog

func NewCatalog(client *http.Client) *Catalog

NewCatalog creates a bounded Models.dev catalog client. A nil client uses a five-second HTTP timeout.

func (*Catalog) Entries

func (c *Catalog) Entries(query string) (string, []CatalogEntry)

Entries returns the pinned supported catalog variants matching query.

func (*Catalog) SubscriptionModels

SubscriptionModels returns models available to one authenticated subscription. Provider endpoints determine entitlement; Models.dev only supplies capability metadata that subscription endpoints omit.

func (*Catalog) Suggestions

Suggestions returns models for one pinned provider/runtime variant and reports whether they came from the live response, cache, or snapshot.

type CatalogEntry

type CatalogEntry struct {
	ProviderID      string
	Name            string
	Kind            agentzv1alpha1.InferenceProviderKind
	BaseURL         string
	BaseURLTemplate string
	AuthHeader      string
	AuthPrefix      string
	Doc             string
}

CatalogEntry is one selectable provider and configuration kind.

type CatalogProvenance

type CatalogProvenance string

CatalogProvenance identifies the source of model suggestions.

const (
	// CatalogProvenanceLive identifies a successful Models.dev response.
	CatalogProvenanceLive CatalogProvenance = "live"
	// CatalogProvenanceCache identifies the last successful parsed response.
	CatalogProvenanceCache CatalogProvenance = "cache"
	// CatalogProvenanceSnapshot identifies the reviewed embedded fallback.
	CatalogProvenanceSnapshot CatalogProvenance = "snapshot"
)

type CredentialValues

type CredentialValues struct {
	APIKey             string
	BearerToken        string
	ServiceAccountJSON string
	AccessKey          string
	SecretKey          string
	SessionToken       string
	ClientID           string
	TenantID           string
	ClientSecret       string
}

CredentialValues is the complete typed write-only credential input surface.

type DelegatedRequest added in v0.29.0

type DelegatedRequest struct {
	Model              string               `json:"model"`
	Stream             bool                 `json:"stream"`
	Store              *bool                `json:"store"`
	Background         bool                 `json:"background"`
	PreviousResponseID string               `json:"previous_response_id"`
	Conversation       json.RawMessage      `json:"conversation"`
	Prompt             json.RawMessage      `json:"prompt"`
	WebSearchOptions   json.RawMessage      `json:"web_search_options"`
	Tools              []inferenceTool      `json:"tools"`
	Input              json.RawMessage      `json:"input"`
	Messages           []inferenceInputItem `json:"messages"`
	// contains filtered or unexported fields
}

DelegatedRequest contains validated inference input for a delegated model.

func ValidateDelegatedMessages added in v0.30.0

func ValidateDelegatedMessages(body []byte, countTokens bool) (*DelegatedRequest, error)

ValidateDelegatedMessages admits inline Anthropic input and client-executed tools. A model grant never authorizes provider files, containers or hosted MCP.

func ValidateDelegatedRequest added in v0.29.0

func ValidateDelegatedRequest(body []byte, responses bool) (*DelegatedRequest, error)

ValidateDelegatedRequest validates the resource-bearing portions of the OpenAI request. Case-sensitive decoding matches the upstream contract, while strict duplicate detection prevents two parsers from authorizing different values.

func (*DelegatedRequest) ValidateProvider added in v0.29.0

func (input *DelegatedRequest) ValidateProvider(kind agentzv1alpha1.InferenceProviderKind) error

ValidateProvider checks the selected provider before forwarding a validated request to an upstream whose errors must remain private.

type InputError

type InputError struct {
	Field   string
	Message string
}

InputError reports one invalid write-only credential field without its value.

func (*InputError) Error

func (e *InputError) Error() string

Error returns a safe credential validation error.

type Issue

type Issue struct {
	Field   string
	Message string
}

Issue identifies one invalid provider input field.

func ValidateModelRemoval

func ValidateModelRemoval(ctx context.Context, reader client.Reader, current, desired *agentzv1alpha1.InferenceProvider) ([]Issue, error)

ValidateModelRemoval rejects removal of models referenced by Pools or Sandboxes.

func ValidateProvider

func ValidateProvider(spec agentzv1alpha1.InferenceProviderSpec) []Issue

ValidateProvider defensively validates the provider union and safe endpoint controls before admission or rendering.

type PoolDefinition

PoolDefinition contains the validated, derived Pool configuration consumed by reconciliation, gateway reads, and Agent configuration rendering.

type ProviderTarget

type ProviderTarget struct {
	LLM             agentgatewayv1alpha1.LLMProvider
	Policies        *agentgatewayv1alpha1.BackendWithAI
	AdditionalHosts []string
	// contains filtered or unexported fields
}

ProviderTarget contains one provider's complete member-scoped AgentGateway configuration. Model is empty for direct provider backends and set for Pool members so the logical Pool ID never reaches an upstream.

func RenderProviderTarget

func RenderProviderTarget(provider *agentzv1alpha1.InferenceProvider, model string) (ProviderTarget, error)

RenderProviderTarget converts an admitted provider into one reusable target. The optional model override binds a Pool member to its real upstream model.

type ResolvedPoolMember

ResolvedPoolMember binds one Pool reference to its typed Provider and model.

type Runtime

type Runtime struct {
	ExternalSecret *externalsecretsv1.ExternalSecret
	Backend        *agentgatewayv1alpha1.AgentgatewayBackend
	AuthPolicy     *agentgatewayv1alpha1.AgentgatewayPolicy
	SecretKeys     []string
}

Runtime contains the resources needed to route and authenticate a provider. ExternalSecret is nil for subscription or unauthenticated providers.

func RenderRuntime

func RenderRuntime(provider *agentzv1alpha1.InferenceProvider, storeName string, refresh time.Duration) (Runtime, error)

RenderRuntime converts an admitted provider into its complete runtime resources without reading credential values.

type SandboxTarget

type SandboxTarget struct {
	Name             string
	Backend          string
	BackendNamespace string
	Path             string
	Models           []string
	Labels           map[string]string
	ExtAuth          bool
	Retries          int
}

SandboxTarget describes one logical inference target exposed by a Sandbox.

type SandboxTargetRuntime

type SandboxTargetRuntime struct {
	Route  *gwv1.HTTPRoute
	Policy *agentgatewayv1alpha1.AgentgatewayPolicy
}

SandboxTargetRuntime contains the fail-closed route and authorization policy for one Sandbox inference target.

func RenderSandboxTarget

func RenderSandboxTarget(namespace, sandboxName string, target SandboxTarget, agents []api.Agent) SandboxTargetRuntime

RenderSandboxTarget creates a route and fail-closed logical model policy.

type SubscriptionRecord

type SubscriptionRecord struct {
	Kind      agentzv1alpha1.InferenceProviderKind `json:"kind"`
	AccountID string                               `json:"accountId,omitempty"`
	ClientID  string                               `json:"clientId,omitempty"`
	Token     *oauth2.Token                        `json:"token"`
	Scopes    []string                             `json:"scopes,omitempty"`
	UpdatedAt time.Time                            `json:"updatedAt"`
}

SubscriptionRecord is the complete credential record retained only in OpenBao for a subscription-backed inference provider.

func DecodeSubscriptionRecord

func DecodeSubscriptionRecord(data map[string]any) (SubscriptionRecord, error)

DecodeSubscriptionRecord decodes one controlled OpenBao record strictly.

func RefreshSubscription

func RefreshSubscription(ctx context.Context, client *http.Client, record SubscriptionRecord) (SubscriptionRecord, bool, error)

RefreshSubscription returns a usable subscription record, refreshing Codex credentials when they are inside the shared expiry safety window.

Jump to

Keyboard shortcuts

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