activeagent 0.2.6.rc1 → 0.2.6.rc2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5be38e4a523b45e6456791eaa43e9a04ea377d0d6921c8c0e427b8bb06418f3
4
- data.tar.gz: 191f478a1d79f5bfe65e2016f9ec4063dce945eb09912da2cd70d393f0fda3c5
3
+ metadata.gz: 2b9c764679c8c11bbf82e3aa132c5d563fc0a6c3cd5c28da2f6804639d1c153b
4
+ data.tar.gz: ec6a3c3495d44071264665e88be075005a240e52afe9202c506819e89897b1f8
5
5
  SHA512:
6
- metadata.gz: 8f4749307fec6f7b9a7339486c09b9f20d61b05388a67f12f0c2e00267fc14979f6d193f649c64117f13b822baac75511b0269700a6362d0e3cb548c9d68c1df
7
- data.tar.gz: 7b3adbd0b9372d037b6fd303f55103d06e54ae7693b3920c7746ee1b7efe95f14134c7998a0bf5034e044fd3548ab0e44bf69df7a64109a2a0e319201273cd84
6
+ metadata.gz: de1673c61fabca8b9bdcf5a4d72d963d7de1538fb96d72580af25cff5c074199cb2a325b3ef0ef34f5c05a8aa5ad642b09782c4655cd5e1b7a98de6a59b50d1a
7
+ data.tar.gz: b70d1f16c1056d7c54bf964f9b5d0202e8b63f027d2eb1457276fd1bb07dd7acf00c6bff1ae45a36c33253463a348fdb75a1b9906559544b58b1f853ec77983c
@@ -1,16 +1,13 @@
1
1
  module ActiveAgent
2
2
  module ActionPrompt
3
3
  class Action
4
- attr_accessor :agent_name, :name, :params
4
+ attr_accessor :agent_name, :id, :name, :params
5
5
 
6
6
  def initialize(attributes = {})
7
+ @id = attributes.fetch(:id, nil)
7
8
  @name = attributes.fetch(:name, "")
8
9
  @params = attributes.fetch(:params, {})
9
10
  end
10
-
11
- def perform_action
12
- agent_name.constantize.new.process(name, params)
13
- end
14
11
  end
15
12
  end
16
13
  end
@@ -3,10 +3,10 @@ module ActiveAgent
3
3
  class Message
4
4
  VALID_ROLES = %w[system assistant user tool function].freeze
5
5
 
6
- attr_accessor :content, :role, :name, :action_requested, :requested_actions, :content_type, :charset
6
+ attr_accessor :action_id, :content, :role, :name, :action_requested, :requested_actions, :content_type, :charset
7
7
 
8
- def initialize(attributes = {})
9
- @agent_class = attributes[:agent_class]
8
+ def initialize(attributes = {})
9
+ @action_id = attributes[:action_id]
10
10
  @charset = attributes[:charset] || "UTF-8"
11
11
  @content = attributes[:content] || ""
12
12
  @content_type = attributes[:content_type] || "text/plain"
@@ -20,16 +20,22 @@ module ActiveAgent
20
20
  def to_h
21
21
  hash = {
22
22
  role: role,
23
+ action_id: action_id,
23
24
  content: content,
24
- content_type: content_type,
25
+ type: content_type,
25
26
  charset: charset
26
27
  }
28
+
27
29
  hash[:name] = name if name
28
30
  hash[:action_requested] = requested_actions.any?
29
31
  hash[:requested_actions] = requested_actions if requested_actions.any?
30
32
  hash
31
33
  end
32
34
 
35
+ def embed
36
+ @agent_class.embed(@content)
37
+ end
38
+
33
39
  private
34
40
 
35
41
  def validate_role
@@ -202,6 +202,12 @@ module ActiveAgent
202
202
 
203
203
  attr_internal :context
204
204
 
205
+ def embed
206
+ context.options.merge(options)
207
+ generation_provider.embed(context) if context && generation_provider
208
+ handle_response(generation_provider.response)
209
+ end
210
+
205
211
  def perform_generation
206
212
  context.options.merge(options)
