ad-agent_architecture 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1afc432b8e4a84cec6f099987e20ccb1abd19b278a1f299fdd3cd822e47b6f2
4
- data.tar.gz: fd1b6e9054740f005c083712e3cd67b1872cc0cd8d66eadaa2c9541fb3f33c9c
3
+ metadata.gz: 2e62425f0ffeff140581be7741ce8b429fb9437a196294e071d017e343894562
4
+ data.tar.gz: b7da8713c09d8179f840a676787aac6608143fde09a112fbe683c9205e9a37d2
5
5
  SHA512:
6
- metadata.gz: 7af0666287aaef19e10bc414c160066ff2ab0dde2f55f2ae758790454028bccc5bb33ee48fb1ff63ca307a98ab25a82a16a896d2dbf256090151870519e5cb78
7
- data.tar.gz: ae03bbcc49b5f4a0f467852a6f2c411c5d45484ba86eeac3251f75ce97379b2f04e8790530248ad997e5b8fee776174c5ef6ec36b128d89dfc693c52e09de874
6
+ metadata.gz: 9e11fffa978aa478142fe2a540c08c2917aa9a169ab0c19f35a19ea449fb7d9a6b06ddbce72a58b489cd50a367cd2e2dd571622f818a14ad63813a770c931626
7
+ data.tar.gz: 733bf3314271fa108de844ffc4fb2189bb7d77742bbfae31e2316b2883995eb2bc21d2888b49da7954db0865bf9cb9c226edce7cc4bde490f4fda535f206f222
data/.rubocop.yml CHANGED
@@ -15,6 +15,7 @@ AllCops:
15
15
  - ".builders/**/*"
16
16
  - "spec/samples/**/*"
17
17
  - "lib/ad/agent_architecture/database/*"
18
+ - "spec/usecases/**/*"
18
19
 
19
20
  Metrics/BlockLength:
20
21
  Exclude:
@@ -116,4 +117,13 @@ RSpec/NamedSubject:
116
117
 
117
118
  RSpec/ExampleLength:
118
119
  Exclude:
