Class: Ask::Agent::Definition
- Inherits:
-
Object
- Object
- Ask::Agent::Definition
- Defined in:
- lib/ask/agent/definition.rb
Overview
Declarative agent definition backed by a file convention.
Subclass Definition inside an agent.rb file under agents/<name>/
or app/agents/<name>/. The directory name becomes the agent name.
Instructions load automatically from a sibling instructions.md.
Class Attribute Summary collapse
-
.subclasses ⇒ Object
readonly
All subclasses that have been loaded, in definition order.
Class Method Summary collapse
-
._config ⇒ Hash
The raw config hash for this definition.
- .inherited(subclass) ⇒ Object
-
.instructions_content ⇒ Object
Contents of the instructions.md file, or nil.
-
.instructions_path ⇒ Object
Path to instructions.md relative to this definition's directory.
-
.max_turns(value = :__no_value__) ⇒ Object
Set or get max turns for the session.
-
.model(value = :__no_value__) ⇒ Object
Set or get the model identifier.
-
.provider(value = :__no_value__) ⇒ Object
Set or get the provider override.
-
.schedule(value = :__no_value__) ⇒ Object
Set a cron or interval schedule for recurring runs.
-
.tools(*values) ⇒ Object
Set tool symbols or classes.
Class Attribute Details
.subclasses ⇒ Object (readonly)
All subclasses that have been loaded, in definition order.
28 29 30 |
# File 'lib/ask/agent/definition.rb', line 28 def subclasses @subclasses end |
Class Method Details
._config ⇒ Hash
Returns the raw config hash for this definition.
45 46 47 |
# File 'lib/ask/agent/definition.rb', line 45 def _config @_config ||= { tools: [] } end |
.inherited(subclass) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ask/agent/definition.rb', line 30 def inherited(subclass) @subclasses << subclass subclass.instance_variable_set(:@_config, { tools: [] }) # Auto-detect the directory from the file where this class is defined # caller(1) is the file containing the `class ... < Definition` line path = caller(1)&.first&.sub(/:.*/, "") # strip line number if path && File.basename(path) == "agent.rb" subclass._config[:dir] = File.dirname(path) end super end |
.instructions_content ⇒ Object
Contents of the instructions.md file, or nil.
105 106 107 108 |
# File 'lib/ask/agent/definition.rb', line 105 def instructions_content path = instructions_path path ? File.read(path) : nil end |
.instructions_path ⇒ Object
Path to instructions.md relative to this definition's directory. Returns nil if no instructions file exists.
96 97 98 99 100 101 102 |
# File 'lib/ask/agent/definition.rb', line 96 def instructions_path dir = _config[:dir] return nil unless dir path = File.join(dir, "instructions.md") File.exist?(path) ? path : nil end |
.max_turns(value = :__no_value__) ⇒ Object
Set or get max turns for the session.
68 69 70 71 72 73 74 |
# File 'lib/ask/agent/definition.rb', line 68 def max_turns(value = :__no_value__) if value == :__no_value__ _config[:max_turns] else _config[:max_turns] = value end end |
.model(value = :__no_value__) ⇒ Object
Set or get the model identifier.
50 51 52 53 54 55 56 |
# File 'lib/ask/agent/definition.rb', line 50 def model(value = :__no_value__) if value == :__no_value__ _config[:model] else _config[:model] = value end end |
.provider(value = :__no_value__) ⇒ Object
Set or get the provider override.
59 60 61 62 63 64 65 |
# File 'lib/ask/agent/definition.rb', line 59 def provider(value = :__no_value__) if value == :__no_value__ _config[:provider] else _config[:provider] = value end end |
.schedule(value = :__no_value__) ⇒ Object
Set a cron or interval schedule for recurring runs.
86 87 88 89 90 91 92 |
# File 'lib/ask/agent/definition.rb', line 86 def schedule(value = :__no_value__) if value == :__no_value__ _config[:schedule] else _config[:schedule] = value end end |
.tools(*values) ⇒ Object
Set tool symbols or classes.
77 78 79 80 81 82 83 |
# File 'lib/ask/agent/definition.rb', line 77 def tools(*values) if values.any? _config[:tools] = values else _config[:tools] end end |