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.
-
.option(key, value = :__no_value__) ⇒ Object
Set an arbitrary Session option.
-
.parallel_tools(value = :__no_value__) ⇒ Object
Set or get parallel tool execution flag.
-
.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.
130 131 132 133 |
# File 'lib/ask/agent/definition.rb', line 130 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.
121 122 123 124 125 126 127 |
# File 'lib/ask/agent/definition.rb', line 121 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 |
.option(key, value = :__no_value__) ⇒ Object
Set an arbitrary Session option. Accepts any key that Ask::Agent::Session.new understands.
option :temperature, 0.7
option :reflector, true
option :telemetry, false
91 92 93 94 95 96 97 98 99 |
# File 'lib/ask/agent/definition.rb', line 91 def option(key, value = :__no_value__) if value == :__no_value__ _config[:options] ||= {} _config[:options][key] else _config[:options] ||= {} _config[:options][key] = value end end |
.parallel_tools(value = :__no_value__) ⇒ Object
Set or get parallel tool execution flag.
77 78 79 80 81 82 83 |
# File 'lib/ask/agent/definition.rb', line 77 def parallel_tools(value = :__no_value__) if value == :__no_value__ _config.key?(:parallel_tools) ? _config[:parallel_tools] : true else _config[:parallel_tools] = 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.
111 112 113 114 115 116 117 |
# File 'lib/ask/agent/definition.rb', line 111 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.
102 103 104 105 106 107 108 |
# File 'lib/ask/agent/definition.rb', line 102 def tools(*values) if values.any? _config[:tools] = values else _config[:tools] end end |