119
- - "**/spec/**/*"
120
+ - "**/spec/**/*"
121
+
122
+ RSpec/MultipleExpectations:
123
+ Max: 3
124
+ Exclude:
125
+ - "spec/ad/agent_architecture/dsl/actions/save_database_spec.rb"
126
+
127
+ Metrics/CyclomaticComplexity:
128
+ Exclude:
129
+ - "lib/ad/agent_architecture/dsl/actions/save_database.rb"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [0.0.10](https://github.com/appydave/ad-agent_architecture/compare/v0.0.9...v0.0.10) (2024-06-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * refactor DSL to use component DSLs ([597050a](https://github.com/appydave/ad-agent_architecture/commit/597050ad727f1aaf8eb3e6589cf1c618f41499e7))
7
+
8
+ ## [0.0.9](https://github.com/appydave/ad-agent_architecture/compare/v0.0.8...v0.0.9) (2024-06-29)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add save, save_json, save_yaml and better report support ([4350628](https://github.com/appydave/ad-agent_architecture/commit/4350628f95b06a5df3bac3432f52aa560c7699f5))
14
+ * add save, save_json, save_yaml and better report support ([9a7238a](https://github.com/appydave/ad-agent_architecture/commit/9a7238a0102e40a6e603a7a82757ff7c684ab374))
15
+
1
16
  ## [0.0.8](https://github.com/appydave/ad-agent_architecture/compare/v0.0.7...v0.0.8) (2024-06-29)
2
17
 
3
18
 
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :development, :test do
9
9
  gem 'guard-bundler'
10
10
  gem 'guard-rspec'
11
11
  gem 'guard-rubocop'
12
+ gem 'guard-shell'
12
13
  gem 'rake'
13
14
  gem 'rake-compiler', require: false
14
15
  gem 'rspec', '~> 3.0'
data/Guardfile CHANGED
@@ -27,4 +27,10 @@ group :green_pass_then_cop, halt_on_fail: true do
27
27
  watch(/{.+\.rb$/)
28
28
  watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
29
  end
30
+
31
+ guard :shell do
32
+ watch(%r{^spec/usecases/.+\.rbx$}) do |m|
33
+ `ruby -r ./spec/usecases/dsl_initialize.rb #{m[0]}`
34
+ end
35
+ end
30
36
  end
@@ -69,6 +69,16 @@ module Ad
69
69
  foreign_key :attribute_id, :attributes
70
70
  end
71
71
 
72
+ db.create_table :prompts do
73
+ primary_key :id
74
+ String :name, null: false
75
+ String :path, null: true
76
+ String :content, null: true
77
+ foreign_key :workflow_id, :workflows
78
+ end
79
+
80
+ # Workflow runs workflows that are executed
81
+
72
82
  db.create_table :workflow_runs do
73
83
  primary_key :id
74
84
  foreign_key :workflow_id, :workflows
@@ -10,6 +10,7 @@ module Ad
10
10
  one_to_many :sections, class: 'Ad::AgentArchitecture::Database::Section'
11
11
  one_to_many :attributes, class: 'Ad::AgentArchitecture::Database::Attribute'
12
12
  one_to_many :workflow_runs, class: 'Ad::AgentArchitecture::Database::WorkflowRun'
13
+ one_to_many :prompts, class: 'Ad::AgentArchitecture::Database::Prompt'
13
14
  end
14
15
 
15
16
  # Section model represents a section entity in the database.
@@ -46,6 +47,10 @@ module Ad
46
47
  many_to_one :attribute, class: 'Ad::AgentArchitecture::Database::Attribute'
47
48
  end
48
49
 
50
+ class Prompt < Sequel::Model
51
+ many_to_one :workflow, class: 'Ad::AgentArchitecture::Database::Workflow'
52
+ end
53
+
49
54
  # WorkflowRun model represents a workflow run entity in the database.
50
55
  class WorkflowRun < Sequel::Model
51
56
  many_to_one :workflow, class: 'Ad::AgentArchitecture::Database::Workflow'
@@ -24,6 +24,13 @@ module Ad
24
24
 
25
25
  attribute_map = attribute_records.to_h { |ar| [ar.name.to_sym, ar] }
26
26
 
27
+ # Save prompts
28
+ @workflow_hash[:prompts].each_value do |prompt|
29
+ Ad::AgentArchitecture::Database::Prompt.create(
30
+ name: prompt[:name], path: prompt[:path], content: prompt[:content], workflow: workflow_record
31
+ )
32
+ end
33
+
27
34
  # Save sections and steps
28
35
  @workflow_hash[:sections].each do |section|
29
36
  section_record = Ad::AgentArchitecture::Database::Section.create(
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for defining the agent DSL
7
+ class AgentDsl
8
+ attr_reader :workflow
9
+
10
+ def self.create(name:, &block)
11
+ new(name).tap do |dsl|
12
+ dsl.instance_eval(&block) if block_given?
13
+ end
14
+ end
15
+
16
+ def initialize(name)
17
+ @workflow = WorkflowDsl.new(name)
18
+ end
19
+
20
+ def attributes(&block)
21
+ @workflow.attributes(&block)
22
+ end
23
+
24
+ def prompts(&block)
25
+ @workflow.prompts(&block)
26
+ end
27
+
28
+ def section(name:, &block)
29
+ @workflow.section(name: name, &block)
30
+ end
31
+
32
+ def save
33
+ Ad::AgentArchitecture::Dsl::Actions::SaveDatabase.new(@workflow.workflow).save
34
+
35
+ self
36
+ end
37
+
38
+ def save_json(file_name = nil)
39
+ full_file_name = file_name || 'workflow.json'
40
+ Ad::AgentArchitecture::Dsl::Actions::SaveJson.new(@workflow.workflow).save(full_file_name)
41
+
42
+ self
43
+ end
44
+
45
+ def save_yaml(file_name = nil)
46
+ full_file_name = file_name || 'workflow.yaml'
47
+ Ad::AgentArchitecture::Dsl::Actions::SaveYaml.new(@workflow.workflow).save(full_file_name)
48
+
49
+ self
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -12,7 +12,7 @@ module Ad
12
12
  end
13
13
 
14
14
  def initialize(name)
15
- @workflow = { name: name, sections: [], attributes: {} }
15
+ @workflow = { name: name, sections: [], attributes: {}, prompts: [] }
16
16
  @current_section_order = 1
17
17
  end
18
18
 
@@ -24,6 +24,14 @@ module Ad
24
24
  @workflow[:attributes][name] = { name: name, type: type, is_array: is_array }
25
25
  end
26
26
 
27
+ def prompts(&block)
28
+ instance_eval(&block) if block_given?
29
+ end
30
+
31
+ def define_prompt(name, path: nil, content: nil)
32
+ @workflow[:prompts] << { name: name, path: path, content: content }
33
+ end
34
+
27
35
  def section(name:, &block)
28
36
  @current_step_order = 1
29
37
  @current_section = { name: name, order: @current_section_order, steps: [] }
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for defining the attributes of a workflow
7
+ class AttributeDsl
8
+ def initialize(attributes)
9
+ @attributes = attributes
10
+ end
11
+
12
+ def attribute(name, type:, is_array: false)
13
+ @attributes[name] = { name: name, type: type, is_array: is_array }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for defining the prompts of a workflow
7
+ class PromptDsl
8
+ def initialize(prompts)
9
+ @prompts = prompts
10
+ end
11
+
12
+ def prompt(name, path: nil, content: nil)
13
+ @prompts[name] = { name: name, path: path, content: content }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for creating a section in the workflow
7
+ class SectionDsl
8
+ def initialize(name, order, sections)
9
+ @section = { name: name, order: order, steps: [] }
10
+ @sections = sections
11
+ @current_step_order = 1
12
+ @sections << @section
13
+ end
14
+
15
+ def step(name:, &block)
16
+ StepDsl.new(name, @current_step_order, @section[:steps]).instance_eval(&block)
17
+ @current_step_order += 1
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for defining the steps of a section
7
+ class StepDsl
8
+ def initialize(name, order, steps)
9
+ @step = { name: name, order: order, input_attributes: [], output_attributes: [], prompt: '' }
10
+ @steps = steps
11
+ @steps << @step
12
+ end
13
+
14
+ def input(attr_name, **_opts)
15
+ @step[:input_attributes] << attr_name
16
+ end
17
+
18
+ def output(attr_name, **_opts)
19
+ @step[:output_attributes] << attr_name
20
+ end
21
+
22
+ def prompt(prompt_text, **_opts)
23
+ @step[:prompt] = prompt_text
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ad
4
+ module AgentArchitecture
5
+ module Dsl
6
+ # This class is responsible for defining the workflow DSL
7
+ class WorkflowDsl
8
+ attr_reader :workflow
9
+
10
+ def initialize(name)
11
+ @workflow = { name: name, sections: [], attributes: {}, prompts: {} }
12
+ @current_section_order = 1
13
+ end
14
+
15
+ def attributes(&block)
16
+ dsl = AttributeDsl.new(@workflow[:attributes])
17
+ dsl.instance_eval(&block) if block_given?
18
+ end
19
+
20
+ def prompts(&block)
21
+ dsl = PromptDsl.new(@workflow[:prompts])
22
+ dsl.instance_eval(&block) if block_given?
23
+ end
24
+
25
+ def section(name:, &block)
26
+ dsl = SectionDsl.new(name, @current_section_order, @workflow[:sections])
27
+ dsl.instance_eval(&block) if block_given?
28
+ @current_section_order += 1
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'k_log'
4
-
5
3
  module Ad
6
4
  module AgentArchitecture
7
5
  module Report
@@ -12,15 +10,17 @@ module Ad
12
10
  def print(workflow)
13
11
  log.section_heading 'Workflow Details Report'
14
12
  log.kv 'Name', workflow.name
15
- log.kv 'Description', workflow.description
13
+ # log.kv 'Description', workflow.description
16
14
 
17
15
  workflow.sections.each do |section|
18
16
  log.section_heading "Section: #{section.name}"
19
- log.kv 'Order', section.order
17
+ # log.kv 'Order', section.order
20
18
  section.steps.each do |step|
21
19
  log.section_heading "Step: #{step.name}"
22
- log.kv 'Order', step.order
23
- log.kv 'Prompt', step.prompt
20
+ # log.kv 'Order', step.order
21
+ # log.kv 'Prompt', step.prompt
22
+ # puts step.input_attributes.first
23
+ # An ERROR here means you have not configured an attribute name
24
24
  log.kv 'Input Attributes', step.input_attributes.map { |ia| ia.attribute.name }.join(', ')
25
25
  log.kv 'Output Attributes', step.output_attributes.map { |oa| oa.attribute.name }.join(', ')
26
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ad
4
4
  module AgentArchitecture
5
- VERSION = '0.0.9'
5
+ VERSION = '0.0.11'
6
6
  end
7
7
  end
@@ -13,13 +13,21 @@ Ad::AgentArchitecture::Database::CreateSchema.new(DB).execute
13
13
 
14
14
  require 'ad/agent_architecture/database/models'
15
15
  require 'ad/agent_architecture/database/sql_query'
16
- require 'ad/agent_architecture/dsl/agent_workflow_dsl'
16
+ require 'ad/agent_architecture/dsl/attribute_dsl'
17
+ require 'ad/agent_architecture/dsl/prompt_dsl'
18
+ require 'ad/agent_architecture/dsl/section_dsl'
19
+ require 'ad/agent_architecture/dsl/step_dsl'
20
+ require 'ad/agent_architecture/dsl/workflow_dsl'
21
+ require 'ad/agent_architecture/dsl/agent_dsl'
17
22
  require 'ad/agent_architecture/dsl/actions/save_database'
18
23
  require 'ad/agent_architecture/dsl/actions/save_json'
19
24
  require 'ad/agent_architecture/dsl/actions/save_yaml'
20
25
  require 'ad/agent_architecture/report/workflow_detail_report'
21
26
  require 'ad/agent_architecture/report/workflow_list_report'
22
27
 
28
+ # Alias'
29
+ Agent = Ad::AgentArchitecture::Dsl::AgentDsl
30
+
23
31
  module Ad
24
32
  module AgentArchitecture
25
33
  # raise Ad::AgentArchitecture::Error, 'Sample message'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ad-agent_architecture",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "ad-agent_architecture",
9
- "version": "0.0.9",
9
+ "version": "0.0.11",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.3",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ad-agent_architecture",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Architecture/Schema for AI Agents",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
data/workflow.json CHANGED
@@ -39,32 +39,38 @@
39
39
  "prompt": "Create 5 introduction variations for [first_draft]."
40
40
  },
41
41
  {
42
- "name": "SEO Analysis",
42
+ "name": "Update Draft with Intro",
43
43
  "order": 4,
44
44
  "input_attributes": [
45
- "first_draft"
45
+ "first_draft",
46
+ "intro_variation"
46
47
  ],
47
48
  "output_attributes": [
48
- "seo_analysis"
49
+ "second_draft"
49
50
  ],
50
- "prompt": "Analyze the blog post for SEO."
51
- }
52
- ]
53
- },
54
- {
55
- "name": "Editing",
56
- "order": 2,
57
- "steps": [
51
+ "prompt": "Update [first_draft] with a better intro [intro_variation]."
52
+ },
58
53
  {
59
- "name": "Edit Draft",
60
- "order": 1,
54
+ "name": "Analyse Intro",
55
+ "order": 5,
61
56
  "input_attributes": [
62
- "first_draft"
57
+ "second_draft"
63
58
  ],
64
59
  "output_attributes": [
65
- "first_draft"
60
+ "intro_analysis"
66
61
  ],
67
- "prompt": "Edit [first_draft] for grammar, style, and clarity."
62
+ "prompt": "Analyze the article [second_draft] introduction"
63
+ },
64
+ {
65
+ "name": "Combine Intro Analysis",
66
+ "order": 6,
67
+ "input_attributes": [
68
+
69
+ ],
70
+ "output_attributes": [
71
+ "intro_analysis_combined"
72
+ ],
73
+ "prompt": ""
68
74
  }
69
75
  ]
70
76
  }
@@ -90,10 +96,27 @@
90
96
  "type": "array",
91
97
  "is_array": false
92
98
  },
