# frozen_string_literal: true module Ad module AgentArchitecture module Dsl # DSL for defining agent workflows class AgentWorkflowDsl def self.create(name:, &block) new(name).tap do |dsl| dsl.instance_eval(&block) if block_given? end end def initialize(name) @workflow = { name: name, sections: [], attributes: {}, prompts: [] } @current_section_order = 1 end def attributes(&block) instance_eval(&block) if block_given? end def attribute(name, type:, is_array: false) @workflow[:attributes][name] = { name: name, type: type, is_array: is_array } end def prompts(&block) instance_eval(&block) if block_given? end def define_prompt(name, path: nil, content: nil) @workflow[:prompts] << { name: name, path: path, content: content } end def section(name:, &block) @current_step_order = 1 @current_section = { name: name, order: @current_section_order, steps: [] } @current_section_order += 1 instance_eval(&block) if block_given? @workflow[:sections] << @current_section end def step(name:, &block) @current_step = { name: name, order: @current_step_order, input_attributes: [], output_attributes: [] } @current_step_order += 1 instance_eval(&block) if block_given? @current_section[:steps] << @current_step end def input(attr_name, **_opts) @current_step[:input_attributes] << attr_name end def output(attr_name, **_opts) @current_step[:output_attributes] << attr_name end def prompt(prompt_text, **_opts) @current_step[:prompt] = prompt_text end def save Ad::AgentArchitecture::Dsl::Actions::SaveDatabase.new(@workflow).save self end def save_json(file_name: nil) full_file_name = file_name || 'workflow.json' Ad::AgentArchitecture::Dsl::Actions::SaveJson.new(@workflow).save(full_file_name) self end def save_yaml(file_name: nil) full_file_name = file_name || 'workflow.yaml' Ad::AgentArchitecture::Dsl::Actions::SaveYaml.new(@workflow).save(full_file_name) self end end end end end