agentversion

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package agentversion defines the bounded AgentVersion vocabulary of the Agent OS kernel: the canonical reference grammar, the immutable published spec, and the deterministic digest over that spec. It has no infrastructure dependencies.

An AgentVersion is immutable by contract: a published spec can never be modified, and an upgrade is always the publication of a new version of the same agent name. The database layer enforces this invariant structurally.

Index

Constants

View Source
const (
	APIVersion       = "fenced.dev/v1"
	LegacyAPIVersion = "fenced.dev/v1alpha1"
	Kind             = "AgentVersion"

	MaxNameLength    = 128
	MaxVersionLength = 128
	MaxAttemptsLimit = 10

	// DefaultNamespace is the namespace an AgentVersion reference resolves to
	// when none is written explicitly. Eliding it keeps the historical
	// "name@version" grammar valid byte-for-byte while the namespace becomes a
	// real part of the identity (P1-07): two versions with the same name and
	// version can coexist under one tenant in different namespaces.
	DefaultNamespace = "default"
)
View Source
const (
	// ManifestAPIVersion identifies the frozen GA Agent Manifest contract.
	// LegacyManifestAPIVersion remains readable for the published N-1 window.
	ManifestAPIVersion       = "fenced.dev/v1"
	LegacyManifestAPIVersion = "fenced.dev/v1alpha1"
	ManifestKind             = "AgentManifest"
	// RuntimeInterfaceV1 is the frozen provider-neutral lifecycle boundary.
	RuntimeInterfaceV1 = "fenced.runtime.interface/v1"
	// RuntimeInterfaceV1Alpha1 is accepted only for legacy manifests.
	RuntimeInterfaceV1Alpha1 = "fenced.runtime.interface/v1alpha1"

	CheckpointNone    = "none"
	CheckpointLogical = "logical"
)

Variables

This section is empty.

Functions

func CanonicalizeSpec

func CanonicalizeSpec(raw json.RawMessage) (json.RawMessage, [sha256.Size]byte, error)

CanonicalizeSpec normalizes a raw spec document into its canonical JSON form and returns the deterministic SHA-256 digest that identifies the immutable publication. Numbers are preserved through json.Number so that integer budgets are not rewritten as floats.

func FormatRef

func FormatRef(namespace, name, version string) string

FormatRef renders the canonical reference for an identity. The default namespace is elided so historical "name@version" references remain byte-identical; any other namespace is written as the full "namespace/name@version" identity.

func ParseRef

func ParseRef(ref string) (namespace, name, version string, err error)

ParseRef splits the canonical "[namespace/]name@version" reference. A reference with no namespace segment resolves to DefaultNamespace, so every historical "name@version" reference keeps its exact meaning. The reference must contain exactly one '@'; the namespace (when written), name and version must all be valid tokens.

func ValidateName

func ValidateName(name string) error

ValidateName rejects names that are not canonical agent-name tokens.

func ValidateNamespace

func ValidateNamespace(namespace string) error

ValidateNamespace rejects namespaces that are not canonical tokens. The namespace is part of the AgentVersion identity and rides in the reference grammar ahead of the '/' separator, so it must be free of both the '/' and '@' separators — the token grammar already excludes them.

func ValidateSpec

func ValidateSpec(raw json.RawMessage) error

ValidateSpec checks the bounded fields that kernel stages consume. Unknown fields are ignored so that later spec stages can evolve without a breaking change. Failures mean the publication must be rejected.

func ValidateVersion

func ValidateVersion(version string) error

ValidateVersion rejects versions that are not canonical version tokens.

Types

type Budget

type Budget struct {
	Tokens       int64          `json:"tokens"`
	CostMicroUSD money.MicroUSD `json:"costUsd"`
	ToolCalls    int64          `json:"toolCalls"`
	WallSeconds  int64          `json:"wallSeconds"`
}

type Capabilities

type Capabilities struct {
	Tools []string `json:"tools"`
	// ToolVersions is the derived version vocabulary of the tool grants:
	// pinned ("echo.dev@1.0.0") and floating ("echo.dev@*") grants. The
	// kernel derives it from the published tool grants, so a runtime
	// capability check compares bare tool names while the publish-time
	// tool freeze still sees the pinned version. It is not author input.
	ToolVersions        []string `json:"toolVersions,omitempty"`
	Models              []string `json:"models"`
	Memory              []string `json:"memory"`
	MemorySensitivities []string `json:"memorySensitivities,omitempty"`
	Secrets             []string `json:"secrets"`
	SpawnTasks          bool     `json:"spawnTasks,omitempty"`
	ChildAgents         []string `json:"childAgents,omitempty"`
	// Peers lists the AgentVersion references this version may send IPC
	// messages to, in agentversion.FormatRef form. Empty denies every peer.
	// It constrains only the sender: the receiving run does not have to
	// declare who may write to it, so knowing a run id is enough to reach it.
	Peers []string `json:"peers,omitempty"`
}

Capabilities contains symbolic permission identifiers. Empty arrays are an explicit default-deny declaration and are different from an omitted block.

type CheckpointPolicy

type CheckpointPolicy struct {
	Mode            string `json:"mode"`
	SchemaVersion   string `json:"schemaVersion,omitempty"`
	IntervalSeconds int64  `json:"intervalSeconds,omitempty"`
}

type Image

type Image struct {
	Ref    string `json:"ref"`
	Digest string `json:"digest,omitempty"`
}

Image is the version-level image pin; it mirrors workload.Image so the kernel package graph stays acyclic.

type Lifecycle

type Lifecycle struct {
	MaxAttempts int `json:"maxAttempts,omitempty"`
}

