agents

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package agents provides named configuration bundles for term-llm. Agents combine system prompts, tool sets, model preferences, and MCP servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyAgent

func CopyAgent(src *Agent, destDir, newName string) error

CopyAgent copies an agent to a new location.

func CreateAgentDir

func CreateAgentDir(baseDir, name string) error

CreateAgentDir creates an agent directory with template files.

func ExpandTemplate

func ExpandTemplate(text string, ctx TemplateContext) string

ExpandTemplate replaces {{variable}} placeholders with values from context.

func ExtractBuiltinResources

func ExtractBuiltinResources(name string) (string, error)

ExtractBuiltinResources extracts additional resource files for a builtin agent to the cache directory. This extracts all .md files except system.md (which is loaded into the agent struct).

func GetBuiltinAgentNames

func GetBuiltinAgentNames() []string

GetBuiltinAgentNames returns the names of all built-in agents.

func GetBuiltinResourceDir

func GetBuiltinResourceDir() (string, error)

GetBuiltinResourceDir returns the cache directory where builtin agent resources are extracted. Uses $XDG_CACHE_HOME if set, otherwise ~/.cache

func GetLocalAgentsDir

func GetLocalAgentsDir() (string, error)

GetLocalAgentsDir returns the path for project-local agents.

func GetUserAgentsDir

func GetUserAgentsDir() (string, error)

GetUserAgentsDir returns the path for user-global agents.

func IsBuiltinAgent

func IsBuiltinAgent(name string) bool

IsBuiltinAgent checks if an agent name is a built-in.

Types

type Agent

type Agent struct {
	// Metadata
	Name        string `yaml:"name"`
	Description string `yaml:"description"`

	// Model preferences (optional)
	Provider string `yaml:"provider,omitempty"`
	Model    string `yaml:"model,omitempty"`

	// Tool configuration
	Tools ToolsConfig `yaml:"tools,omitempty"`

	// Tool-specific settings
	Shell ShellConfig `yaml:"shell,omitempty"`
	Read  ReadConfig  `yaml:"read,omitempty"`
	Spawn SpawnConfig `yaml:"spawn,omitempty"`

	// Behavior
	MaxTurns int  `yaml:"max_turns,omitempty"`
	Search   bool `yaml:"search,omitempty"` // Enable web search tools

	// Include additional .md files in the system prompt
	// Files are loaded from the agent directory and appended after system.md
	Include []string `yaml:"include,omitempty"`

	// MCP servers to auto-connect
	MCP []MCPConfig `yaml:"mcp,omitempty"`

	// System prompt (loaded from system.md + included files)
	SystemPrompt string `yaml:"-"`

	// Source info
	Source     AgentSource `yaml:"-"`
	SourcePath string      `yaml:"-"`
}

Agent represents a named configuration bundle.

func LoadFromDir

func LoadFromDir(dir string, source AgentSource) (*Agent, error)

LoadFromDir loads an agent from a directory containing agent.yaml and optionally system.md.

func LoadFromEmbedded

func LoadFromEmbedded(name string, agentYAML, systemMD []byte) (*Agent, error)

LoadFromEmbedded loads an agent from embedded filesystem data.

func (*Agent) GetEnabledTools

func (a *Agent) GetEnabledTools(allTools []string) []string

GetEnabledTools returns the list of enabled tools. If Enabled is set, returns that list. If Disabled is set, returns all tools except disabled ones. If neither is set, returns nil (use default).

func (*Agent) GetMCPServerNames

func (a *Agent) GetMCPServerNames() []string

GetMCPServerNames returns the names of MCP servers to connect.

func (*Agent) HasDisabledList

func (a *Agent) HasDisabledList() bool

HasDisabledList returns true if the agent uses a disabled list.

func (*Agent) HasEnabledList

func (a *Agent) HasEnabledList() bool

HasEnabledList returns true if the agent uses an explicit enabled list.

func (*Agent) String

func (a *Agent) String() string

String returns a brief description of the agent.

func (*Agent) Validate

func (a *Agent) Validate() error

Validate checks that the agent configuration is valid.

type AgentSource

type AgentSource int

AgentSource indicates where an agent was loaded from.

const (
	SourceLocal   AgentSource = iota // Project-local (./term-llm-agents/)
	SourceUser                       // User-global (~/.config/term-llm/agents/)
	SourceBuiltin                    // Embedded built-in
)

