Module: Soka::Agents::DSLMethods::ClassMethods
- Defined in:
- lib/soka/agents/dsl_methods.rb
Overview
Class methods for DSL
Instance Attribute Summary collapse
-
#_api_key ⇒ Object
Returns the value of attribute _api_key.
-
#_hooks ⇒ Object
Returns the value of attribute _hooks.
-
#_instructions ⇒ Object
Returns the value of attribute _instructions.
-
#_max_iterations ⇒ Object
Returns the value of attribute _max_iterations.
-
#_model ⇒ Object
Returns the value of attribute _model.
-
#_provider ⇒ Object
Returns the value of attribute _provider.
-
#_retry_config ⇒ Object
Returns the value of attribute _retry_config.
-
#_think_in ⇒ Object
Returns the value of attribute _think_in.
-
#_tools ⇒ Object
Returns the value of attribute _tools.
Instance Method Summary collapse
-
#after_action(method_name) ⇒ Object
Register after_action hook.
-
#api_key(key) ⇒ Object
Define API key for the agent.
-
#before_action(method_name) ⇒ Object
Register before_action hook.
- #inherited(subclass) ⇒ Object
-
#instructions(text_or_method) ⇒ Object
Define custom instructions (system prompt) for the agent.
-
#max_iterations(num) ⇒ Object
Define maximum iterations for the agent.
-
#model(model) ⇒ Object
Define model for the agent.
-
#on_error(method_name) ⇒ Object
Register on_error hook.
-
#provider(provider) ⇒ Object
Define provider for the agent.
-
#retry_config { ... } ⇒ Object
Configure retry behavior.
-
#think_in(language) ⇒ Object
Define thinking language for the agent.
-
#tool(tool_class_or_name, description_or_options = nil, options = {}) ⇒ Object
Register a tool for the agent.
-
#tools(*tool_classes) ⇒ Object
Register multiple tools at once.
Instance Attribute Details
#_api_key ⇒ Object
Returns the value of attribute _api_key.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _api_key @_api_key end |
#_hooks ⇒ Object
Returns the value of attribute _hooks.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _hooks @_hooks end |
#_instructions ⇒ Object
Returns the value of attribute _instructions.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _instructions @_instructions end |
#_max_iterations ⇒ Object
Returns the value of attribute _max_iterations.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _max_iterations @_max_iterations end |
#_model ⇒ Object
Returns the value of attribute _model.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _model @_model end |
#_provider ⇒ Object
Returns the value of attribute _provider.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _provider @_provider end |
#_retry_config ⇒ Object
Returns the value of attribute _retry_config.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _retry_config @_retry_config end |
#_think_in ⇒ Object
Returns the value of attribute _think_in.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _think_in @_think_in end |
#_tools ⇒ Object
Returns the value of attribute _tools.
13 14 15 |
# File 'lib/soka/agents/dsl_methods.rb', line 13 def _tools @_tools end |
Instance Method Details
#after_action(method_name) ⇒ Object
Register after_action hook
100 101 102 |
# File 'lib/soka/agents/dsl_methods.rb', line 100 def after_action(method_name) @_hooks[:after_action] << method_name end |
#api_key(key) ⇒ Object
Define API key for the agent
37 38 39 |
# File 'lib/soka/agents/dsl_methods.rb', line 37 def api_key(key) @_api_key = key end |
#before_action(method_name) ⇒ Object
Register before_action hook
94 95 96 |
# File 'lib/soka/agents/dsl_methods.rb', line 94 def before_action(method_name) @_hooks[:before_action] << method_name end |
#inherited(subclass) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/soka/agents/dsl_methods.rb', line 16 def inherited(subclass) super subclass._tools = [] subclass._hooks = { before_action: [], after_action: [], on_error: [] } subclass._retry_config = {} end |
#instructions(text_or_method) ⇒ Object
Define custom instructions (system prompt) for the agent
53 54 55 |
# File 'lib/soka/agents/dsl_methods.rb', line 53 def instructions(text_or_method) @_instructions = text_or_method end |
#max_iterations(num) ⇒ Object
Define maximum iterations for the agent
43 44 45 |
# File 'lib/soka/agents/dsl_methods.rb', line 43 def max_iterations(num) @_max_iterations = num end |
#model(model) ⇒ Object
Define model for the agent
31 32 33 |
# File 'lib/soka/agents/dsl_methods.rb', line 31 def model(model) @_model = model end |
#on_error(method_name) ⇒ Object
Register on_error hook
106 107 108 |
# File 'lib/soka/agents/dsl_methods.rb', line 106 def on_error(method_name) @_hooks[:on_error] << method_name end |
#provider(provider) ⇒ Object
Define provider for the agent
25 26 27 |
# File 'lib/soka/agents/dsl_methods.rb', line 25 def provider(provider) @_provider = provider end |
#retry_config { ... } ⇒ Object
Configure retry behavior
86 87 88 89 90 |
# File 'lib/soka/agents/dsl_methods.rb', line 86 def retry_config(&) config = Agents::RetryConfig.new config.instance_eval(&) @_retry_config = config.to_h end |
#think_in(language) ⇒ Object
Define thinking language for the agent
59 60 61 |
# File 'lib/soka/agents/dsl_methods.rb', line 59 def think_in(language) @_think_in = language.to_s end |
#tool(tool_class_or_name, description_or_options = nil, options = {}) ⇒ Object
Register a tool for the agent
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/soka/agents/dsl_methods.rb', line 67 def tool(tool_class_or_name, = nil, = {}) if tool_class_or_name.is_a?(Symbol) || tool_class_or_name.is_a?(String) # Function tool - expects description and options add_function_tool(tool_class_or_name, , ) else # Class tool - second parameter is options opts = .is_a?(Hash) ? : add_class_tool(tool_class_or_name, opts) end end |
#tools(*tool_classes) ⇒ Object
Register multiple tools at once
80 81 82 |
# File 'lib/soka/agents/dsl_methods.rb', line 80 def tools(*tool_classes) tool_classes.each { |tool_class| tool(tool_class) } end |