activeagent 1.6.0 → 1.6.2
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 +4 -4
- data/CHANGELOG.md +131 -1
- data/lib/active_agent/base.rb +2 -0
- data/lib/active_agent/concerns/release.rb +171 -0
- data/lib/active_agent/schema_tools.rb +108 -6
- data/lib/active_agent/telemetry/configuration.rb +11 -0
- data/lib/active_agent/telemetry/instrumentation.rb +9 -0
- data/lib/active_agent/telemetry/tracer.rb +4 -1
- data/lib/active_agent/telemetry.rb +22 -0
- data/lib/active_agent/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b14c71e437e0c5701b6300861adb5d8b79eba328602e255b38928e6030584a2b
|
|
4
|
+
data.tar.gz: c5eeeedce5730d88609b5131304571f9d7ecc12d3177ada460de7a4dd56ad61d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d76b024171c0a84e4ecc6f6618ccb92d1e94a215f15e15839e8b78b37c8bcd6a312626b8dda996cca23bb2ebcab325fc08fab289689d66143855fa0c372ffb40
|
|
7
|
+
data.tar.gz: 02605c62c4d22bc001462ee13451fce5f578cb43adb8f9380c8f116ef589629cafb175e10ce019fa073b9086382c2e8dd09bb03d9aab52813f75852a27e43aeb
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,137 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.6.2] - 2026-09-16
|
|
11
|
+
|
|
12
|
+
Releases `activeagent` and `actionagent` 1.6.2 from one tag.
|
|
13
|
+
|
|
14
|
+
Agents gain releases: a digest of everything the model is given, cut on
|
|
15
|
+
deploy and pinned to every trace, run and evaluation run, so a score is a
|
|
16
|
+
statement about a specific release and a regression is attributable to the
|
|
17
|
+
change that caused it. Around it, five dashboard fixes: an evaluation
|
|
18
|
+
created on MySQL can be run, the Tools tab reads the same `agent.tools` the
|
|
19
|
+
runner does, a container-valued query parameter is coerced instead of
|
|
20
|
+
raising, a recording's detail response no longer carries the visitor's
|
|
21
|
+
cookies and web storage, and the MCP endpoint answers an unsupported method with 405
|
|
22
|
+
instead of the dashboard page. `sign_in_path` and `sign_out_path` are now
|
|
23
|
+
documented.
|
|
24
|
+
|
|
25
|
+
Upgrading: the install generator emits a new `add_agent_releases` migration
|
|
26
|
+
(guarded column by column); run it. Cutting a release is
|
|
27
|
+
`rake action_agent:agents:release[REVISION]` in the deploy.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **Agents have releases, and every trace, run and evaluation says which one
|
|
32
|
+
it ran under.** `ActiveAgent::Release` gives each agent class a digest of
|
|
33
|
+
what the model is given — provider and model, generation options minus
|
|
34
|
+
credentials, the actions, the prompt templates on disk, and the tools and
|
|
35
|
+
delegations it declares — so two deploys of the same agent share a digest
|
|
36
|
+
and any change to those inputs is a new one, with no number to bump.
|
|
37
|
+
`ActiveAgent::Release.revision` carries the deploy alongside (a git SHA;
|
|
38
|
+
read from `SERVICE_VERSION`, `GIT_SHA`, `KAMAL_VERSION` and friends when
|
|
39
|
+
not set). The instrumentation stamps `agent.version` and `agent.revision`
|
|
40
|
+
on every generation's root span, and every trace gets `service.version`.
|
|
41
|
+
In the dashboard, `rake action_agent:agents:release[REVISION]` cuts an
|
|
42
|
+
`AgentVersion` for each agent whose code changed since the last release —
|
|
43
|
+
idempotent, so it belongs in the deploy — `rake action_agent:agents:versions`
|
|
44
|
+
lists them, and `Agent#record_release!` is the call behind both for a host
|
|
45
|
+
that syncs agents its own way. Traces are pinned to the release their root
|
|
46
|
+
span names, runs and evaluation runs to the version current when they
|
|
47
|
+
started (`agent_version_id` on all three; the install generator emits the
|
|
48
|
+
migration). A version's JSON carries `release`, `release_digest` and
|
|
49
|
+
`revision`, so the Versions tab tells a deploy from an edit. For that to
|
|
50
|
+
reach a host's own agents, a trace from a class the host mirrors into the
|
|
51
|
+
dashboard is now attributed to that mirror — the registrar matched only on
|
|
52
|
+
service, class *and* action, so every code-path trace registered an
|
|
53
|
+
observed per-action twin beside the synced record and could never be
|
|
54
|
+
pinned to its release.
|
|
55
|
+
|
|
56
|
+
### Fixed
|
|
57
|
+
|
|
58
|
+
- **An evaluation created on MySQL can be run.** MySQL cannot give a JSON
|
|
59
|
+
column a default, so an evaluation saved there without `config` read it
|
|
60
|
+
back as `nil`, and `compare_models` raised before the runner did anything
|
|
61
|
+
else. `config` and `criteria` now read as the empty value their column
|
|
62
|
+
default supplies on other databases. (#417)
|
|
63
|
+
- **The Tools tab now says which schema tools an agent is offered, and
|
|
64
|
+
lets you change it.** The editor listed every schema tool as enabled and
|
|
65
|
+
read-only whatever `agent.tools` held — *"a checkbox that cannot add or
|
|
66
|
+
remove the tool is a control that changes nothing"* — while evaluations,
|
|
67
|
+
dashboard runs and the MCP facade offered exactly what that column named.
|
|
68
|
+
An agent whose roster had been emptied over the API ran a suite with no
|
|
69
|
+
tools (1/8, `expected tool not called ×6`) under a tab reading "12
|
|
70
|
+
enabled". A schema tool's row now reads the roster and is switchable, and
|
|
71
|
+
every schema tool the host declares has a row, off unless the roster names
|
|
72
|
+
it — any agent may enable any of them, and a tool switched off has to keep
|
|
73
|
+
its row to be switched back on. A tool the agent class declares in code is
|
|
74
|
+
still reported rather than selected: the class offers it, and no checkbox
|
|
75
|
+
could change that.
|
|
76
|
+
- **A container-valued query parameter no longer 500s the dashboard API.**
|
|
77
|
+
`page`, `per_page`, `days`, `minutes`, `limit` and `after_sequence` were
|
|
78
|
+
read with `to_i`, which neither an Array (`minutes[]=1&minutes[]=2`) nor a
|
|
79
|
+
nested object (`page[x]=1`) answers. `Api::BaseController` now coerces
|
|
80
|
+
them: a multi-valued parameter means its first value, a nested object falls
|
|
81
|
+
back to the default, and the clamps that bounded the number still apply.
|
|
82
|
+
`sandboxes#compare` answers a `providers` value that is not a list of
|
|
83
|
+
names with a 400 instead of a `NoMethodError`.
|
|
84
|
+
- **A session recording's `show` no longer returns the visitor's cookies and
|
|
85
|
+
web storage.** Every other read path redacted the handoff state, but the
|
|
86
|
+
detail response carried `cookies`, `session_storage` and `local_storage`
|
|
87
|
+
unscrubbed, both as its own key and nested inside `metadata`. Both are now
|
|
88
|
+
stripped; only `#handoff` returns them, to the recording's owner. (#456)
|
|
89
|
+
|
|
90
|
+
## [1.6.1] - 2026-09-16
|
|
91
|
+
|
|
92
|
+
Releases `activeagent` and `actionagent` 1.6.1 from one tag.
|
|
93
|
+
|
|
94
|
+
A patch for two defects that share a failure mode: each one turns a broken
|
|
95
|
+
run into a plausible-looking success rather than an error. A date filter that
|
|
96
|
+
matched nothing reported zero instead of raising, and an agent reported that
|
|
97
|
+
zero as fact; telemetry that was enabled but never instrumented wrote no
|
|
98
|
+
traces while every configuration signal read healthy. Neither surfaced in a
|
|
99
|
+
test suite, because neither produces a failure — only a confident wrong
|
|
100
|
+
answer and an empty table.
|
|
101
|
+
|
|
102
|
+
No new public surface and no behaviour change for anything that was already
|
|
103
|
+
working, so a patch under semver. Suites that filter on a date column will
|
|
104
|
+
report different — correct — numbers after upgrading; read the first run as a
|
|
105
|
+
corrected baseline.
|
|
106
|
+
|
|
107
|
+
### Fixed
|
|
108
|
+
|
|
109
|
+
- **A range filter on a `SchemaTools` column no longer matches nothing and
|
|
110
|
+
reports zero.** `permitted_filters!` validated the column against the
|
|
111
|
+
allowlist but passed the value through untouched, so a range hash reached
|
|
112
|
+
`where` unrecognized and Rails compiled `where(due_date: {"before" => x})`
|
|
113
|
+
to `due_date = NULL` — a predicate that matches no row. The tool returned
|
|
114
|
+
`{count: 0}` with no error and the model read it as a truthful empty
|
|
115
|
+
answer: "0 overdue tickets" against a database holding four. Equality
|
|
116
|
+
filters were unaffected, which is why this went unnoticed. Comparisons are
|
|
117
|
+
now built through Arel with the column's own type cast, under the operators
|
|
118
|
+
`before`, `after`, `lt`, `lte`, `gt`, `gte`, `on_or_before` and
|
|
119
|
+
`on_or_after`; two bounds may be given together to express a window; and an
|
|
120
|
+
operator outside that set raises `UnpermittedAttribute` rather than
|
|
121
|
+
returning zero, consistent with how an undeclared column is already
|
|
122
|
+
rejected. Ranges are offered for date, datetime, time and numeric columns
|
|
123
|
+
only — a lexical `>` on a name column answers a question nobody asked.
|
|
124
|
+
- **A range filter is now discoverable.** `filter_properties` described a date
|
|
125
|
+
column as a bare `{type: "string", format: "date"}`, so the tool surface
|
|
126
|
+
could not express "before today" at all and a model asking the question
|
|
127
|
+
correctly still had no way to ask it. Comparable columns are now offered as
|
|
128
|
+
`anyOf: [scalar, range object]`, with the operator roster in the schema.
|
|
129
|
+
- **Telemetry enabled from a host app's initializer now installs
|
|
130
|
+
instrumentation.** The railtie prepended `GenerationInstrumentation` only
|
|
131
|
+
when `Telemetry.enabled?` was already true as railties ran — before
|
|
132
|
+
`config/initializers/*.rb`. An app that configures telemetry in its own
|
|
133
|
+
initializer, which is what the documentation shows, was therefore never
|
|
134
|
+
instrumented: `enabled?` answered true, `local_storage` was on, the trace
|
|
135
|
+
model resolved and the store lambda worked when called directly, and no
|
|
136
|
+
generation ever produced a span to store. `configure` now installs as well
|
|
137
|
+
when the resulting configuration is enabled; `instrument_telemetry!` is
|
|
138
|
+
idempotent, so the railtie path and the configure path cannot
|
|
139
|
+
double-prepend and initializer order stops mattering.
|
|
140
|
+
|
|
10
141
|
## [1.6.0] - 2026-09-14
|
|
11
142
|
|
|
12
143
|
Releases `activeagent` and `actionagent` 1.6.0 from one tag.
|
|
@@ -142,7 +273,6 @@ still correct: 1.6.0 satisfies it.
|
|
|
142
273
|
hash naming both `provider` and `model` is now rebuilt as it was; a bare
|
|
143
274
|
label is still parsed. The dashboard's "re-run" of a saved selection is
|
|
144
275
|
the path this fixes.
|
|
145
|
-
|
|
146
276
|
## [1.5.2] - 2026-09-11
|
|
147
277
|
|
|
148
278
|
Releases `activeagent` and `actionagent` 1.5.2 from one tag.
|
data/lib/active_agent/base.rb
CHANGED
|
@@ -12,6 +12,7 @@ require "active_agent/concerns/parameterized"
|
|
|
12
12
|
require "active_agent/concerns/preview"
|
|
13
13
|
require "active_agent/concerns/provider"
|
|
14
14
|
require "active_agent/concerns/queueing"
|
|
15
|
+
require "active_agent/concerns/release"
|
|
15
16
|
require "active_agent/concerns/rescue"
|
|
16
17
|
require "active_agent/concerns/streaming"
|
|
17
18
|
require "active_agent/concerns/tooling"
|
|
@@ -49,6 +50,7 @@ module ActiveAgent
|
|
|
49
50
|
include Parameterized
|
|
50
51
|
include Provider
|
|
51
52
|
include Queueing
|
|
53
|
+
include Release
|
|
52
54
|
include Rescue
|
|
53
55
|
include Streaming
|
|
54
56
|
include Tooling
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
# A release of an agent is what the model is given: the provider and model,
|
|
8
|
+
# the generation options, the prompt templates on disk, the actions and the
|
|
9
|
+
# tools the class declares. {ClassMethods#release_digest} names that
|
|
10
|
+
# deterministically, so two deploys that ship the same agent share a digest
|
|
11
|
+
# and a change to any of those inputs yields a new one — without anyone
|
|
12
|
+
# bumping a number by hand.
|
|
13
|
+
#
|
|
14
|
+
# The digest is what telemetry stamps on every generation (`agent.version`)
|
|
15
|
+
# and what a dashboard cuts an AgentVersion from on deploy, so a trace, a
|
|
16
|
+
# run and an evaluation can all say which release of the agent produced
|
|
17
|
+
# them. {Release.revision} carries the deploy itself (a git SHA or a release
|
|
18
|
+
# label) alongside, when the host knows it.
|
|
19
|
+
#
|
|
20
|
+
# Class-level and memoized: in development a reload replaces the class, so
|
|
21
|
+
# the next reference recomputes it.
|
|
22
|
+
module Release
|
|
23
|
+
extend ActiveSupport::Concern
|
|
24
|
+
|
|
25
|
+
# Option keys that never belong in a manifest: credentials, and per-call
|
|
26
|
+
# state the class does not own.
|
|
27
|
+
EXCLUDED_OPTION_KEYS = %i[
|
|
28
|
+
api_key access_token secret password token trace_id messages message instructions
|
|
29
|
+
].freeze
|
|
30
|
+
SECRET_KEY_PATTERN = /key|token|secret|password|credential/i
|
|
31
|
+
|
|
32
|
+
# How the deploy identifies itself, when it does. A host sets
|
|
33
|
+
# `ActiveAgent::Release.revision = ENV["GIT_SHA"]` (or a proc) from an
|
|
34
|
+
# initializer; otherwise the conventional deploy variables are read.
|
|
35
|
+
class << self
|
|
36
|
+
attr_writer :revision
|
|
37
|
+
|
|
38
|
+
# @return [String, nil]
|
|
39
|
+
def revision
|
|
40
|
+
value = @revision.respond_to?(:call) ? @revision.call : @revision
|
|
41
|
+
value = value.presence || ENV.values_at("SERVICE_VERSION", "GIT_SHA", "KAMAL_VERSION", "SOURCE_VERSION", "HEROKU_SLUG_COMMIT").find(&:present?)
|
|
42
|
+
value&.to_s
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Canonical JSON: sorted keys at every level, so the digest does not
|
|
46
|
+
# depend on the order anything was declared in.
|
|
47
|
+
# @api private
|
|
48
|
+
def canonical(value)
|
|
49
|
+
case value
|
|
50
|
+
when Hash then value.map { |k, v| [ k.to_s, canonical(v) ] }.sort_by(&:first).to_h
|
|
51
|
+
when Array then value.map { |v| canonical(v) }
|
|
52
|
+
when Symbol then value.to_s
|
|
53
|
+
else value
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class_methods do
|
|
59
|
+
# Everything about this class that shapes a generation, as data.
|
|
60
|
+
#
|
|
61
|
+
# @return [Hash]
|
|
62
|
+
def release_manifest
|
|
63
|
+
@release_manifest ||= Release.canonical(
|
|
64
|
+
agent: name,
|
|
65
|
+
provider: release_provider,
|
|
66
|
+
model: prompt_options&.dig(:model),
|
|
67
|
+
options: release_options,
|
|
68
|
+
actions: release_actions,
|
|
69
|
+
templates: release_templates,
|
|
70
|
+
tools: release_tools,
|
|
71
|
+
delegations: release_delegations
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# A short, stable identifier for {#release_manifest}: the first twelve
|
|
76
|
+
# hex characters of its SHA-256.
|
|
77
|
+
#
|
|
78
|
+
# @return [String]
|
|
79
|
+
def release_digest
|
|
80
|
+
@release_digest ||= Digest::SHA256.hexdigest(JSON.generate(release_manifest))[0, 12]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Forgets the memoized manifest and digest — for a host that edits
|
|
84
|
+
# templates at runtime, and for tests.
|
|
85
|
+
# @return [void]
|
|
86
|
+
def reset_release!
|
|
87
|
+
@release_manifest = nil
|
|
88
|
+
@release_digest = nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def release_provider
|
|
94
|
+
provider = respond_to?(:prompt_provider) ? prompt_provider : nil
|
|
95
|
+
(provider || prompt_options&.dig(:service))&.to_s
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Generation options minus credentials and per-call state. Nested
|
|
99
|
+
# hashes are walked so a token under `options: { headers: … }` is
|
|
100
|
+
# dropped too.
|
|
101
|
+
def release_options
|
|
102
|
+
strip_secrets((prompt_options || {}).except(*EXCLUDED_OPTION_KEYS, :model, :service))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def strip_secrets(value)
|
|
106
|
+
case value
|
|
107
|
+
when Hash
|
|
108
|
+
value.each_with_object({}) do |(key, inner), kept|
|
|
109
|
+
next if EXCLUDED_OPTION_KEYS.include?(key.to_sym) || key.to_s.match?(SECRET_KEY_PATTERN)
|
|
110
|
+
|
|
111
|
+
kept[key] = strip_secrets(inner)
|
|
112
|
+
end
|
|
113
|
+
when Array then value.map { |inner| strip_secrets(inner) }
|
|
114
|
+
else value
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# The public actions — the prompts a caller can invoke.
|
|
119
|
+
def release_actions
|
|
120
|
+
respond_to?(:action_methods) ? action_methods.to_a.sort : []
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Every template file under this agent's view prefixes, keyed by its
|
|
124
|
+
# path relative to the view root, with a digest of its contents. The
|
|
125
|
+
# prefixes mirror View#_prefixes without an action: `app/views/<agent>/`
|
|
126
|
+
# and `app/views/agents/<agent without suffix>/`.
|
|
127
|
+
def release_templates
|
|
128
|
+
return {} if anonymous? || !respond_to?(:view_paths)
|
|
129
|
+
|
|
130
|
+
base = name.underscore
|
|
131
|
+
prefixes = [ base, "agents/#{base.delete_suffix("_agent")}" ]
|
|
132
|
+
roots = Array(view_paths).map { |path| path.respond_to?(:to_path) ? path.to_path : path.to_s }
|
|
133
|
+
|
|
134
|
+
roots.each_with_object({}) do |root, templates|
|
|
135
|
+
prefixes.each do |prefix|
|
|
136
|
+
Dir.glob(File.join(root, prefix, "**", "*")).sort.each do |file|
|
|
137
|
+
next unless File.file?(file)
|
|
138
|
+
|
|
139
|
+
relative = file.delete_prefix("#{root}/")
|
|
140
|
+
templates[relative] = Digest::SHA256.hexdigest(File.binread(file))[0, 12]
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Tool definitions the class declares itself (a host convention such as
|
|
147
|
+
# schema-derived rosters), reduced to what identifies them.
|
|
148
|
+
def release_tools
|
|
149
|
+
return [] unless respond_to?(:tool_definitions)
|
|
150
|
+
|
|
151
|
+
Array(tool_definitions).map do |definition|
|
|
152
|
+
next definition.to_s unless definition.respond_to?(:to_h)
|
|
153
|
+
|
|
154
|
+
hash = definition.to_h
|
|
155
|
+
{
|
|
156
|
+
name: (hash[:name] || hash["name"]).to_s,
|
|
157
|
+
description: (hash[:description] || hash["description"]).to_s,
|
|
158
|
+
parameters: hash[:parameters] || hash["parameters"]
|
|
159
|
+
}
|
|
160
|
+
end.sort_by { |tool| tool.is_a?(Hash) ? tool[:name] : tool }
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# The delegations this class declares, by tool name.
|
|
164
|
+
def release_delegations
|
|
165
|
+
return [] unless respond_to?(:delegations)
|
|
166
|
+
|
|
167
|
+
Array(delegations).map { |tool_name, _definition| tool_name.to_s }.sort
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -68,6 +68,21 @@ module ActiveAgent
|
|
|
68
68
|
# ask for 10_000; this is what stops that from becoming the prompt.
|
|
69
69
|
MAX_LIMIT = 100
|
|
70
70
|
|
|
71
|
+
# Column types a range comparison is offered for. Strings and booleans
|
|
72
|
+
# are deliberately absent: a lexical `>` on a name column answers a
|
|
73
|
+
# question nobody asked.
|
|
74
|
+
RANGE_FILTERABLE_TYPES = %i[date datetime time integer float decimal].freeze
|
|
75
|
+
|
|
76
|
+
# The comparison operators a range filter may use, mapped to the Arel
|
|
77
|
+
# predicate that builds them. Names are the ones models reach for
|
|
78
|
+
# unprompted (`before`/`after` for dates, `lt`/`gte` for numbers), so a
|
|
79
|
+
# reasonable guess resolves instead of erroring.
|
|
80
|
+
RANGE_OPERATORS = {
|
|
81
|
+
"before" => :lt, "after" => :gt,
|
|
82
|
+
"lt" => :lt, "lte" => :lteq, "gt" => :gt, "gte" => :gteq,
|
|
83
|
+
"on_or_before" => :lteq, "on_or_after" => :gteq
|
|
84
|
+
}.freeze
|
|
85
|
+
|
|
71
86
|
# Raised when a tool call names a column outside the declared allowlists,
|
|
72
87
|
# or is otherwise outside the declared boundary.
|
|
73
88
|
class UnpermittedAttribute < ArgumentError; end
|
|
@@ -300,8 +315,13 @@ module ActiveAgent
|
|
|
300
315
|
|
|
301
316
|
# Validates and normalizes a filter hash against the allowlist.
|
|
302
317
|
#
|
|
318
|
+
# A filter value is normally matched for equality. A Hash value instead
|
|
319
|
+
# declares a range — `{ "before" => "2026-01-01" }`, `{ "gte" => 10 }` —
|
|
320
|
+
# and may carry two bounds at once to express a window.
|
|
321
|
+
#
|
|
303
322
|
# @api private
|
|
304
|
-
# @raise [UnpermittedAttribute] if any key is not declared filterable
|
|
323
|
+
# @raise [UnpermittedAttribute] if any key is not declared filterable,
|
|
324
|
+
# or a range names an operator that does not exist
|
|
305
325
|
def permitted_filters!(arguments)
|
|
306
326
|
filters = arguments.each_with_object({}) do |(key, value), memo|
|
|
307
327
|
next if value.nil?
|
|
@@ -318,6 +338,54 @@ module ActiveAgent
|
|
|
318
338
|
filters
|
|
319
339
|
end
|
|
320
340
|
|
|
341
|
+
# Splits filters into equality pairs and range predicates.
|
|
342
|
+
#
|
|
343
|
+
# Kept separate from {.permitted_filters!} because the two halves are
|
|
344
|
+
# applied differently: equality goes to `where(hash)`, ranges have to be
|
|
345
|
+
# built through Arel.
|
|
346
|
+
#
|
|
347
|
+
# @api private
|
|
348
|
+
# @return [Array(Hash, Array<Arel::Nodes::Node>)]
|
|
349
|
+
def partition_filters!(filters)
|
|
350
|
+
equality = {}
|
|
351
|
+
ranges = []
|
|
352
|
+
|
|
353
|
+
filters.each do |column, value|
|
|
354
|
+
if value.is_a?(Hash)
|
|
355
|
+
ranges.concat(range_predicates!(column, value))
|
|
356
|
+
else
|
|
357
|
+
equality[column] = value
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
[ equality, ranges ]
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Builds Arel predicates for one column's range hash.
|
|
365
|
+
#
|
|
366
|
+
# Rails silently turns `where(col: { "before" => x })` into `col = NULL`,
|
|
367
|
+
# which matches nothing and reports zero rather than failing — the worst
|
|
368
|
+
# outcome for an agent, which reads it as a truthful empty answer. So an
|
|
369
|
+
# unknown operator is rejected loudly here instead.
|
|
370
|
+
#
|
|
371
|
+
# @api private
|
|
372
|
+
# @raise [UnpermittedAttribute] on an unknown operator
|
|
373
|
+
def range_predicates!(column, value)
|
|
374
|
+
arel = @model.arel_table[column]
|
|
375
|
+
type = @model.type_for_attribute(column)
|
|
376
|
+
|
|
377
|
+
value.map do |operator, operand|
|
|
378
|
+
predicate = RANGE_OPERATORS[operator.to_s]
|
|
379
|
+
unless predicate
|
|
380
|
+
raise UnpermittedAttribute,
|
|
381
|
+
"`#{operator}` is not a valid comparison for `#{column}`. " \
|
|
382
|
+
"Allowed comparisons: #{RANGE_OPERATORS.keys.join(", ")}"
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
arel.public_send(predicate, type.cast(operand))
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
321
389
|
# Projects a record down to the declared return columns.
|
|
322
390
|
#
|
|
323
391
|
# The projection happens in SQL (+select+) as well as here, but the Ruby
|
|
@@ -386,7 +454,40 @@ module ActiveAgent
|
|
|
386
454
|
)
|
|
387
455
|
properties = schema[:schema][:properties]
|
|
388
456
|
|
|
389
|
-
filterable.index_with
|
|
457
|
+
filterable.index_with do |column|
|
|
458
|
+
scalar = (properties[column] || { type: "string" }).deep_dup
|
|
459
|
+
range_filterable?(column) ? with_range_form(column, scalar) : scalar
|
|
460
|
+
end
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# Dates, times and numbers are the columns a question like "overdue" or
|
|
464
|
+
# "more than 10" actually needs a comparison on.
|
|
465
|
+
def range_filterable?(column)
|
|
466
|
+
RANGE_FILTERABLE_TYPES.include?(@model.type_for_attribute(column).type)
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
# Offers a column as either a scalar (equality) or a range object.
|
|
470
|
+
#
|
|
471
|
+
# Without this the range form works but is undiscoverable: a model shown
|
|
472
|
+
# only `{type: "string", format: "date"}` has no way to know it may ask
|
|
473
|
+
# for `before`, and answers date questions with an equality match or no
|
|
474
|
+
# filter at all.
|
|
475
|
+
def with_range_form(column, scalar)
|
|
476
|
+
operand = scalar.slice(:type, :format)
|
|
477
|
+
description = scalar[:description]
|
|
478
|
+
|
|
479
|
+
{
|
|
480
|
+
description: [ description, "Accepts an exact value, or a range object such as " \
|
|
481
|
+
"{\"before\": ...} / {\"gte\": ...} (#{RANGE_OPERATORS.keys.join(", ")})." ].compact.join(" "),
|
|
482
|
+
anyOf: [
|
|
483
|
+
scalar.except(:description),
|
|
484
|
+
{
|
|
485
|
+
type: "object",
|
|
486
|
+
properties: RANGE_OPERATORS.keys.index_with { operand.dup },
|
|
487
|
+
additionalProperties: false
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
}
|
|
390
491
|
end
|
|
391
492
|
|
|
392
493
|
def resource_name
|
|
@@ -415,10 +516,10 @@ module ActiveAgent
|
|
|
415
516
|
)
|
|
416
517
|
|
|
417
518
|
define_singleton_method(name) do |actor: nil, limit: nil, **arguments|
|
|
418
|
-
|
|
519
|
+
equality, ranges = partition_filters!(permitted_filters!(arguments))
|
|
419
520
|
capped = normalize_limit(limit)
|
|
420
521
|
|
|
421
|
-
relation = relation_for(actor).where(
|
|
522
|
+
relation = ranges.reduce(relation_for(actor).where(equality)) { |rel, p| rel.where(p) }
|
|
422
523
|
# One extra row distinguishes "exactly at the limit" from "more than
|
|
423
524
|
# the limit", without a second COUNT query.
|
|
424
525
|
records = relation.limit(capped + 1).to_a
|
|
@@ -443,9 +544,10 @@ module ActiveAgent
|
|
|
443
544
|
)
|
|
444
545
|
|
|
445
546
|
define_singleton_method(name) do |actor: nil, **arguments|
|
|
446
|
-
|
|
547
|
+
equality, ranges = partition_filters!(permitted_filters!(arguments))
|
|
548
|
+
relation = ranges.reduce(relation_for(actor).where(equality)) { |rel, p| rel.where(p) }
|
|
447
549
|
|
|
448
|
-
{ count:
|
|
550
|
+
{ count: relation.count }
|
|
449
551
|
end
|
|
450
552
|
end
|
|
451
553
|
|
|
@@ -24,6 +24,17 @@ module ActiveAgent
|
|
|
24
24
|
# @return [Boolean] Whether to store traces in the app's own database
|
|
25
25
|
attr_reader :local_storage
|
|
26
26
|
|
|
27
|
+
# The deploy every trace is stamped with (`service.version`). Unset, it
|
|
28
|
+
# is whatever ActiveAgent::Release.revision resolves — a git SHA from
|
|
29
|
+
# the conventional deploy variables — so traces from two deploys of
|
|
30
|
+
# the same service can be told apart without any host configuration.
|
|
31
|
+
attr_writer :service_version
|
|
32
|
+
|
|
33
|
+
def service_version
|
|
34
|
+
value = @service_version.respond_to?(:call) ? @service_version.call : @service_version
|
|
35
|
+
(value.presence || ActiveAgent::Release.revision)&.to_s
|
|
36
|
+
end
|
|
37
|
+
|
|
27
38
|
def initialize
|
|
28
39
|
super
|
|
29
40
|
# The framework predates the shared gem and has always been opt-in;
|
|
@@ -58,6 +58,15 @@ module ActiveAgent
|
|
|
58
58
|
span.set_attribute("agent.action", action_name.to_s)
|
|
59
59
|
span.set_attribute("agent.provider", provider_name)
|
|
60
60
|
span.set_attribute("agent.model", model_name)
|
|
61
|
+
# Which release of the agent ran: the digest of what the model was
|
|
62
|
+
# given (ActiveAgent::Release), so a dashboard can pin this trace
|
|
63
|
+
# to the version it cut on deploy.
|
|
64
|
+
if self.class.respond_to?(:release_digest)
|
|
65
|
+
span.set_attribute("agent.version", self.class.release_digest)
|
|
66
|
+
if (revision = ActiveAgent::Release.revision).present?
|
|
67
|
+
span.set_attribute("agent.revision", revision)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
61
70
|
|
|
62
71
|
# Add prompt span, carrying the prompt contents (instructions +
|
|
63
72
|
# outbound messages) so dashboards can show what was sent.
|
|
@@ -169,12 +169,15 @@ module ActiveAgent
|
|
|
169
169
|
|
|
170
170
|
# Returns default attributes for all spans.
|
|
171
171
|
def default_attributes
|
|
172
|
-
{
|
|
172
|
+
attributes = {
|
|
173
173
|
"service.name" => configuration.resolved_service_name,
|
|
174
174
|
"service.environment" => configuration.resolved_environment,
|
|
175
175
|
"telemetry.sdk.name" => "activeagent",
|
|
176
176
|
"telemetry.sdk.version" => ActiveAgent::VERSION
|
|
177
177
|
}
|
|
178
|
+
version = configuration.respond_to?(:service_version) ? configuration.service_version : nil
|
|
179
|
+
attributes["service.version"] = version if version.present?
|
|
180
|
+
attributes
|
|
178
181
|
end
|
|
179
182
|
end
|
|
180
183
|
end
|
|
@@ -78,9 +78,31 @@ module ActiveAgent
|
|
|
78
78
|
# end
|
|
79
79
|
def configure
|
|
80
80
|
yield configuration if block_given?
|
|
81
|
+
install_instrumentation! if enabled?
|
|
81
82
|
configuration
|
|
82
83
|
end
|
|
83
84
|
|
|
85
|
+
# Installs generation instrumentation on ActiveAgent::Base.
|
|
86
|
+
#
|
|
87
|
+
# The railtie also does this at boot, but only for configuration already
|
|
88
|
+
# loaded by then (activeagent.yml, config.active_agent.telemetry). A host
|
|
89
|
+
# app that enables telemetry from its own initializer runs *after*
|
|
90
|
+
# railties, so that check has already seen `enabled? == false` and
|
|
91
|
+
# skipped the install — leaving telemetry enabled but nothing
|
|
92
|
+
# instrumented, and so no traces despite a valid local_store. Calling it
|
|
93
|
+
# from {.configure} as well makes the install order-independent;
|
|
94
|
+
# `instrument_telemetry!` is idempotent, so the two paths cannot
|
|
95
|
+
# double-prepend.
|
|
96
|
+
#
|
|
97
|
+
# @api private
|
|
98
|
+
# @return [void]
|
|
99
|
+
def install_instrumentation!
|
|
100
|
+
return unless defined?(ActiveAgent::Base)
|
|
101
|
+
|
|
102
|
+
ActiveAgent::Base.include(Instrumentation)
|
|
103
|
+
ActiveAgent::Base.instrument_telemetry!
|
|
104
|
+
end
|
|
105
|
+
|
|
84
106
|
# Resets the configuration to defaults.
|
|
85
107
|
#
|
|
86
108
|
# @return [Configuration] New default configuration
|
data/lib/active_agent/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activeagent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Bowen
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-09-17 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: actionpack
|
|
@@ -417,6 +418,7 @@ files:
|
|
|
417
418
|
- lib/active_agent/concerns/preview.rb
|
|
418
419
|
- lib/active_agent/concerns/provider.rb
|
|
419
420
|
- lib/active_agent/concerns/queueing.rb
|
|
421
|
+
- lib/active_agent/concerns/release.rb
|
|
420
422
|
- lib/active_agent/concerns/rescue.rb
|
|
421
423
|
- lib/active_agent/concerns/streaming.rb
|
|
422
424
|
- lib/active_agent/concerns/tooling.rb
|
|
@@ -605,6 +607,7 @@ metadata:
|
|
|
605
607
|
documentation_uri: https://docs.activeagents.ai
|
|
606
608
|
source_code_uri: https://github.com/activeagents/activeagent
|
|
607
609
|
rubygems_mfa_required: 'true'
|
|
610
|
+
post_install_message:
|
|
608
611
|
rdoc_options: []
|
|
609
612
|
require_paths:
|
|
610
613
|
- lib
|
|
@@ -619,7 +622,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
619
622
|
- !ruby/object:Gem::Version
|
|
620
623
|
version: '0'
|
|
621
624
|
requirements: []
|
|
622
|
-
rubygems_version: 3.
|
|
625
|
+
rubygems_version: 3.5.22
|
|
626
|
+
signing_key:
|
|
623
627
|
specification_version: 4
|
|
624
628
|
summary: Rails AI Agents Framework
|
|
625
629
|
test_files: []
|