Module: ComposableAgents::Mixins::Resumable
- Defined in:
- lib/composable_agents/mixins/resumable.rb
Overview
Mixin adding resumable step capabilities to agents. An agent prepending this mixin can use the following:
- A new constructor named parameter run_id that identifies the run that can be resumable.
- A step re-entrant method that defines a part of the agent's processing whose input/output is persisted and that can be skipped if it was previously executed.
- An agent_step method that calls a sub-agent with the artifacts and also tracks the state of this agent.
- Any agent that implements the methods export_state and import_state will benefit from its state's serialization automatically.
- An instance variable @artifacts that stores artifacts (initialized with input ones) that are JSON serialized by steps. Artifacts used with this mixin, and states returned by used agents should be JSON-serializable. This mixin uses the following methods from the agent:
#export_state -> ObjectOptional method returning the current JSON-serializable state of the agent.#import_state(state)Optional method that sets the agent state from a JSON-serializable object.
Internal collapse
-
#steps_run ⇒ Array<Array<Hash{Symbol => Object}>>
readonly
Hierarchies of the steps executed during each run of this agent.
Public API collapse
-
#initialize(*args, run_id: nil, **kwargs) ⇒ Object
Constructor.
Internal collapse
-
#run(**input_artifacts) ⇒ Hash{Symbol => Object}
Execute the agent to generate some output artifacts based on some input artifacts.
Instance Attribute Details
#steps_run ⇒ Array<Array<Hash{Symbol => Object}>> (readonly)
Hierarchies of the steps executed during each run of this agent.
90 91 92 |
# File 'lib/composable_agents/mixins/resumable.rb', line 90 def steps_run @steps_run end |
Instance Method Details
#initialize(*args, run_id: nil, **kwargs) ⇒ Object
Constructor
24 25 26 27 28 |
# File 'lib/composable_agents/mixins/resumable.rb', line 24 def initialize(*args, run_id: nil, **kwargs) super(*args, **kwargs) @steps_run = [] @run_id = run_id end |
#run(**input_artifacts) ⇒ Hash{Symbol => Object}
Execute the agent to generate some output artifacts based on some input artifacts.
36 37 38 39 40 41 42 43 |
# File 'lib/composable_agents/mixins/resumable.rb', line 36 def run(**input_artifacts) # The artifacts store, JSON serializable @artifacts = input_artifacts.dup # List of the steps_run hierarchies, one per run. Each run appends its own new list. @steps_run << [] @current_step_node = nil super end |