type Manifest

type Manifest struct {
	APIVersion string   `json:"apiVersion"`
	Kind       string   `json:"kind"`
	Metadata   Metadata `json:"metadata"`
	Spec       Spec     `json:"spec"`
}

Manifest is the strict, portable v0.9 Agent declaration consumed by SDKs, CLI tooling and Registry publication. Tenant identity is intentionally not embedded: it comes from the authenticated control-plane principal.

func DecodeManifest

func DecodeManifest(raw []byte) (Manifest, json.RawMessage, [sha256.Size]byte, error)

DecodeManifest rejects ambiguous or forward-unknown documents, validates the full developer contract, and returns deterministic canonical JSON and its SHA-256 identity.

func (*Manifest) NormalizeLegacyIdentifiers

func (m *Manifest) NormalizeLegacyIdentifiers()

NormalizeLegacyIdentifiers rewrites identifiers that predate the AgentOS → Fenced rename into their canonical Fenced form. DecodeManifest applies it before validation, so a manifest published under the former name stays loadable instead of failing with "runtimes[0].interface must be fenced.runtime.interface/v1".

The canonical JSON and SHA-256 returned by DecodeManifest are computed on the normalized document, so a legacy manifest has a different identity after the rename. See docs/COMPATIBILITY.md.

func (Manifest) PromoteToV1

func (m Manifest) PromoteToV1() (Manifest, error)

PromoteToV1 performs the only supported alpha-to-GA schema migration. The v1 schema is otherwise wire-identical, so canonical identity changes solely because the two explicit contract identifiers are promoted.

func (Manifest) Ref

func (m Manifest) Ref() string

func (Manifest) Validate

func (m Manifest) Validate() error

type Metadata

type Metadata struct {
	Name      string `json:"name"`
	Version   string `json:"version"`
	Namespace string `json:"namespace"`
}

type ResourceLimits

type ResourceLimits struct {
	CPUMillis      int64 `json:"cpuMillis"`
	MemoryMiB      int64 `json:"memoryMiB"`
	WorkspaceBytes int64 `json:"workspaceBytes"`
}

type RuntimeClassPolicy

type RuntimeClassPolicy struct {
	Allowed   []string `json:"allowed,omitempty"`
	Preferred string   `json:"preferred,omitempty"`
}

type RuntimeTarget

type RuntimeTarget struct {
	Class      string   `json:"class"`
	Interface  string   `json:"interface"`
	RuntimeABI string   `json:"runtimeABI"`
	Entrypoint []string `json:"entrypoint"`
}

RuntimeTarget binds one portable agent build to a runtime class.

type Spec

type Spec struct {
	RuntimeClassPolicy RuntimeClassPolicy `json:"runtimeClassPolicy,omitempty"`
	Lifecycle          Lifecycle          `json:"lifecycle,omitempty"`
	// Runtimes declares the portable launch targets shipped by this version.
	// Each target binds a runtime class to the stable Runtime Interface, a
	// provider ABI and an argv entrypoint.
	Runtimes []RuntimeTarget `json:"runtimes,omitempty"`
	// Capabilities are policy identifiers, not network endpoints or secret
	// values. Adapters map them to the corresponding Kernel gateways.
	Capabilities *Capabilities     `json:"capabilities,omitempty"`
	Resources    *ResourceLimits   `json:"resources,omitempty"`
	Budget       *Budget           `json:"budget,omitempty"`
	Checkpoint   *CheckpointPolicy `json:"checkpoint,omitempty"`
	// Image pins the container image the published version is allowed to run
	// (ADR-010). When set, admission rejects tasks whose spec pins a
	// different image.
	Image *Image `json:"image,omitempty"`
}

Spec is the bounded AgentVersion vocabulary consumed by the kernel. Legacy fields remain valid while v0.9 portable runtime and capability declarations are validated when present. Unknown fields are preserved in stored specs so additive compatibility can be maintained across later stages.

type ToolGrantSet

type ToolGrantSet struct {
	// Capability is matched against a bare tool name.
	Capability []string
	// NameLevel holds the grants authored without a version.
	NameLevel []string
	// Versioned holds the pinned and floating grants.
	Versioned []string
}

ToolGrantSet is one tool grant list split into the vocabularies the kernel compares against.

The three views exist because the kernel makes three different questions about the same grant:

  • Capability: may this AgentVersion use the tool at all? It is matched against a bare tool name, so a grant that pins a version grants the tool as well.
  • NameLevel: which tool versions may it use? These are the grants authored without a version, and they are frozen to the tool versions that existed when the AgentVersion was published.
  • Versioned: which exact version may it use? These are the pinned ("name@version") and floating ("name@*") grants; they decide the version and opt out of the freeze.

Before the split, the runtime capability check and the publish-time freeze read the same field with two different vocabularies: the capability check compares bare tool names while the freeze understands the version forms. A correctly pinned publication was therefore denied every agent-facing tool call, while a bare grant kept its frozen behaviour.

func PublicationToolGrants

func PublicationToolGrants(capabilitiesTools, capabilityToolVersions []string) ToolGrantSet

PublicationToolGrants returns the views of a published specification. A normalized publication keeps the version vocabulary in capabilities.toolVersions; a publication written before that split (or by an older writer) carries both forms inside capabilities.tools.

The merge is idempotent: normalizing an already normalized document reproduces it, so a publication can be canonicalized again without losing its pinned versions.

func SplitToolGrants

func SplitToolGrants(grants []string) ToolGrantSet

SplitToolGrants splits one grant list into its three views. The result is deduplicated and keeps first-appearance order, so a publication stays deterministic.

Jump to

Keyboard shortcuts

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