Class: CircuitBreaker::Executors::AgentExecutor
- Inherits:
-
BaseExecutor
- Object
- BaseExecutor
- CircuitBreaker::Executors::AgentExecutor
- Defined in:
- lib/circuit_breaker/executors/agent_executor.rb
Constant Summary collapse
- MAX_ITERATIONS =
10
Instance Attribute Summary
Attributes inherited from BaseExecutor
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(context = {}) ⇒ AgentExecutor
constructor
A new instance of AgentExecutor.
Methods included from DSL
included, #validate_parameters
Constructor Details
#initialize(context = {}) ⇒ AgentExecutor
Returns a new instance of AgentExecutor.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/circuit_breaker/executors/agent_executor.rb', line 21 def initialize(context = {}) super @agent_type = context[:agent_type] @task = context[:task] @model = context[:model] || 'gpt-4' @model_provider = context[:model_provider] || detect_model_provider(@model) @ollama_base_url = context[:ollama_base_url] || 'http://localhost:11434' @system_prompt = context[:system_prompt] @memory = LLM::ChainMemory.new @toolkit = setup_toolkit(context[:tools] || []) @parameters = context[:parameters] || {} end |
Instance Method Details
#execute ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/circuit_breaker/executors/agent_executor.rb', line 34 def execute return unless @task iteration = 0 final_output = nil while iteration < MAX_ITERATIONS # Get current state and plan next action current_state = prepare_state(iteration) action_plan = plan_next_action(current_state) break if action_plan[:status] == 'complete' # Execute planned action action_result = execute_action(action_plan) # Store intermediate results @memory.add_step_result( step_name: action_plan[:action], input: action_plan[:input], output: action_result, metadata: { iteration: iteration } ) final_output = action_result iteration += 1 end @result = { task: @task, iterations: iteration, final_output: final_output, memory: @memory.to_h, status: iteration < MAX_ITERATIONS ? 'completed' : 'max_iterations_reached' } end |