func (AgentSource) SourceName

func (s AgentSource) SourceName() string

SourceName returns a human-readable name for the agent source.

type MCPConfig

type MCPConfig struct {
	Name    string `yaml:"name"`
	Command string `yaml:"command,omitempty"`
}

MCPConfig specifies an MCP server to connect.

type ReadConfig

type ReadConfig struct {
	Dirs []string `yaml:"dirs,omitempty"`
}

ReadConfig provides read tool settings.

type Registry

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

Registry manages agent discovery and resolution.

func NewRegistry

func NewRegistry(cfg RegistryConfig) (*Registry, error)

NewRegistry creates an agent registry with standard paths.

func (*Registry) Get

func (r *Registry) Get(name string) (*Agent, error)

Get retrieves an agent by name. Resolution order: local > user > search paths > builtin

func (*Registry) List

func (r *Registry) List() ([]*Agent, error)

List returns all available agents. Each agent appears only once, with first-found taking precedence.

func (*Registry) ListBySource

func (r *Registry) ListBySource(source AgentSource) ([]*Agent, error)

ListBySource returns agents from a specific source.

type RegistryConfig

type RegistryConfig struct {
	UseBuiltin  bool
	SearchPaths []string
}

RegistryConfig configures the agent registry.

type ShellConfig

type ShellConfig struct {
	Allow   []string          `yaml:"allow,omitempty"`
	AutoRun bool              `yaml:"auto_run,omitempty"`
	Scripts map[string]string `yaml:"scripts,omitempty"` // Named scripts (auto-approved)
}

ShellConfig provides shell tool settings.

type SpawnConfig added in v0.0.35

type SpawnConfig struct {
	MaxParallel    int      `yaml:"max_parallel,omitempty"`   // Max concurrent sub-agents (default 3)
	MaxDepth       int      `yaml:"max_depth,omitempty"`      // Max nesting level (default 2)
	DefaultTimeout int      `yaml:"timeout,omitempty"`        // Default timeout in seconds (default 300)
	AllowedAgents  []string `yaml:"allowed_agents,omitempty"` // Optional whitelist of allowed agents
}

SpawnConfig configures spawn_agent behavior for this agent.

type TemplateContext

type TemplateContext struct {
	// Time-related
	Date     string // YYYY-MM-DD
	DateTime string // YYYY-MM-DD HH:MM:SS
	Time     string // HH:MM
	Year     string // YYYY

	// Directory info
	Cwd     string // Full working directory
	CwdName string // Directory name only
	Home    string // Home directory
	User    string // Username

	// Git info (empty if not a git repo)
	GitBranch   string // Current branch
	GitRepo     string // Repository name
	GitDiffStat string // Output of git diff --stat (staged + unstaged)

	// File context (from -f flags)
	Files     string // Comma-separated file names
	FileCount string // Number of files

	// System
	OS string // Operating system

	// Agent context
	ResourceDir string // Directory containing agent resources (for builtin agents)

	// Project agent instructions (dynamically discovered)
	// Searches in priority order: AGENTS.md, CLAUDE.md, .github/copilot-instructions.md,
	// .cursor/rules, CONTRIBUTING.md - returns first found
	Agents string
}

TemplateContext holds values for template variable expansion.

func NewTemplateContext

func NewTemplateContext() TemplateContext

NewTemplateContext creates a context with current environment values. Deprecated: Use NewTemplateContextForTemplate instead to avoid expensive operations when template variables are not used.

func NewTemplateContextForTemplate added in v0.0.34

func NewTemplateContextForTemplate(template string) TemplateContext

NewTemplateContextForTemplate creates a context, only computing expensive values (like git_diff_stat, agents) if they are actually used in the template.

func (TemplateContext) WithFiles

func (c TemplateContext) WithFiles(files []string) TemplateContext

WithFiles adds file context to the template context.

func (TemplateContext) WithResourceDir

func (c TemplateContext) WithResourceDir(resourceDir string) TemplateContext

WithResourceDir sets the resource directory for an agent.

type ToolsConfig

type ToolsConfig struct {
	// Enabled is an explicit allow list of tools
	Enabled []string `yaml:"enabled,omitempty"`
	// Disabled is a deny list (all others enabled)
	Disabled []string `yaml:"disabled,omitempty"`
}

ToolsConfig specifies which tools to enable or disable.

Jump to

Keyboard shortcuts

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