activeagent 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_agent/action_prompt/base.rb +470 -0
  3. data/lib/active_agent/action_prompt/message.rb +22 -2
  4. data/lib/active_agent/action_prompt/prompt.rb +2 -2
  5. data/lib/active_agent/action_prompt.rb +84 -0
  6. data/lib/active_agent/base.rb +9 -448
  7. data/lib/active_agent/callbacks.rb +9 -9
  8. data/lib/active_agent/generation.rb +3 -3
  9. data/lib/active_agent/generation_job.rb +8 -6
  10. data/lib/active_agent/generation_provider/open_ai_provider.rb +20 -8
  11. data/lib/active_agent/parameterized.rb +1 -1
  12. data/lib/active_agent/version.rb +1 -1
  13. data/lib/active_agent.rb +1 -2
  14. data/lib/generators/active_agent/agent_generator.rb +5 -3
  15. data/lib/generators/active_agent/install_generator.rb +2 -9
  16. data/lib/generators/active_agent/templates/agent.rb.tt +1 -1
  17. data/lib/generators/active_agent/templates/application_agent.rb.tt +0 -4
  18. data/lib/generators/erb/agent_generator.rb +43 -0
  19. data/lib/generators/erb/install_generator.rb +16 -0
  20. data/lib/generators/erb/templates/application_agent.rb.tt +7 -0
  21. data/lib/generators/erb/templates/layout.html.erb.tt +1 -0
  22. data/lib/generators/erb/templates/layout.text.erb.tt +1 -0
  23. data/lib/generators/erb/templates/view.html.erb.tt +5 -0
  24. data/lib/generators/erb/templates/view.text.erb.tt +3 -0
  25. data/lib/generators/test_unit/agent_generator.rb +30 -0
  26. data/lib/generators/test_unit/install_generator.rb +13 -0
  27. data/lib/generators/test_unit/templates/functional_test.rb.tt +20 -0
  28. data/lib/generators/test_unit/templates/preview.rb.tt +14 -0
  29. metadata +29 -15
  30. data/lib/active_agent/README.md +0 -21
  31. data/lib/active_agent/action_prompt/README.md +0 -0
  32. data/lib/active_agent/generation_provider/README.md +0 -0
  33. data/lib/generators/active_agent/templates/action.html.erb.tt +0 -0
  34. data/lib/generators/active_agent/templates/action.json.jbuilder.tt +0 -14
  35. data/lib/generators/active_agent/templates/agent.html.erb +0 -1
  36. data/lib/generators/active_agent/templates/agent.text.erb +0 -1
  37. data/lib/generators/active_agent/templates/agent_spec.rb.tt +0 -0
  38. data/lib/generators/active_agent/templates/agent_test.rb.tt +0 -0
@@ -7,10 +7,10 @@ module ActiveAgent
7
7
 
8
8
  argument :actions, type: :array, default: [], banner: "method method"
9
9
 
10
- check_class_collision
10
+ check_class_collision suffix: "Agent"
11
11
 
12
12
  def create_agent_file
13
- template "agent.rb", File.join("app/agents", class_path, "#{file_name}.rb")
13
+ template "agent.rb", File.join("app/agents", class_path, "#{file_name}_agent.rb")
14
14
 
15
15
  in_root do
16
16
  if behavior == :invoke && !File.exist?(application_agent_file_name)
@@ -19,10 +19,12 @@ module ActiveAgent
19
19
  end
20
20
  end
21
21
 
22
+ hook_for :template_engine, :test_framework
23
+
22
24
  private
23
25
 
24
26
  def file_name # :doc:
25
- @_file_name ||= super + "_agent"
27
+ @_file_name ||= super.sub(/_agent\z/i, "")
26
28
  end
27
29
 
28
30
  def application_agent_file_name
@@ -5,18 +5,11 @@ module ActiveAgent
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
+ hook_for :template_engine, :test_framework
9
+
8
10
  def create_configuration
9
11
  template "active_agent.yml", "config/active_agent.yml"
