composable_agents 3.1.0 → 3.2.0
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 +12 -0
- data/README.md +6 -3
- data/lib/composable_agents/mixins/retriable.rb +7 -5
- data/lib/composable_agents/mixins/retriable_artifacts.rb +1 -16
- data/lib/composable_agents/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aee730a3031c19e5b24bdd00a7a1fea08e590ff99916b61d4d20caa1c6f5d6db
|
|
4
|
+
data.tar.gz: 38195f2c530d077d429d5e3c253c96d0b41d4660b159aea68cf610fb26f3c10b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc150e2714463ef82f7dbdac5a90716b06643728ea839c1c8b60643d2175730efdfbe10ee855d5536dc268a654678a470757e16e3a3fea169bbb44dffde6e1cb
|
|
7
|
+
data.tar.gz: 992a6ef86a797cdd5110a0398e22a223d93e0bb7c0b4ec531ec25ec98466edc99cf20b3521f8118194cd32ecb1c02d1de898ea0ad5c8a9a1f5f92ea31a4345e4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [v3.2.0](https://github.com/Muriel-Salvan/composable_agents/compare/v3.1.0...v3.2.0) (2026-11-02 16:54:36)
|
|
2
|
+
|
|
3
|
+
## Global changes
|
|
4
|
+
### Patches
|
|
5
|
+
|
|
6
|
+
* [feat(Retriable): enhance retry policy options with new_input_artifacts, altering retried input artifacts](https://github.com/Muriel-Salvan/composable_agents/commit/e4ee0fe4105bdddb87670817006aedee6a7f3840)
|
|
7
|
+
|
|
8
|
+
## Changes for Retriable
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* [feat(Retriable): enhance retry policy options with new_input_artifacts, altering retried input artifacts](https://github.com/Muriel-Salvan/composable_agents/commit/e4ee0fe4105bdddb87670817006aedee6a7f3840)
|
|
12
|
+
|
|
1
13
|
# [v3.1.0](https://github.com/Muriel-Salvan/composable_agents/compare/v3.0.0...v3.1.0) (2026-11-01 13:55:18)
|
|
2
14
|
|
|
3
15
|
## Global changes
|
data/README.md
CHANGED
|
@@ -463,11 +463,14 @@ Mixins are `prepend`-ed into an agent class to add specific capabilities.
|
|
|
463
463
|
|
|
464
464
|
#### `ComposableAgents::Mixins::Retriable`
|
|
465
465
|
|
|
466
|
-
- **Description:** Adds conditional retry capabilities to agents. Retry condition procs are registered with `#retry_on` (or `#with_retry_on` for temporary activation) and are evaluated at the end of each run. A proc receives the agent instance and the exception raised by `run` (or `nil` if none) and returns either `nil` (no retry) or a policy hash with
|
|
466
|
+
- **Description:** Adds conditional retry capabilities to agents. Retry condition procs are registered with `#retry_on` (or `#with_retry_on` for temporary activation) and are evaluated at the end of each run. A proc receives the agent instance and the exception raised by `run` (or `nil` if none) and returns either `nil` (no retry) or a policy hash with optional keys to describe the policy:
|
|
467
|
+
- `:wait_secs` — Wait time in seconds before retrying (defaults to 0).
|
|
468
|
+
- `:modifier` — Proc called with the agent before retrying ( defaults to doing nothing).
|
|
469
|
+
- `:new_input_artifacts` — Hash of input artifacts to add to the retried run (defaults to `{}`).
|
|
470
|
+
When a proc returns a policy, the agent waits `wait_secs` seconds, applies the `modifier` proc (if any), merges the `new_input_artifacts` into the retry input, and re-runs. If `run` raised an exception and no proc returned a retry policy, the exception is re-raised to the caller.
|
|
467
471
|
- **Public methods:**
|
|
468
|
-
- `#retry_on(proc)` — Register a retry condition proc.
|
|
472
|
+
- `#retry_on(proc)` — Register a retry condition proc.
|
|
469
473
|
- `#with_retry_on(proc, &block)` — Register a retry proc for the duration of a block, then unregister it when the block returns (even if it raises).
|
|
470
|
-
- policy hash — Configuration with optional `:wait_secs` (seconds to wait before retrying, defaults to 0) and optional `:modifier` (proc called with the agent before retrying).
|
|
471
474
|
- **Usage example:**
|
|
472
475
|
```ruby
|
|
473
476
|
class MyAgent < ComposableAgents::Agent
|
|
@@ -17,14 +17,13 @@ module ComposableAgents
|
|
|
17
17
|
# * Each registered proc is kept in an internal array, in registration order.
|
|
18
18
|
# * A proc receives the agent's instance and the exception raised by `run`
|
|
19
19
|
# (or `nil` if none) and returns either `nil` (no retry) or a policy hash
|
|
20
|
-
#
|
|
20
|
+
# (see Retriable#retry_on).
|
|
21
21
|
# * The run method is wrapped: it calls the original run, then evaluates the
|
|
22
22
|
# registered procs in order until one returns a non-nil policy hash.
|
|
23
23
|
# * If `run` raised an exception and no proc returned a non-nil policy hash,
|
|
24
24
|
# the exception is re-raised to the caller.
|
|
25
25
|
# * If a proc decides to retry: wait for `wait_secs` seconds, then call the
|
|
26
|
-
# `modifier` proc (if any),
|
|
27
|
-
#
|
|
26
|
+
# `modifier` proc (if any), merge the `new_input_artifacts` into the retry input, and call run again.
|
|
28
27
|
module Retriable
|
|
29
28
|
# @!group Public API
|
|
30
29
|
|
|
@@ -41,8 +40,9 @@ module ComposableAgents
|
|
|
41
40
|
# - param exception [Exception, nil] The exception that was raised by the run, or nil if none.
|
|
42
41
|
# - result [Hash\\{Symbol => Object}] Definition of the retry policy, with optional properties:
|
|
43
42
|
# - wait_secs [Integer, Float] Wait time in seconds before retrying (defaults to 0).
|
|
44
|
-
# - modifier [
|
|
43
|
+
# - modifier [#call(agent)] Code called to modify the agent's state before retrying (defaults to doing nothing).
|
|
45
44
|
# - param agent [Agent] The agent for which the retry is considered.
|
|
45
|
+
# - new_input_artifacts [Hash\\{Symbol => Object}] New input artifacts that need to be added to the retried run (defaults to {}).
|
|
46
46
|
# @return [self]
|
|
47
47
|
def retry_on(proc)
|
|
48
48
|
retry_policies << proc
|
|
@@ -78,12 +78,13 @@ module ComposableAgents
|
|
|
78
78
|
# @param input_artifacts [Hash{Symbol => Object}] input artifacts
|
|
79
79
|
# @return [Hash{Symbol => Object}] output artifacts from the last run
|
|
80
80
|
def run(**input_artifacts)
|
|
81
|
+
retry_input_artifacts = input_artifacts.dup
|
|
81
82
|
output_artifacts = nil
|
|
82
83
|
retry_index = 0
|
|
83
84
|
loop do
|
|
84
85
|
exception = nil
|
|
85
86
|
begin
|
|
86
|
-
output_artifacts = super
|
|
87
|
+
output_artifacts = super(**retry_input_artifacts)
|
|
87
88
|
rescue StandardError => e
|
|
88
89
|
exception = e
|
|
89
90
|
end
|
|
@@ -98,6 +99,7 @@ module ComposableAgents
|
|
|
98
99
|
logger.debug "Retry ##{retry_index}: re-running in #{wait_secs}s#{" (exception #{exception})" if exception}"
|
|
99
100
|
sleep(wait_secs) if wait_secs.positive?
|
|
100
101
|
policy[:modifier]&.call(self)
|
|
102
|
+
retry_input_artifacts.merge!(policy[:new_input_artifacts] || {})
|
|
101
103
|
else
|
|
102
104
|
raise exception if exception
|
|
103
105
|
|
|
@@ -49,27 +49,12 @@
|
|
|
49
49
|
"Maximum number of retries (#{max_retries}) exceeded. Missing or errored artifacts: #{artifact_keys.join(', ')}"
|
|
50
50
|
else
|
|
51
51
|
artifacts_errors_retries += 1
|
|
52
|
-
{
|
|
52
|
+
{ new_input_artifacts: { user_instructions: missing_output_user_instructions(missing) } }
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
# Execute the agent to generate some output artifacts based on some input artifacts.
|
|
59
|
-
# On retry, uses +@overridden_user_instructions+ (set by the retry policy's modifier)
|
|
60
|
-
# instead of the original +user_instructions+.
|
|
61
|
-
#
|
|
62
|
-
# @param user_instructions [Object, nil] Instructions for the user prompt, that will be rendered.
|
|
63
|
-
# @param input_artifacts [Hash{Symbol => Object}] The input artifacts content, per artifact name
|
|
64
|
-
# @return [Hash{Symbol => Object}] The output artifacts
|
|
65
|
-
def run(user_instructions: nil, **input_artifacts)
|
|
66
|
-
if @overridden_user_instructions
|
|
67
|
-
user_instructions = @overridden_user_instructions
|
|
68
|
-
@overridden_user_instructions = nil
|
|
69
|
-
end
|
|
70
|
-
super
|
|
71
|
-
end
|
|
72
|
-
|
|
73
58
|
private
|
|
74
59
|
|
|
75
60
|
# Compute the missing output artifacts with their descriptions and errors.
|