Documentation
¶
Overview ¶
Package agents loads the agents a workspace offers: the built-in ones and Markdown files with YAML frontmatter from ~/.blitz/agents, the project's .agents/agents (prompt text, loaded without trust; a project's agent may loosen the permission mode only once the project is trusted) and enabled plugins, each a name, a description, a system prompt, the tools it may use and optionally its own model (spec_014_agents).
Index ¶
- Variables
- func Delete(dir, name string) error
- func DeleteFile(dir, path string) error
- func Save(dir string, spec *AgentSpec, previous string, builtin func(string) bool) (path string, problems []string, err error)
- func ValidName(name string) bool
- type AgentMetadata
- type AgentSpec
- type File
- type Registry
- func (r *Registry) External() int
- func (r *Registry) Get(name string) (*AgentSpec, bool)
- func (r *Registry) Invalidate()
- func (r *Registry) IsBuiltin(name string) bool
- func (r *Registry) List() []*AgentSpec
- func (r *Registry) LoadExternalAgents(dirs ...string) error
- func (r *Registry) Lock(dirs ...string)
- func (r *Registry) Refresh() (bool, error)
- func (r *Registry) SwitchOff(names []string)
Constants ¶
This section is empty.
Variables ¶
var AgencyLevels = []string{"low", "medium", "high", "extreme"}
AgencyLevels are the agency levels an agent may declare.
Functions ¶
func DeleteFile ¶
DeleteFile removes path, an agent file in dir (or below it), whether or not it parses.
func Save ¶
func Save(dir string, spec *AgentSpec, previous string, builtin func(string) bool) (path string, problems []string, err error)
Save writes spec to its file in dir: in place of previous's file when previous names one (a rename, or "" for a new agent), else dir/<name>.md. What's wrong with spec comes back as problems, with nothing written.
Types ¶
type AgentMetadata ¶
type AgentMetadata struct {
Name string `yaml:"name"`
DisplayName string `yaml:"display_name,omitempty"`
Description string `yaml:"description"`
Tools []string `yaml:"tools"`
DefaultModel string `yaml:"default_model,omitempty"`
AgencyLevel string `yaml:"agency_level,omitempty"`
// PermissionMode is the mode it runs in through invoke_agent: default,
// plan, accept-edits, dont-ask or bypass ("": the workspace's). A
// project's agent may only tighten until the project is trusted, and
// bypass needs the OS sandbox.
PermissionMode string `yaml:"permission_mode,omitempty"`
// MaxTurns caps its model calls through invoke_agent (0: the caller's
// budget, or a background task's).
MaxTurns int `yaml:"max_turns,omitempty"`
// Background makes invoke_agent run it in the background unless the
// call says otherwise.
Background bool `yaml:"background,omitempty"`
// Isolation "worktree" runs it in its own git worktree and branch;
// it needs Background.
Isolation string `yaml:"isolation,omitempty"`
// The model settings it runs with, over the model's own
// ([model_settings]) and the session's effort; unset leaves those.
Temperature *float64 `yaml:"temperature,omitempty"`
TopP *float64 `yaml:"top_p,omitempty"`
MaxTokens *int `yaml:"max_tokens,omitempty"`
Effort string `yaml:"effort,omitempty"`
ThinkingBudget *int `yaml:"thinking_budget,omitempty"`
// Lock and Groups are how an organization's catalog applies the
// agent (spec_053 EN-30); read by the catalog, accepted here.
Lock string `yaml:"lock,omitempty"`
Groups []string `yaml:"groups,omitempty"`
}
AgentMetadata holds frontmatter metadata defined in the markdown header.
func (AgentMetadata) Check ¶
func (m AgentMetadata) Check() error
Check returns what keeps the metadata from loading, or nil.
func (AgentMetadata) ModelSettings ¶
func (m AgentMetadata) ModelSettings() (config.ModelSettings, bool)
ModelSettings returns the model settings the agent sets, and whether it sets any.
type AgentSpec ¶
type AgentSpec struct {
AgentMetadata
SystemPrompt string
// Path is the file it came from ("" for a built-in agent).
Path string
}
AgentSpec represents a parsed agent specification with frontmatter and markdown body.
func ParseMarkdownSpec ¶
ParseMarkdownSpec parses a markdown file containing YAML frontmatter. A key it doesn't know is an error: a misspelt permission_mode would leave the agent in the workspace's mode.
func (*AgentSpec) InterpolatePrompt ¶
InterpolatePrompt fills in the agency rules for agencyLevel ("" is high).
type File ¶
type File struct {
Path string
// Spec is what it defines; nil when it doesn't parse.
Spec *AgentSpec
// Problem is why it doesn't load ("" when it does).
Problem string
}
File is one agent file in a folder.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages discovered and built-in agents.
func NewRegistry ¶
NewRegistry creates a new Registry and loads built-in embedded agent specs.
func (*Registry) External ¶ added in v0.6.5
External counts the agents loaded from files (not built in).
func (*Registry) Invalidate ¶ added in v0.6.5
func (r *Registry) Invalidate()
Invalidate makes the next Refresh load the external agents again whether or not their files look changed (/reload): an edit that kept a file's size and time is seen too.
func (*Registry) LoadExternalAgents ¶
LoadExternalAgents scans directories for user-defined .md agent specifications. A leading "~" is expanded. External specs may add new agents but may not replace built-in ones, since that would let a directory silently swap the system prompt and tool list of a trusted persona. Rejected or unparsable specs are reported in the returned (joined) error; valid ones are still loaded. The directories are remembered for Refresh.
func (*Registry) Lock ¶ added in v0.9.1
Lock marks dirs as the organization's locked agent folders (spec_053 EN-31): an agent loaded from one can't be replaced by a later folder's of the same name, such as a plugin's; that one is reported instead. Call it before loading.