10
12
  end
11
-
12
- def create_application_agent
13
- template "application_agent.rb", "app/agents/application_agent.rb"
14
- end
15
-
16
- def create_agent_layouts
17
- template "agent.html.erb", "app/views/layouts/agent.html.erb"
18
- template "agent.text.erb", "app/views/layouts/agent.text.erb"
19
- end
20
13
  end
21
14
  end
22
15
  end
@@ -1,5 +1,5 @@
1
1
  <% module_namespacing do -%>
2
- class <%= class_name %> < ApplicationAgent
2
+ class <%= class_name %>Agent < ApplicationAgent
3
3
  <% actions.each_with_index do |action, index| -%>
4
4
  <% if index != 0 -%>
5
5
 
@@ -3,9 +3,5 @@ class ApplicationAgent < ActiveAgent::Base
3
3
  layout 'agent'
4
4
 
5
5
  generate_with :openai, model: "gpt-4o-mini", instructions: "You are a helpful assistant."
6
-
7
- def text_prompt
8
- prompt { |format| format.text { render plain: params[:message] } }
9
- end
10
6
  end
11
7
  <% end %>
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb"
4
+
5
+ module Erb # :nodoc:
6
+ module Generators # :nodoc:
7
+ class AgentGenerator < Base # :nodoc:
8
+ source_root File.expand_path("templates", __dir__)
9
+ argument :actions, type: :array, default: [], banner: "method method"
10
+
11
+ def copy_view_files
12
+ view_base_path = File.join("app/views", class_path, file_name + "_agent")
13
+ empty_directory view_base_path
14
+
15
+ if behavior == :invoke
16
+ formats.each do |format|
17
+ layout_path = File.join("app/views/layouts", class_path, filename_with_extensions("agent", format))
18
+ template filename_with_extensions(:layout, format), layout_path unless File.exist?(layout_path)
19
+ end
20
+ end
21
+
22
+ actions.each do |action|
23
+ @action = action
24
+
25
+ formats.each do |format|
26
+ @path = File.join(view_base_path, filename_with_extensions(action, format))
27
+ template filename_with_extensions(:view, format), @path
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def formats
35
+ [ :text, :html ]
36
+ end
37
+
38
+ def file_name
39
+ @_file_name ||= super.sub(/_agent\z/i, "")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Erb # :nodoc:
6
+ module Generators # :nodoc:
7
+ class InstallGenerator < ::Rails::Generators::Base # :nodoc:
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def create_agent_layouts
11
+ template "layout.html.erb.tt", "app/views/layouts/agent.html.erb"
12
+ template "layout.text.erb.tt", "app/views/layouts/agent.text.erb"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ <% module_namespacing do -%>
2
+ class ApplicationAgent < ActiveAgent::Base
3
+ layout 'agent'
4
+
5
+ generate_with :openai, model: "gpt-4o-mini", instructions: "You are a helpful assistant."
6
+ end
7
+ <% end %>
@@ -0,0 +1 @@
1
+ <%%= yield %>
@@ -0,0 +1 @@
1
+ <%%= yield %>
@@ -0,0 +1,5 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+
3
+ <p>
4
+ <%%= @message %>, find me in <%= @path %>
5
+ </p>
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ <%%= @message %>, find me in <%= @path %>
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/test_unit"
4
+
5
+ module TestUnit # :nodoc:
6
+ module Generators # :nodoc:
7
+ class AgentGenerator < Base # :nodoc:
8
+ source_root File.expand_path("templates", __dir__)
9
+ argument :actions, type: :array, default: [], banner: "method method"
10
+
11
+ def check_class_collision
12
+ class_collisions "#{class_name}AgentTest", "#{class_name}AgentPreview"
13
+ end
14
+
15
+ def create_test_files
16
+ template "functional_test.rb", File.join("test/agents", class_path, "#{file_name}_agent_test.rb")
17
+ end
18
+
19
+ def create_preview_files
20
+ template "preview.rb", File.join("test/agents/previews", class_path, "#{file_name}_agent_preview.rb")
21
+ end
22
+
23
+ private
24
+
25
+ def file_name
26
+ @_file_name ||= super.sub(/_agent\z/i, "")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/test_unit"
4
+
5
+ module TestUnit # :nodoc:
6
+ module Generators # :nodoc:
7
+ class InstallGenerator < Base # :nodoc:
8
+ # TestUnit install generator for ActiveAgent
9
+ # This can be used to create additional test-specific files during installation
10
+ # Currently no additional files are needed for TestUnit setup
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>AgentTest < ActiveAgent::TestCase
5
+ <% actions.each_with_index do |action, index| -%>
6
+ <% if index != 0 -%>
7
+
8
+ <% end -%>
9
+ test "<%= action %>" do
10
+ agent = <%= class_name %>Agent.<%= action %>
11
+ assert_equal <%= action.to_s.humanize.inspect %>, agent.prompt_context
12
+ end
13
+ <% end -%>
14
+ <% if actions.blank? -%>
15
+ # test "the truth" do
16
+ # assert true
17
+ # end
18
+ <% end -%>
19
+ end
20
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ <% module_namespacing do -%>
2
+ # Preview all agent views/prompts templates at http://localhost:3000/active_agent/agents/<%= file_path %>_agent
3
+ class <%= class_name %>AgentPreview < ActiveAgent::Preview
4
+ <% actions.each_with_index do |action, index| -%>
5
+ <% if index != 0 -%>
6
+
7
+ <% end -%>
8
+ # Preview this email at http://localhost:3000/active_agent/agents/<%= file_path %>_agent/<%= action %>
9
+ def <%= action %>
10
+ <%= class_name %>Agent.<%= action %>
11
+ end
12
+ <% end -%>
13
+ end
14
+ <% end -%>
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bowen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-05-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: actionpack
@@ -130,6 +129,20 @@ dependencies:
130
129
  - - "<"
