agentdef

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 Imported by: ? 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 agentdef is the agent definition format: the fields a definition file carries, the parser that reads one, and the canonical form a definition digest covers. It depends on nothing else in Mecatl, so the identity broker and the harness can read definitions without one depending on the other.

A definition file is a flat <name>.md file: a YAML frontmatter block between two "---" lines, then a markdown body. Parse reads the bytes of one file. Finding files, and deciding which locations count, is the caller's job.

The engine's agentfs adapter still has its own copy of this parser, until it is switched over to this package. Until then both must read every file the same way; a parity test in the root module (internal/app) checks it.

Index

Constants

View Source
const DigestAlgorithm = "sha256"

DigestAlgorithm names the algorithm Digest uses.

View Source
const FileExt = ".md"

FileExt is the extension of an agent definition file. A definition lives at <dir>/<name>.md, a flat file rather than a <name>/AGENT.md directory.

View Source
const FormVersion = "agentdef-canonical/v1"

FormVersion names the canonical form Canonical produces. Any change to that form, such as a new encoding rule or a renamed key, changes digests of definitions that did not change, so it needs a new version. A consumer that records a digest should record this version with it.

View Source
const MaxBodyBytes = 32 * 1024

MaxBodyBytes caps Definition.Body. Parse truncates a longer body on a rune boundary, appends an ellipsis, and reports a note. It equals the engine's tool.MaxAgentBodyBytes.

View Source
const MaxDescriptionBytes = 2000

MaxDescriptionBytes caps Definition.Description. Parse truncates a longer description on a rune boundary, appends an ellipsis, and reports a note. It equals the engine's tool.MaxAgentDescriptionBytes.

Variables

This section is empty.

Functions

func Canonical

func Canonical(d Definition) ([]byte, error)

Canonical returns the canonical bytes of d: the input of a digest of the accepted definition, so two definitions have the same digest exactly when they are the same definition. The form is the JSON encoding of d with:

  • the keys its json tags name, in the order of its fields;
  • map keys sorted;
  • empty fields left out, so a field added to Definition changes only the digests of definitions that set it;
  • no HTML escaping and no trailing newline.

It returns an error when a string in d is not valid UTF-8: JSON would encode each invalid byte as U+FFFD, so two different definitions could share a form.

func Digest

func Digest(d Definition) (string, error)

Digest returns the digest of the definition d: the lowercase hexadecimal SHA-256 of Canonical(d). It is the digest of the accepted definition, so two readers of the same file get the same value; it fails when Canonical does.

Types

type Definition

type Definition struct {
	// Name identifies the definition. It is required and trimmed.
	Name string `json:"name"`
	// Description says what the definition is for. It is required, trimmed,
	// and at most MaxDescriptionBytes.
	Description string `json:"description"`
	// Tools is the optional allowlist of tool names. Empty means the caller's
	// default set. A legacy "Bash" entry reads as "Shell".
	Tools []string `json:"tools,omitempty"`
	// DisallowedTools is the optional list of tool names removed after Tools
	// or the default set. A legacy "Bash" entry reads as "Shell".
	DisallowedTools []string `json:"disallowedTools,omitempty"`
	// Model is the optional model selector, such as an alias or a full ID.
	Model string `json:"model,omitempty"`
	// Provider is the optional provider selector.
	Provider string `json:"provider,omitempty"`
	// PermissionMode is the optional session permission mode hint.
	PermissionMode string `json:"permissionMode,omitempty"`
	// MaxTurns is the optional per-run turn cap; zero means the caller's.
	MaxTurns int `json:"maxTurns,omitempty"`
	// MaxToolCalls is the optional per-run tool call cap; zero means the
	// caller's.
	MaxToolCalls int `json:"maxToolCalls,omitempty"`
	// Color is an optional display hint.
	Color string `json:"color,omitempty"`
	// Skills names optional skills to preload.
	Skills []string `json:"skills,omitempty"`
	// MCPServers lists optional MCP servers, by reference or inline.
	MCPServers []MCPServer `json:"mcpServers,omitempty"`
	// Hooks maps a lifecycle phase to a shell command. The parser does not
	// check phase names.
	Hooks map[string]string `json:"hooks,omitempty"`
	// Memory is the optional memory tier: "", "user", or "project".
	Memory string `json:"memory,omitempty"`
	// Body is the markdown instructions after the frontmatter, trimmed and at
	// most MaxBodyBytes.
	Body string `json:"body,omitempty"`
}

Definition is one parsed agent definition. It carries what the file says and nothing about where the file came from. The json tags name the keys of the canonical form (see Canonical).

func Parse

func Parse(raw []byte) (Definition, []string, error)

Parse reads one definition file's bytes. It returns the definition and a note for each adjustment it made to a definition it kept, such as a truncated description, a skipped mcpServers entry, or an ignored memory tier. It returns an error when the file is not a definition: it has no frontmatter, the frontmatter is not valid YAML, or the name or description is missing. Error text never quotes the file, which can hold secrets.

Tool names are not checked: an unknown tool name is the caller's concern, against a concrete tool catalog.

type MCPServer

type MCPServer struct {
	// Name identifies the server.
	Name string `json:"name"`
	// URL is the inline server's endpoint; empty for a reference.
	URL string `json:"url,omitempty"`
	// Headers are the inline server's request headers. The values can be
	// secrets: never log or display them.
	Headers map[string]string `json:"headers,omitempty"`
}

MCPServer is one MCP server a definition names. With no URL it refers to a server configured elsewhere; with a URL it is an inline streamable-HTTP server.

func (MCPServer) IsReference

func (s MCPServer) IsReference() bool

IsReference reports whether s refers to a server configured elsewhere rather than defining an inline one.

Jump to

Keyboard shortcuts

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