93
- "seo_analysis": {
94
- "name": "seo_analysis",
99
+ "intro_variation": {
100
+ "name": "intro_variation",
101
+ "type": "string",
102
+ "is_array": false
103
+ },
104
+ "second_draft": {
105
+ "name": "second_draft",
106
+ "type": "string",
107
+ "is_array": false
108
+ },
109
+ "intro_analysis": {
110
+ "name": "intro_analysis",
111
+ "type": "string",
112
+ "is_array": false
113
+ },
114
+ "intro_analysis_combined": {
115
+ "name": "intro_analysis_combined",
95
116
  "type": "string",
96
117
  "is_array": false
97
118
  }
119
+ },
120
+ "prompts": {
98
121
  }
99
122
  }
data/workflow.yaml CHANGED
@@ -25,23 +25,27 @@
25
25
  :output_attributes:
26
26
  - :intro_variations
27
27
  :prompt: Create 5 introduction variations for [first_draft].
28
- - :name: SEO Analysis
28
+ - :name: Update Draft with Intro
29
29
  :order: 4
30
30
  :input_attributes:
31
31
  - :first_draft
32
+ - :intro_variation
32
33
  :output_attributes:
33
- - :seo_analysis
34
- :prompt: Analyze the blog post for SEO.
35
- - :name: Editing
36
- :order: 2
37
- :steps:
38
- - :name: Edit Draft
39
- :order: 1
34
+ - :second_draft
35
+ :prompt: Update [first_draft] with a better intro [intro_variation].
36
+ - :name: Analyse Intro
37
+ :order: 5
40
38
  :input_attributes:
