tools

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tools defines the Tool interface and Registry for agent tool execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentIDFromContext

func AgentIDFromContext(ctx context.Context) string

AgentIDFromContext returns the agent ID from context, if set.

func ProjectIDFromContext

func ProjectIDFromContext(ctx context.Context) string

ProjectIDFromContext returns the project ID from context, if set.

func TaskIDFromContext

func TaskIDFromContext(ctx context.Context) string

TaskIDFromContext returns the task ID from context, if set.

func TeamIDFromContext

func TeamIDFromContext(ctx context.Context) string

TeamIDFromContext returns the team ID from context, if set.

func WithAgentID

func WithAgentID(ctx context.Context, agentID string) context.Context

WithAgentID returns a context with the agent ID set.

func WithProjectID

func WithProjectID(ctx context.Context, projectID string) context.Context

WithProjectID returns a context with the project ID set.

func WithTaskID

func WithTaskID(ctx context.Context, taskID string) context.Context

WithTaskID returns a context with the task ID set.

func WithTeamID

func WithTeamID(ctx context.Context, teamID string) context.Context

WithTeamID returns a context with the team ID set.

Types

type PolicyEngine

type PolicyEngine interface {
	// IsAllowed checks whether agentID (in teamID) may call toolName.
	// Returns (allowed, reason).
	IsAllowed(ctx context.Context, toolName, agentID, teamID string) (bool, string)
}

PolicyEngine enforces access control on tool execution.

type Registry

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

Registry merges built-in tools into a unified, policy-enforced registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) AllDefs

func (r *Registry) AllDefs() []provider.ToolDef

AllDefs returns tool definitions for all registered tools.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, args map[string]any) (any, error)

Execute runs a tool by name with the given arguments. If a policy engine is set, access control is checked before execution.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get returns a tool by name.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all registered tool names.

func (*Registry) Register

func (r *Registry) Register(tool Tool)

Register adds a tool to the registry.

func (*Registry) RegisterMCP

func (r *Registry) RegisterMCP(serverName string, tools []Tool)

RegisterMCP registers MCP tools with a server-prefixed name.

func (*Registry) SetPolicyEngine

func (r *Registry) SetPolicyEngine(pe PolicyEngine)

SetPolicyEngine attaches a PolicyEngine for access control enforcement.

func (*Registry) UnregisterMCP

func (r *Registry) UnregisterMCP(serverName string)

UnregisterMCP removes all tools registered under the given MCP server name.

type Tool

type Tool interface {
	// Name returns the unique identifier for this tool.
	Name() string

	// Definition returns the tool schema exposed to the LLM.
	Definition() provider.ToolDef

	// Execute runs the tool with the given arguments and returns the result.
	Execute(ctx context.Context, args map[string]any) (any, error)
}

Tool is an agent-callable function with a well-defined schema.

Jump to

Keyboard shortcuts

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