agent

package
v0.133.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 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 agent defines the machine-readable "agent contract" that every fleet service can advertise so an AI agent (Claude, Codex, OpenCode, an MCP server, the catalog hub) can call it correctly without guessing the input shape, auth model, or output envelope.

It is the agentic counterpart to server/capabilities.go (which lists query-flag knobs) and server/schema.go (which carries the envelope schema version). Where /capabilities says "these toggles exist" and /schema says "this is the envelope version", /agent.json says "here is exactly how to invoke me: one named tool, its input JSON Schema, the auth it needs, and what the response looks like."

Why a dedicated package instead of bolting fields onto Capability: an agent tool is a higher-level unit than a query flag. A service exposes ONE tool (or a few) that an agent reasons about; capabilities are the lower-level dials *inside* that tool. Keeping them separate means the agent contract stays small and stable while capabilities can grow without changing the agent's mental model.

Propagation model: the serving logic lives here, in go-common. A service opts in with a single option:

//go:embed agent.json
var agentFS embed.FS
srv := server.New(cfg, server.WithAgentFromEmbed(agentFS, "agent.json"))

or, to reuse the fleet-wide default contract without shipping its own file:

srv := server.New(cfg, server.WithAgent(agent.DefaultTool(cfg.AppName, cfg.Version)))

fleet-runner inject already refreshes go-common across the fleet via the replace ../go-common directive, so adding this package propagates the capability to every service on its next converge. Per-repo work is just the optional agent.json data file — no handler code.

Index

Constants

View Source
const DefaultSchemaVersion = 1

DefaultSchemaVersion is the contract schema version advertised when a service does not override it.

View Source
const ExampleAgentJSON = `` /* 1113-byte string literal not displayed */

ExampleAgentJSON is a reference agent.json a service can copy and edit. Ship it as agent.json next to main.go with:

//go:embed agent.json
var agentFS embed.FS

and register with server.WithAgentFromEmbed(agentFS, "agent.json").

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// Type is "api_key" for the fleet gateway, or "none".
	Type string `json:"type"`
	// Header is the request header the gateway expects (e.g. "X-API-Key").
	Header string `json:"header,omitempty"`
	// QueryParam is the query-param alternative (e.g. "api_key").
	QueryParam string `json:"query_param,omitempty"`
}

Auth describes the authorization an agent must attach.

func DefaultAuth

func DefaultAuth() Auth

DefaultAuth returns the standard fleet gateway auth descriptor.

type Contract

type Contract struct {
	// SchemaVersion lets drift checkers distinguish contract shapes.
	// Bump when Tool/Auth gain fields in a breaking way.
	SchemaVersion int    `json:"schema_version"`
	Service       string `json:"service"`
	Version       string `json:"version"`
	Tools         []Tool `json:"tools"`
}

Contract is the full payload served at GET /agent.json. It can carry one or more tools (most fleet services expose exactly one).

func DefaultContract

func DefaultContract(service, version string) Contract

DefaultContract builds a Contract with a single DefaultTool.

func FromJSON

func FromJSON(b []byte) (Contract, error)

FromJSON parses a Contract from JSON bytes (used by WithAgentFromEmbed).

func LoadEmbed

func LoadEmbed(fsys embed.FS, name, service, version string) (Contract, error)

LoadEmbed reads an agent.json from an embedded filesystem (the typical service pattern: //go:embed agent.json var agentFS embed.FS) and parses it into a Contract. Service identity (service/version) is taken from the caller so a service can ship a contract that omits those fields.

If the embedded file is missing or invalid, an error is returned — the server option should fail fast rather than serve a silent default that masks a broken embed.

func (Contract) JSON

func (c Contract) JSON() ([]byte, error)

JSON serialises the contract to indented JSON.

type Tool

type Tool struct {
	// Name is the stable tool identifier (typically the service slug).
	// Agents key on this; it must be unique within a server.
	Name string `json:"name"`
	// Summary is a one-line description for tool lists.
	Summary string `json:"summary"`
	// Description is the longer, agent-readable explanation.
	Description string `json:"description,omitempty"`
	// Category mirrors the fleet category (security, recon, web_analysis…).
	Category string `json:"category,omitempty"`
	// Tags are free-form fleet tags (go, kind-container…).
	Tags []string `json:"tags,omitempty"`
	// TRL is the technology-readiness level from the catalog, if known.
	TRL int `json:"trl,omitempty"`
	// InputSchema is a JSON Schema (draft-07 subset) describing the
	// parameters an agent must supply. The service's primary target
	// param (url/target/domain/…) should be marked required.
	InputSchema map[string]any `json:"input_schema"`
	// Auth describes what the gateway needs to authorize the call.
	Auth Auth `json:"auth"`
	// OutputShape is a short, human-readable note about the response
	// envelope (not a full schema — keep it cheap to render in a tool
	// list). The canonical envelope is response.Envelope.
	OutputShape string `json:"output_shape,omitempty"`
	// Examples are ready-to-run invocations (curl) for the catalog/hub.
	Examples []string `json:"examples,omitempty"`
	// Method is the HTTP method server.WithMCP uses to invoke this tool
	// against the service's own route. Empty defaults to GET.
	Method string `json:"method,omitempty"`
	// Path is the HTTP path server.WithMCP invokes, relative to the
	// service root. Empty defaults to "/". May contain "{name}"
	// placeholders (e.g. "/{type}/{name}") substituted from matching
	// InputSchema properties before the request is built — several
	// fleet services (go-fleet-dig's /{type}/{name}) take their
	// primary input from the path, not a query string. Whatever
	// InputSchema properties aren't consumed by a placeholder become
	// query parameters for GET/HEAD/DELETE, or a JSON body otherwise
	// (unless BodyField is set — see below).
	Path string `json:"path,omitempty"`
	// BodyField names the one InputSchema property (must be a string)
	// sent as the raw, un-encoded request body on non-GET methods,
	// instead of JSON-marshaling every property. Several fleet
	// services (go-fleet-md: POST the markdown itself, not a JSON
	// envelope) take their primary input as a raw body with the rest
	// of their knobs on the query string. Every other property still
	// becomes a query parameter, same as the GET/HEAD/DELETE case.
	// Ignored when Method is empty/GET/HEAD/DELETE.
	BodyField string `json:"body_field,omitempty"`
	// BodyContentType is the Content-Type sent with BodyField's raw
	// value. Defaults to "text/plain; charset=utf-8" when BodyField is
	// set and this is empty.
	BodyContentType string `json:"body_content_type,omitempty"`
}

Tool is the agent-facing contract for one callable unit of a service. It is intentionally close to the Model Context Protocol (MCP) "tool" object and to OpenAI/Anthropic function-calling "function" objects so a bridge can translate 1:1 without remapping.

func DefaultTool

func DefaultTool(service, version string) Tool

DefaultTool builds a minimal but valid agent Tool for a service using the fleet-wide conventions: a single required "target" string input (the primary fetch param), api_key auth, and the standard envelope note. This is what a service gets if it calls WithAgent(agent.DefaultTool(...)) without shipping its own agent.json — enough for an agent to call it, with the service free to enrich later.

Jump to

Keyboard shortcuts

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