131
130
  - !ruby/object:Gem::Version
132
131
  version: '9.0'
132
+ - !ruby/object:Gem::Dependency
133
+ name: jbuilder
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
133
146
  description: The only agent-oriented AI framework designed for Rails, where Agents
134
147
  are Controllers. Build AI features with less complexity using the MVC conventions
135
148
  you love.
@@ -140,10 +153,9 @@ extra_rdoc_files: []
140
153
  files:
141
154
  - CHANGELOG.md
142
155
  - lib/active_agent.rb
143
- - lib/active_agent/README.md
144
156
  - lib/active_agent/action_prompt.rb
145
- - lib/active_agent/action_prompt/README.md
146
157
  - lib/active_agent/action_prompt/action.rb
158
+ - lib/active_agent/action_prompt/base.rb
147
159
  - lib/active_agent/action_prompt/message.rb
148
160
  - lib/active_agent/action_prompt/prompt.rb
149
161
  - lib/active_agent/base.rb
@@ -154,7 +166,6 @@ files:
154
166
  - lib/active_agent/generation_job.rb
155
167
  - lib/active_agent/generation_methods.rb
156
168
  - lib/active_agent/generation_provider.rb
157
- - lib/active_agent/generation_provider/README.md
158
169
  - lib/active_agent/generation_provider/anthropic_provider.rb
159
170
  - lib/active_agent/generation_provider/base.rb
160
171
  - lib/active_agent/generation_provider/ollama_provider.rb
@@ -176,15 +187,20 @@ files:
176
187
  - lib/generators/active_agent/USAGE
177
188
  - lib/generators/active_agent/agent_generator.rb
178
189
  - lib/generators/active_agent/install_generator.rb
179
- - lib/generators/active_agent/templates/action.html.erb.tt
180
- - lib/generators/active_agent/templates/action.json.jbuilder.tt
181
190
  - lib/generators/active_agent/templates/active_agent.yml
