agents

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSystemPrompt

func BuildSystemPrompt(persona *Persona, projectContext string) string

BuildSystemPrompt constructs a full system prompt by combining the persona's configuration with project-specific context.

func DefaultDir

func DefaultDir() string

DefaultDir returns the user's agent directory.

func ParseAgentsYAML

func ParseAgentsYAML(data []byte) (map[string]YAMLAgentSpec, error)

ParseAgentsYAML parses the contents of an agents.yaml file.

func ParseTasksYAML

func ParseTasksYAML(data []byte) (map[string]YAMLTaskSpec, error)

ParseTasksYAML parses the contents of a tasks.yaml file.

func PersonasFromYAML

func PersonasFromYAML(dir string) (map[string]*Persona, error)

PersonasFromYAML loads agents.yaml from dir and returns the resulting personas keyed by name. Returns an empty map (not an error) when the file is absent.

func RenderPersonaFile

func RenderPersonaFile(persona *Persona) string

RenderPersonaFile generates a markdown file with YAML frontmatter from a Persona.

Types

type Agent

type Agent struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Model       string `json:"model,omitempty"`
	Prompt      string `json:"prompt"`
	FilePath    string `json:"file_path"`
}

Agent is a user-defined persona with a custom system prompt. Stored as markdown files with YAML frontmatter in Hawk user state.

func Get

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

Get finds an agent by name from all known directories.

func ListAll

func ListAll() ([]*Agent, error)

ListAll discovers all agent definitions from Hawk user state.

func Load

func Load(path string) (*Agent, error)

Load reads an agent definition from a markdown file. Format:

---
name: reviewer
description: Code review specialist
model: inherit
---
You are a code reviewer...

func Parse

func Parse(content, filePath string) (*Agent, error)

Parse extracts agent metadata and prompt from markdown content.

type Persona

type Persona struct {
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	Model         string   `json:"model"`
	Provider      string   `json:"provider"`
	SystemPrompt  string   `json:"system_prompt"`
	Tools         []string `json:"tools"`
	ExcludedTools []string `json:"excluded_tools"`
	// ReadOnly declares that this persona must never mutate the workspace. It is
	// a machine-readable contract (stronger than listing Edit/Write in
	// ExcludedTools, since it also forbids mutation via Bash): orchestrators
	// should run a ReadOnly persona with a read-only tool registry. Used by the
	// validation half of an implement-then-validate agent pair.
	ReadOnly           bool             `json:"read_only,omitempty"`
	Temperature        float64          `json:"temperature"`
	MaxTokens          int              `json:"max_tokens"`
	Expertise          []string         `json:"expertise"`
	CommunicationStyle string           `json:"communication_style"`
	Rules              []string         `json:"rules"`
	Examples           []PersonaExample `json:"examples"`
	CreatedAt          time.Time        `json:"created_at"`
	UsageCount         int              `json:"usage_count"`
	SuccessRate        float64          `json:"success_rate"`
	// Color is an optional display color for the persona (e.g. "blue",
	// "#ff8800"), used by UIs to distinguish agents. Mirrors Claude Code's
	// per-agent color frontmatter field.
	Color string `json:"color,omitempty"`
	// Hooks maps lifecycle event names (e.g. "pre_run", "post_run") to a
	// shell command or handler string to invoke for this agent. Mirrors
	// Claude Code's per-agent hooks.
	Hooks PersonaHooks `json:"hooks,omitempty"`
}

Persona represents an enhanced agent definition with specific skills, model preferences, and behavioral configuration.

func BuiltinPersonas

func BuiltinPersonas() []*Persona

BuiltinPersonas returns the set of built-in personas that are auto-created on first run.

func CavecrewPersonas

func CavecrewPersonas() []*Persona

CavecrewPersonas returns just the three cavecrew personas (investigator, builder, reviewer) built into GrayCode Hawk. These are a strict, format-driven subset of the full BuiltinPersonas list; callers that want only the cavecrew subset can use this function instead of BuiltinPersonas.

func ParsePersonaFile

func ParsePersonaFile(path string) (*Persona, error)

ParsePersonaFile reads a persona definition from a markdown file with YAML frontmatter.

type PersonaExample

type PersonaExample struct {
	Input   string `json:"input"`
	Output  string `json:"output"`
	Context string `json:"context"`
}