41
- - :first_draft
39
+ - :second_draft
42
40
  :output_attributes:
43
- - :first_draft
44
- :prompt: Edit [first_draft] for grammar, style, and clarity.
41
+ - :intro_analysis
42
+ :prompt: Analyze the article [second_draft] introduction
43
+ - :name: Combine Intro Analysis
44
+ :order: 6
45
+ :input_attributes: []
46
+ :output_attributes:
47
+ - :intro_analysis_combined
48
+ :prompt: ''
45
49
  :attributes:
46
50
  :transcript:
47
51
  :name: :transcript
@@ -59,7 +63,20 @@
59
63
  :name: :intro_variations
60
64
  :type: :array
61
65
  :is_array: false
62
- :seo_analysis:
63
- :name: :seo_analysis
66
+ :intro_variation:
67
+ :name: :intro_variation
68
+ :type: :string
69
+ :is_array: false
70
+ :second_draft:
71
+ :name: :second_draft
72
+ :type: :string
73
+ :is_array: false
74
+ :intro_analysis:
75
+ :name: :intro_analysis
76
+ :type: :string
77
+ :is_array: false
78
+ :intro_analysis_combined:
79
+ :name: :intro_analysis_combined
64
80
  :type: :string
65
81
  :is_array: false
82
+ :prompts: {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad-agent_architecture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -86,7 +86,13 @@ files:
86
86
  - lib/ad/agent_architecture/dsl/actions/save_database.rb
87
87
  - lib/ad/agent_architecture/dsl/actions/save_json.rb
88
88
  - lib/ad/agent_architecture/dsl/actions/save_yaml.rb
89
- - lib/ad/agent_architecture/dsl/agent_workflow_dsl.rb
89
+ - lib/ad/agent_architecture/dsl/agent_dsl.rb
90
+ - lib/ad/agent_architecture/dsl/agent_workflow_dsl.rb.old
91
+ - lib/ad/agent_architecture/dsl/attribute_dsl.rb
92
+ - lib/ad/agent_architecture/dsl/prompt_dsl.rb
93
+ - lib/ad/agent_architecture/dsl/section_dsl.rb
94
+ - lib/ad/agent_architecture/dsl/step_dsl.rb
95
+ - lib/ad/agent_architecture/dsl/workflow_dsl.rb
90
96
  - lib/ad/agent_architecture/report/workflow_detail_report.rb
91
97
  - lib/ad/agent_architecture/report/workflow_list_report.rb
92
98
  - lib/ad/agent_architecture/sql/workflow_details.sql