182
- - lib/generators/active_agent/templates/agent.html.erb
183
191
  - lib/generators/active_agent/templates/agent.rb.tt
184
- - lib/generators/active_agent/templates/agent.text.erb
185
- - lib/generators/active_agent/templates/agent_spec.rb.tt
186
- - lib/generators/active_agent/templates/agent_test.rb.tt
187
192
  - lib/generators/active_agent/templates/application_agent.rb.tt
193
+ - lib/generators/erb/agent_generator.rb
194
+ - lib/generators/erb/install_generator.rb
195
+ - lib/generators/erb/templates/application_agent.rb.tt
196
+ - lib/generators/erb/templates/layout.html.erb.tt
197
+ - lib/generators/erb/templates/layout.text.erb.tt
198
+ - lib/generators/erb/templates/view.html.erb.tt
199
+ - lib/generators/erb/templates/view.text.erb.tt
200
+ - lib/generators/test_unit/agent_generator.rb
201
+ - lib/generators/test_unit/install_generator.rb
202
+ - lib/generators/test_unit/templates/functional_test.rb.tt
203
+ - lib/generators/test_unit/templates/preview.rb.tt
188
204
  - lib/tasks/activeagent_tasks.rake
189
205
  homepage: https://activeagents.ai
190
206
  licenses:
@@ -194,7 +210,6 @@ metadata:
194
210
  documentation_uri: https://github.com/activeagents/activeagent
195
211
  source_code_uri: https://github.com/activeagents/activeagent
196
212
  rubygems_mfa_required: 'true'
197
- post_install_message:
198
213
  rdoc_options: []
199
214
  require_paths:
200
215
  - lib
@@ -209,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
224
  - !ruby/object:Gem::Version
210
225
  version: '0'
211
226
  requirements: []
212
- rubygems_version: 3.5.3
213
- signing_key:
227
+ rubygems_version: 3.6.9
214
228
  specification_version: 4
215
229
  summary: Rails AI Agents Framework
216
230
  test_files: []
@@ -1,21 +0,0 @@
1
- # Active Agent
2
- Active Agent is a Rails framework for creating and managing AI agents. It provides a structured way to interact with generation providers through agents with context including prompts, tools, and messages. It includes two core modules, Generation Provider and Action Prompt, along with several support classes to handle different aspects of agent creation and management.
3
-
4
- ## Core Modules
5
-
6
- - Generation Provider - module for configuring and interacting with generation providers through Prompts and Responses.
7
- - Action Prompt - module for defining prompts, tools, and messages. The Base class implements an AbstractController to render prompts and actions. Prompts are Action Views that provide instructions for the agent to generate content, formatted messages for the agent and users including **streaming generative UI**.
8
-
9
- ## Main Components
10
-
11
- - Base class - for creating and configuring agents.
12
- - Queued Generation - module for managing queued generation requests and responses. Using the Generation Job class to perform asynchronous generation requests, it provides a way to **stream generation** requests back to the Job, Agent, or User.
13
-
14
- ### ActiveAgent::Base
15
-
16
- The Base class is used to create agents that interact with generation providers through prompts and messages. It includes methods for configuring and interacting with generation providers using Prompts and Responses. The Base class also provides a structured way to render prompts and actions.
17
-
18
- #### Core Methods
19
-
20
- - `generate_with(provider, options = {})` - Configures the agent to generate content using the specified generation provider and options.
21
- - `streams_with(provider, options = {})` - Configures the agent to stream content using the specified generation provider's stream option.
File without changes
File without changes
@@ -1,14 +0,0 @@
1
- json.type :function
2
- json.function do
3
- json.name action_name
4
- json.description "TODO: Write a description for this action"
5
- json.parameters do
6
- json.type :object
7
- json.properties do
8
- json.param_name do
9
- json.type :string
10
- json.description "The param_description"
11
- end
12
- end
13
- end
14
- end
@@ -1 +0,0 @@
1
- <%= yield if block_given? %>
@@ -1 +0,0 @@
1
- <%= yield if block_given? %>