207
213
  generation_provider.generate(context) if context && generation_provider
@@ -215,13 +221,15 @@ module ActiveAgent
215
221
  end
216
222
 
217
223
  def update_context(response)
218
- context.message = response.message
224
+ context = response.prompt
219
225
  response
220
226
  end
221
227
 
222
228
  def perform_actions(requested_actions:)
223
229
  requested_actions.each do |action|
224
230
  perform_action(action)
231
+ prompt.messages.last.role = :tool
232
+ prompt.messages.last.action_id = action.id
225
233
  end
226
234
  end
227
235
 
@@ -17,9 +17,6 @@ module ActiveAgent
17
17
 
18
18
  def generate(prompt)
19
19
  @prompt = prompt
20
-
21
- # prompt_parameters(model: @model_name, messages: prompt.messages, tools: prompt.actions)
22
- # parameters[:instructions] = prompt.instructions.content if prompt.instructions.present?
23
20
 
24
21
  chat_prompt(parameters: prompt_parameters)
25
22
  rescue => e
@@ -28,6 +25,7 @@ module ActiveAgent
28
25
 
29
26
  def chat_prompt(parameters: prompt_parameters)
30
27
  parameters[:stream] = provider_stream if prompt.options[:stream] || config["stream"]
28
+
31
29
  chat_response(@client.chat(parameters: parameters))
32
30
  end
33
31
 
@@ -39,7 +37,7 @@ module ActiveAgent
39
37
  raise GenerationProviderError, e.message
40
38
  end
41
39
 
42
- def embeddings_parameters(input: prompt.message.content, model: "text-embedding-ada-002")
40
+ def embeddings_parameters(input: prompt.message.content, model: "text-embedding-3-large")
43
41
  {
44
42
  model: model,
45
43
  input: input
@@ -76,17 +74,33 @@ module ActiveAgent
76
74
  def prompt_parameters(model: @prompt.options[:model] || @model_name, messages: @prompt.messages, temperature: @config["temperature"] || 0.7, tools: @prompt.actions)
77
75
  {
78
76
  model: model,
79
- messages: messages,
77
+ messages: provider_messages(messages),
80
78
  temperature: temperature,
81
79
  tools: tools.presence
82
80
  }
83
81
  end
84
82
 
83
+ def provider_messages(messages)
84
+ messages.map do |message|
85
+ provider_message {
86
+ role: message.role,
87
+ tool_call_id: message.action_id.presence,
88
+ content: message.content,
89
+ type: message.content_type,
90
+ charset: message.charset
91
+ }.compact
92
+
93
+ if content_type == "image_url"
94
+ provider_message[:image_url] = { url: content }
95
+ end
96
+ end
97
+ end
98
+
85
99
  def chat_response(response)
86
100
  return @response if prompt.options[:stream]
87
101
 
88
102
  message_json = response.dig("choices", 0, "message")
89
-
103
+
90
104
  message = ActiveAgent::ActionPrompt::Message.new(
91
105
  content: message_json["content"],
92
106
  role: message_json["role"],
@@ -102,6 +116,7 @@ module ActiveAgent
102
116
  if tool_calls
103
117
  tool_calls.map do |tool_call|
104
118
  ActiveAgent::ActionPrompt::Action.new(
119
+ id: tool_call["id"],
105
120
  name: tool_call.dig("function", "name"),
106
121
  params: JSON.parse(
107
122
  tool_call.dig("function", "arguments"),
@@ -1,3 +1,3 @@
1
1
  module ActiveAgent
2
- VERSION = "0.2.6.rc1"
2
+ VERSION = "0.2.6.rc2"
3
3
  end
@@ -4,11 +4,7 @@ module ActiveAgent
4
4
  module Generators
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  source_root File.expand_path("templates", __dir__)
7
-
8
- def create_initializer
9
- template "initializer.rb", "config/initializers/active_agent.rb"
10
- end
11
-
7
+
12
8
  def create_configuration
13
9
  template "active_agent.yml", "config/active_agent.yml"
14
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.rc1
4
+ version: 0.2.6.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bowen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-13 00:00:00.000000000 Z
11
+ date: 2025-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack