Documentation
¶
Overview ¶
Package agents provides named configuration bundles for term-llm. Agents combine system prompts, tool sets, model preferences, and MCP servers.
Index ¶
- Constants
- func CopyAgent(src *Agent, destDir, newName string) error
- func CreateAgentDir(baseDir, name string) error
- func DiscoverProjectInstructions() string
- func ExpandFileIncludes(input string, opts IncludeOptions) (string, error)
- func ExpandTemplate(text string, ctx TemplateContext) string
- func ExtractBuiltinResources(name string) (string, error)
- func GetBuiltinAgentNames() []string
- func GetBuiltinResourceDir() (string, error)
- func GetLocalAgentsDir() (string, error)
- func GetUserAgentsDir() (string, error)
- func IsAgentPath(value string) bool
- func IsBuiltinAgent(name string) bool
- type Agent
- func (a *Agent) GetEnabledTools(allTools []string) []string
- func (a *Agent) GetMCPServerNames() []string
- func (a *Agent) HasDisabledList() bool
- func (a *Agent) HasEnabledList() bool
- func (a *Agent) Merge(pref config.AgentPreference)
- func (a *Agent) ShouldLoadProjectInstructions() bool
- func (a *Agent) String() string
- func (a *Agent) Validate() error
- type AgentSource
- type CustomToolDef
- type IncludeOptions
- type MCPConfig
- type MemoryConfig
- type OutputToolConfig
- type PlatformMessagesConfig
- type ReadConfig
- type Registry
- type RegistryConfig
- type ShellConfig
- type SpawnConfig
- type TemplateContext
- func (c TemplateContext) WithFiles(files []string) TemplateContext
- func (c TemplateContext) WithHandoverDir(dir string) TemplateContext
- func (c TemplateContext) WithHandoverPath(path string) TemplateContext
- func (c TemplateContext) WithLLM(provider, model string) TemplateContext
- func (c TemplateContext) WithPlatform(platform string) TemplateContext
- func (c TemplateContext) WithResourceDir(resourceDir string) TemplateContext
- type ToolsConfig
Constants ¶
const (
// DefaultIncludeMaxDepth limits recursive {{file:...}} expansion depth.
DefaultIncludeMaxDepth = 10
)
Variables ¶
This section is empty.
Functions ¶
func CreateAgentDir ¶
CreateAgentDir creates an agent directory with template files.
func DiscoverProjectInstructions ¶ added in v0.0.43
func DiscoverProjectInstructions() string
DiscoverProjectInstructions loads project instructions using a unified algorithm:
- User-level: ~/.config/term-llm/AGENTS.md
- Project-level: hierarchical AGENTS.md from repo root → cwd At each directory level, AGENTS.override.md takes precedence over AGENTS.md.
- Fallback (only if step 2 found nothing): CLAUDE.md, copilot-instructions.md, etc.
All found parts are joined with "\n\n---\n\n". Returns empty string if nothing is found.
func ExpandFileIncludes ¶ added in v0.0.84
func ExpandFileIncludes(input string, opts IncludeOptions) (string, error)
ExpandFileIncludes replaces {{file:path}} directives with file contents. Includes are expanded recursively with cycle and depth guards.
func ExpandTemplate ¶
func ExpandTemplate(text string, ctx TemplateContext) string
ExpandTemplate replaces {{variable}} placeholders with values from context.
func ExtractBuiltinResources ¶
ExtractBuiltinResources extracts additional resource files for a builtin agent to the cache directory. It walks the agent's builtin directory tree (preserving subdirectory layout) and copies .md, .yaml, and .env files (including dot-prefixed files like .template.yaml). agent.yaml and system.md at the root are skipped because they are loaded into the Agent struct.
func GetBuiltinAgentNames ¶
func GetBuiltinAgentNames() []string
GetBuiltinAgentNames returns the names of all built-in agents.
func GetBuiltinResourceDir ¶
GetBuiltinResourceDir returns the cache directory where builtin agent resources are extracted. Uses $XDG_CACHE_HOME if set, otherwise ~/.cache
func GetLocalAgentsDir ¶
GetLocalAgentsDir returns the path for project-local agents.
func GetUserAgentsDir ¶
GetUserAgentsDir returns the path for user-global agents.
func IsAgentPath ¶ added in v0.0.65
IsAgentPath returns true if the value looks like a filesystem path rather than an agent name. It checks for forward slashes, backslashes (for Windows-style paths, including from WSL/mixed-shell usage), and Windows drive-letter prefixes (e.g., C:\).
func IsBuiltinAgent ¶
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"`
// Skills override for this agent.
// Values: "" (use global config), "all"/"*" (enable all), "none" (disable),
// or comma-separated skill names (e.g. "git,docker").
// When set, overrides the global skills.enabled config for this agent.
// CLI --skills flag takes precedence over this.
Skills string `yaml:"skills,omitempty"`
// Behavior
MaxTurns int `yaml:"max_turns,omitempty"`
Search bool `yaml:"search,omitempty"` // Enable web search tools
// DefaultPrompt is used when agent is invoked without a message
DefaultPrompt string `yaml:"default_prompt,omitempty"`
// Output specifies where to write agent response (deprecated, use OutputTool + OnComplete)
// Valid: "" (stdout), "commit_editmsg" (.git/COMMIT_EDITMSG)
Output string `yaml:"output,omitempty"`
// OutputTool configures a tool for capturing structured output.
// When set, a tool with the configured name is dynamically created
// and added to the agent's enabled tools.
OutputTool OutputToolConfig `yaml:"output_tool,omitempty"`
// OnComplete is a shell command to run with captured output piped to stdin.
// Runs in the git repo root (if in a git repo) or cwd.
// Replaces the hardcoded "output: commit_editmsg" approach.
OnComplete string `yaml:"on_complete,omitempty"`
// 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"`
// AgentsMd controls loading of AGENTS.md hierarchy into the system prompt.
// Values: "auto" (default), "true", "false"
// "auto" loads project instructions if the agent has coding tools (write_file, edit_file, shell)
// "true" always loads, "false" never loads
AgentsMd string `yaml:"agents_md,omitempty"`
// Memory settings
Memory MemoryConfig `yaml:"memory,omitempty"`
// MCP servers to auto-connect
MCP []MCPConfig `yaml:"mcp,omitempty"`
// EnableHandover indicates the agent writes handover documents to the
// XDG handover directory. On /handover the most recently modified .md
// file in that directory is read as zero-cost context for the next agent.
EnableHandover bool `yaml:"enable_handover,omitempty"`
// HandoverMode controls how context is produced on /handover:
// "light" - use last assistant message as handover context (zero cost)
// "file" - read latest .md from the handover directory (zero cost, agent maintains it)
// "script" - run handover_script command line (no shell expansion), use stdout (zero cost)
// "compress" - LLM-driven compression of full conversation
// "" - auto: try file first, fall back to compress
HandoverMode string `yaml:"handover_mode,omitempty"`
// HandoverScript is a command line whose stdout becomes the handover context.
// It is executed directly (without shell expansion). When the agent is the
// handover target, the command runs only after explicit confirmation.
HandoverScript string `yaml:"handover_script,omitempty"`
// GistID for syncing with GitHub Gists (set on export/import)
GistID string `yaml:"gist_id,omitempty"`
// PlatformMessages holds developer messages injected at the start of each
// new conversation session, keyed by platform.
PlatformMessages PlatformMessagesConfig `yaml:"platform_messages,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 ¶
LoadFromEmbedded loads an agent from embedded filesystem data.
func LoadFromPath ¶ added in v0.0.65
LoadFromPath loads an agent from an explicit filesystem path. The path is resolved to absolute. Returns an error if the directory doesn't exist or doesn't contain agent.yaml.
func (*Agent) GetEnabledTools ¶
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 ¶
GetMCPServerNames returns the names of MCP servers to connect.
func (*Agent) HasDisabledList ¶
HasDisabledList returns true if the agent uses a disabled list.
func (*Agent) HasEnabledList ¶
HasEnabledList returns true if the agent uses an explicit enabled list.
func (*Agent) Merge ¶ added in v0.0.42
func (a *Agent) Merge(pref config.AgentPreference)
Merge applies preferences on top of the agent's existing configuration. Non-zero/non-nil values in pref override the agent's defaults.
func (*Agent) ShouldLoadProjectInstructions ¶ added in v0.0.43
ShouldLoadProjectInstructions returns true if this agent should load project instruction files. Uses "auto" logic by default: include if agent has coding tools (write_file, edit_file, shell).
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 CustomToolDef ¶ added in v0.0.90
type CustomToolDef struct {
// Name is the tool name shown to the LLM. Must match ^[a-z][a-z0-9_]*$
// and must not collide with any built-in tool name.
Name string `yaml:"name"`
// Description is the tool description passed to the LLM.
Description string `yaml:"description"`
// Script is the path to the script, relative to the agent directory.
// Subdirectories are allowed (e.g. "scripts/job-status.sh").
Script string `yaml:"script"`
// Input is a JSON Schema (type: object) for the tool's input parameters.
// If omitted, the tool accepts no parameters.
Input map[string]interface{} `yaml:"input,omitempty"`
// TimeoutSeconds is the execution timeout. Default 30, max 300.
TimeoutSeconds int `yaml:"timeout_seconds,omitempty"`
// Env is a map of additional environment variables to set when running the script.
Env map[string]string `yaml:"env,omitempty"`
// Call controls how arguments are passed to the script.
// "" / "args" — named flags: --key value (default)
// "positional" — positional args in schema property order
// "json" — JSON object on stdin
Call string `yaml:"call,omitempty"`
}
CustomToolDef defines a script-backed custom tool declared in agent.yaml.
type IncludeOptions ¶ added in v0.0.84
type IncludeOptions struct {
// BaseDir is used to resolve relative include paths.
BaseDir string
// MaxDepth limits recursive include expansion.
MaxDepth int
// AllowAbsolute allows absolute include paths.
AllowAbsolute bool
}
IncludeOptions controls {{file:...}} expansion behavior.
type MemoryConfig ¶ added in v0.0.105
type MemoryConfig struct {
// InsightsExpansion appends behavioral insights to the resolved system
// prompt for sessions started with this agent. Default false.
InsightsExpansion bool `yaml:"insights_expansion,omitempty"`
// InsightsMaxTokens caps the insight block token budget. Default: 500.
InsightsMaxTokens int `yaml:"insights_max_tokens,omitempty"`
}
MemoryConfig holds memory-related settings for an agent.
type OutputToolConfig ¶ added in v0.0.37
type OutputToolConfig struct {
Name string `yaml:"name"` // Tool name (e.g., "set_commit_message")
Param string `yaml:"param"` // Parameter to capture (default: "content")
Description string `yaml:"description"` // Tool description
}
OutputToolConfig configures a tool for capturing structured output.
func (*OutputToolConfig) IsConfigured ¶ added in v0.0.37
func (c *OutputToolConfig) IsConfigured() bool
IsConfigured returns true if the output tool is configured.
type PlatformMessagesConfig ¶ added in v0.0.136
type PlatformMessagesConfig struct {
Web string `yaml:"web_developer_message,omitempty"`
Telegram string `yaml:"telegram_developer_message,omitempty"`
Chat string `yaml:"chat_developer_message,omitempty"`
Jobs string `yaml:"jobs_developer_message,omitempty"`
}
PlatformMessagesConfig holds per-platform developer messages that are injected at the start of each new conversation session.
func (PlatformMessagesConfig) For ¶ added in v0.0.136
func (p PlatformMessagesConfig) For(platform string) string
For returns the developer message for the given platform name ("web", "telegram", "chat", "jobs"). Returns empty string when no message is configured for that platform.
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 ¶
Get retrieves an agent by name. Resolution order: local > user > search paths > builtin Preferences are applied on top of the loaded agent config.
func (*Registry) List ¶
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.
func (*Registry) ListNames ¶ added in v0.0.43
ListNames returns just the names of available agents without loading full content. This is optimized for completions where only names are needed.
func (*Registry) SetPreferences ¶ added in v0.0.42
func (r *Registry) SetPreferences(prefs map[string]config.AgentPreference)
SetPreferences sets the preference overrides to apply to agents. Call this after creating the registry to configure agent preferences. This also invalidates the cache for any agents that have preferences set, ensuring the new preferences are applied on next Get().
type RegistryConfig ¶
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
// Runtime surface (chat, console, web, telegram, jobs)
Platform string
// Active LLM
Provider string // Current provider name/key
Model string // Current model name
ProviderModel string // Combined provider:model string
// Agent context
ResourceDir string // Directory containing agent resources (for builtin agents)
HandoverDir string // XDG handover directory for the current project
HandoverPath string // Full handover file path (date + random slug)
// 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, handover_dir) 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) WithHandoverDir ¶ added in v0.0.146
func (c TemplateContext) WithHandoverDir(dir string) TemplateContext
WithHandoverDir sets the handover directory for {{handover_dir}} token expansion.
func (TemplateContext) WithHandoverPath ¶ added in v0.0.146
func (c TemplateContext) WithHandoverPath(path string) TemplateContext
WithHandoverPath sets the full handover file path for {{handover_path}} token expansion.
func (TemplateContext) WithLLM ¶ added in v0.0.179
func (c TemplateContext) WithLLM(provider, model string) TemplateContext
WithLLM sets the active provider/model for template expansion.
func (TemplateContext) WithPlatform ¶ added in v0.0.100
func (c TemplateContext) WithPlatform(platform string) TemplateContext
WithPlatform sets the runtime surface for {{platform}} token expansion.
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"`
// Custom is a list of script-backed custom tools declared in agent.yaml
Custom []CustomToolDef `yaml:"custom,omitempty"`
}
ToolsConfig specifies which tools to enable or disable.