PersonaExample stores an input/output example for few-shot prompting.

type PersonaHooks

type PersonaHooks map[string]string

PersonaHooks maps a lifecycle event name to the command/handler to run. Common keys include "pre_run", "post_run", and "on_error", but any key is permitted so the set can grow without breaking the loader.

type PersonaRegistry

type PersonaRegistry struct {
	Personas map[string]*Persona
	Dir      string
	// contains filtered or unexported fields
}

PersonaRegistry manages a collection of personas loaded from disk.

func NewPersonaRegistry

func NewPersonaRegistry(dir string) *PersonaRegistry

NewPersonaRegistry creates a new registry with the given storage directory. If dir is empty, it defaults to Hawk's user state agents directory.

func (*PersonaRegistry) Create

func (r *PersonaRegistry) Create(persona *Persona) error

Create saves a new persona to disk and adds it to the registry.

func (*PersonaRegistry) Delete

func (r *PersonaRegistry) Delete(name string) error

Delete removes a persona from the registry and disk.

func (*PersonaRegistry) EnsureBuiltins

func (r *PersonaRegistry) EnsureBuiltins() error

EnsureBuiltins creates the built-in personas in the directory if they do not exist.

func (*PersonaRegistry) EnsureCavecrew

func (r *PersonaRegistry) EnsureCavecrew() error

EnsureCavecrew creates just the three cavecrew personas (investigator, builder, reviewer) if they do not exist. Callers who want only the compact-format-driven subset can call this instead of EnsureBuiltins.

Cavecrew personas are already part of BuiltinPersonas, so calling this is a no-op after EnsureBuiltins has run.

func (*PersonaRegistry) Get

func (r *PersonaRegistry) Get(name string) (*Persona, error)

Get retrieves a persona by name.

func (*PersonaRegistry) List

func (r *PersonaRegistry) List() []*Persona

List returns all personas sorted by name.

func (*PersonaRegistry) LoadAll

func (r *PersonaRegistry) LoadAll() error

LoadAll reads all .md files from the registry directory and populates the Personas map.

func (*PersonaRegistry) LoadYAMLInto

func (r *PersonaRegistry) LoadYAMLInto(dir string, overwrite bool) (int, error)

LoadYAMLInto loads CrewAI-style agents.yaml from dir and merges the resulting personas into the registry. Existing personas with the same name are NOT overwritten unless overwrite is true, so markdown personas take precedence by default. Returns the number of personas added.

func (*PersonaRegistry) SelectPersona

func (r *PersonaRegistry) SelectPersona(task string) *Persona

SelectPersona automatically selects the best persona for a given task by matching keywords in the task description against persona expertise.

type YAMLAgentSpec

type YAMLAgentSpec struct {
	Role      string   `yaml:"role"`
	Goal      string   `yaml:"goal"`
	Backstory string   `yaml:"backstory"`
	LLM       string   `yaml:"llm"`
	Model     string   `yaml:"model"` // alias for LLM
	Provider  string   `yaml:"provider"`
	Tools     []string `yaml:"tools"`
}

YAMLAgentSpec is the CrewAI-style description of a single agent. All fields are optional so partially specified files still load.

func (YAMLAgentSpec) ToPersona

func (s YAMLAgentSpec) ToPersona(name string) *Persona

ToPersona converts a CrewAI-style YAML agent spec into a Persona. The agent key from the YAML map becomes the persona Name. role/goal/backstory are assembled into a SystemPrompt mirroring CrewAI's prompt template.

type YAMLConfig

type YAMLConfig struct {
	Agents map[string]YAMLAgentSpec
	Tasks  map[string]YAMLTaskSpec
}

YAMLConfig is the parsed result of loading agents.yaml and tasks.yaml.

func LoadYAMLConfig

func LoadYAMLConfig(dir string) (*YAMLConfig, error)

LoadYAMLConfig loads agents.yaml and tasks.yaml from dir. Missing files are treated as empty (not an error); only malformed YAML is reported.

type YAMLTaskSpec

type YAMLTaskSpec struct {
	Description    string   `yaml:"description"`
	ExpectedOutput string   `yaml:"expected_output"`
	Agent          string   `yaml:"agent"`
	Tools          []string `yaml:"tools"`
}

YAMLTaskSpec is the CrewAI-style description of a single task.

Jump to

Keyboard shortcuts

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