Class: Agents::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/agents/definition.rb

Overview

A named sub-agent parsed from a Markdown definition file. YAML frontmatter holds metadata; the Markdown body is the system prompt.

Examples:

Definition file format

---
name: codebase-analyzer
description: Analyzes codebase implementation details.
tools: read_file, bash
model: claude-sonnet-4-5
---

You are a specialist at understanding HOW code works...

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, tools:, prompt:, model: nil, color: nil, max_turns: nil, source_path: "") ⇒ Definition

Returns a new instance of Definition.



45
46
47
48
49
50
51
52
53
54
# File 'lib/agents/definition.rb', line 45

def initialize(name:, description:, tools:, prompt:, model: nil, color: nil, max_turns: nil, source_path: "")
  @name = name
  @description = description
  @tools = tools
  @prompt = prompt
  @model = model
  @color = color
  @max_turns = max_turns
  @source_path = source_path
end

Instance Attribute Details

#colorString? (readonly)

Returns TUI display color (reserved for future use).

Returns:

  • (String, nil)

    TUI display color (reserved for future use)



37
38
39
# File 'lib/agents/definition.rb', line 37

def color
  @color
end

#descriptionString (readonly)

Returns description shown to the LLM in the tool catalog.

Returns:

  • (String)

    description shown to the LLM in the tool catalog



25
26
27
# File 'lib/agents/definition.rb', line 25

def description
  @description
end

#max_turnsInteger? (readonly)

Returns maximum conversation turns (reserved for future use).

Returns:

  • (Integer, nil)

    maximum conversation turns (reserved for future use)



40
41
42
# File 'lib/agents/definition.rb', line 40

def max_turns
  @max_turns
end

#modelString? (readonly)

Returns LLM model override (reserved for future use).

Returns:

  • (String, nil)

    LLM model override (reserved for future use)



34
35
36
# File 'lib/agents/definition.rb', line 34

def model
  @model
end

#nameString (readonly)

Returns unique agent identifier used in spawn_specialist(name: “…”).

Returns:

  • (String)

    unique agent identifier used in spawn_specialist(name: “…”)



22
23
24
# File 'lib/agents/definition.rb', line 22

def name
  @name
end

#promptString (readonly)

Returns system prompt (Markdown body of the definition file).

Returns:

  • (String)

    system prompt (Markdown body of the definition file)



31
32
33
# File 'lib/agents/definition.rb', line 31

def prompt
  @prompt
end

#source_pathString (readonly)

Returns file path this definition was loaded from.

Returns:

  • (String)

    file path this definition was loaded from



43
44
45
# File 'lib/agents/definition.rb', line 43

def source_path
  @source_path
end

#toolsArray<String> (readonly)

Returns tool names available to this agent.

Returns:

  • (Array<String>)

    tool names available to this agent



28
29
30
# File 'lib/agents/definition.rb', line 28

def tools
  @tools
end

Class Method Details

.from_file(path) ⇒ Definition

Parses a Markdown file with YAML frontmatter into a Definition.

Parameters:

  • path (String, Pathname)

    path to the .md file

Returns:

Raises:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/agents/definition.rb', line 61

def self.from_file(path)
  content = File.read(path)
  frontmatter, body = parse_frontmatter(content)

  validate_required_fields!(frontmatter, path)

  new(
    name: frontmatter["name"].to_s.strip,
    description: frontmatter["description"].to_s.strip,
    tools: parse_tools(frontmatter["tools"]),
    prompt: body.strip,
    model: frontmatter["model"]&.to_s&.strip,
    color: frontmatter["color"]&.to_s&.strip,
    max_turns: frontmatter["maxTurns"]&.to_i,
    source_path: path.to_s
  )
end