catalog

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package catalog composes explicitly registered agent tools into policy-gated snapshots. It deliberately does not discover executables from skill folders: scripts become callable only after a host wraps them as an agent.Tool or MCP tool and assigns provenance and risk.

Package catalog provides the application composition boundary for agent tools. A Catalog holds explicitly registered local, MCP, and Team snapshots with provenance and risk. A Policy then creates a tenant-scoped, deny-by- default snapshot suitable for agent.WithTools.

Merge combines several immutable Catalogs while preserving their entry order and policy metadata. Duplicate tool names remain errors rather than receiving an implicit precedence.

ToolSearch implements optional, source-aware deferred discovery. With ToolSearchOptions{Enabled: true}, local and Team tools stay direct while MCP and extension tools are deferred by default; DeferredSources customizes that policy. AgentOptions installs the direct snapshot and prepare hook. Raw files under a Skill's scripts/ folder are never discovered as tools.

Index

Examples

Constants

View Source
const (
	// SourceLocal identifies a tool implemented by the application process.
	SourceLocal = "local"
	// SourceMCP identifies a tool from an MCP server snapshot.
	SourceMCP = "mcp"
	// SourceExtension identifies a tool supplied by an installed extension.
	SourceExtension = "extension"
	// SourceTeam identifies a Team-scoped agent tool.
	SourceTeam = "team"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer func(context.Context, string, Descriptor) (bool, error)

Authorizer can make tenant-specific decisions after static allowlist and risk checks pass. Returning false hides the tool from the snapshot.

type Catalog

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

Catalog is immutable after construction and safe for concurrent snapshots.

func Merge

func Merge(catalogs ...*Catalog) (*Catalog, error)

Merge combines immutable catalogs in argument order. It preserves each entry's tool, provenance, risk, and tags, and returns an independent Catalog. A nil input or duplicate tool name is an error; no inputs produce an empty Catalog.

Example
package main

import (
	"context"
	"fmt"

	"github.com/rsbin1178/pips/agent"
	"github.com/rsbin1178/pips/agent/catalog"
)

func main() {
	read := agent.NewTool("read_doc", "Read a document", func(context.Context, struct{}) (string, error) {
		return "", nil
	})
	lookup := agent.NewTool("remote_lookup", "Look up documentation", func(context.Context, struct{}) (string, error) {
		return "", nil
	})

	local, _ := catalog.New(catalog.Local("app", catalog.RiskRead, read)...)
	remote, _ := catalog.New(catalog.MCP("docs", catalog.RiskRead, lookup)...)
	merged, _ := catalog.Merge(local, remote)

	tools, _ := merged.Snapshot(context.Background(), catalog.AllowAll("example", catalog.RiskRead))
	for _, tool := range tools {
		fmt.Println(tool.Decl().Name)
	}
}
Output:
read_doc
remote_lookup

func New

func New(entries ...Entry) (*Catalog, error)

New validates and indexes explicitly registered tools.

func (*Catalog) Search

func (c *Catalog) Search(ctx context.Context, policy Policy, query string) ([]Descriptor, error)

Search returns policy-authorized descriptors whose name, description, source or tags contain every query term. It never exposes a Tool implementation.

func (*Catalog) Snapshot

func (c *Catalog) Snapshot(ctx context.Context, policy Policy) ([]agent.Tool, error)

Snapshot returns tools authorized for this tenant in registration order.

func (*Catalog) Tools

func (c *Catalog) Tools(ctx context.Context, policy Policy, names ...string) ([]agent.Tool, error)

Tools selects exact tool names from an already policy-gated catalog. It is used by deferred tool loading after the search result has been shown.

type Descriptor

type Descriptor struct {
	Name        string
	Description string
	Source      Source
	Risk        Risk
	Tags        []string
}

Descriptor is the immutable metadata visible to a policy decision.

type Entry

type Entry struct {
	Tool   agent.Tool
	Source Source
	Risk   Risk
	Tags   []string
}

Entry is one explicitly registered tool and its policy metadata.

func Extension

func Extension(extensionID string, risk Risk, tools ...agent.Tool) []Entry

Extension wraps tools contributed by an installed extension.

func Local

func Local(id string, risk Risk, tools ...agent.Tool) []Entry

Local wraps application-owned tools with local provenance.

func MCP

func MCP(server string, risk Risk, tools ...agent.Tool) []Entry

MCP wraps a snapshot returned by agent/mcp with server provenance.

func Team

func Team(teamID string, risk Risk, tools ...agent.Tool) []Entry

Team wraps a snapshot returned by agent/team with team provenance.

type Policy

type Policy struct {
	TenantID  string
	Allowlist []string
	MaxRisk   Risk
	Authorize Authorizer
}

Policy bounds a snapshot. It is deny-by-default: callers must provide an allowlist or use AllowAll deliberately. MaxRisk defaults to RiskRead.

func AllowAll

func AllowAll(tenantID string, maxRisk Risk) Policy

AllowAll deliberately opts into every registered tool up to maxRisk. It is intended for trusted single-tenant applications; multi-tenant hosts should supply a precise allowlist and Authorize function.

type Risk

type Risk uint8

Risk classifies the highest expected impact of a tool invocation.

const (
	RiskRead Risk = iota
	RiskWrite
	RiskPrivileged
)

Tool risk levels, ordered from least to most privileged.

type Source

type Source struct {
	Kind string
	ID   string
}

Source identifies how a tool reached the application composition root. The catalog never imports optional MCP or team packages; their callers pass the snapshots through the corresponding constructor helpers below.

type ToolSearch

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

ToolSearch provides Claude-style deferred tool discovery without exposing every declaration on the first model request. Add Tools() when building the agent and use PrepareTurn as its prepare-turn hook. Search results are policy-filtered before they reach the model, then re-authorized when the snapshot is applied.

func NewToolSearch

func NewToolSearch(catalog *Catalog, policy Policy, options ToolSearchOptions) (*ToolSearch, error)

NewToolSearch constructs a source-aware tool configuration. policy must explicitly authorize every eventual target; an empty allowlist produces an empty tool snapshot. Call Tools with the construction context, then install PrepareTurn only when Enabled is true.

func (*ToolSearch) AgentOptions

func (s *ToolSearch) AgentOptions(ctx context.Context) ([]agent.Option, error)

AgentOptions builds the options needed to install this configuration. It keeps direct tools visible and adds the prepare hook only when search is on.

func (*ToolSearch) Forget

func (s *ToolSearch) Forget(runID string)

Forget removes one run's deferred selection early. It is useful when a host chains its event handler and observes agent.EventRunCompleted.

func (*ToolSearch) PrepareTurn

func (s *ToolSearch) PrepareTurn(ctx context.Context, info agent.RunInfo) agent.TurnUpdate

PrepareTurn returns the complete next-turn snapshot. It must be installed through agent.WithPrepareTurn; the agent runtime validates the replacement before showing it to the model.

func (*ToolSearch) Tools

func (s *ToolSearch) Tools(ctx context.Context) ([]agent.Tool, error)

Tools returns the application built-ins and all direct catalog tools. When deferred search is enabled, it additionally returns tool_search; otherwise it returns every policy-authorized catalog tool. The slice is suitable for agent.WithTools.

type ToolSearchOptions

type ToolSearchOptions struct {
	Enabled         bool
	DeferredSources []string
	Initial         []agent.Tool
	Limit           int
	MaxRuns         int
}

ToolSearchOptions controls deferred loading behavior. Initial tools are application built-ins and remain visible on every snapshot. When Enabled is false, every policy-authorized catalog tool is exposed normally. When true, only DeferredSources are discovered through tool_search; all other sources stay visible. An empty DeferredSources uses the Claude Code-like default: MCP and extension tools are deferred, while local and Team tools are direct.

Jump to

Keyboard shortcuts

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