Class: DecisionAgent::ABTesting::ABTestingAgent
- Inherits:
-
Object
- Object
- DecisionAgent::ABTesting::ABTestingAgent
- Defined in:
- lib/decision_agent/ab_testing/ab_testing_agent.rb
Overview
Agent wrapper that adds A/B testing capabilities to the standard Agent Automatically handles variant assignment and decision tracking
Instance Attribute Summary collapse
-
#ab_test_manager ⇒ Object
readonly
Returns the value of attribute ab_test_manager.
-
#version_manager ⇒ Object
readonly
Returns the value of attribute version_manager.
Instance Method Summary collapse
-
#active_tests ⇒ Array<ABTest>
List active A/B tests.
-
#cache_stats ⇒ Object
Get cache statistics.
-
#clear_agent_cache! ⇒ Object
Clear the agent cache (useful for testing or when versions are updated).
-
#decide(context:, feedback: {}, ab_test_id: nil, user_id: nil) ⇒ Hash
Make a decision with A/B testing support.
-
#get_test_results(test_id) ⇒ Hash
Get A/B test results.
-
#initialize(ab_test_manager:, version_manager: nil, evaluators: [], scoring_strategy: nil, audit_adapter: nil, cache_agents: true) ⇒ ABTestingAgent
constructor
A new instance of ABTestingAgent.
Constructor Details
#initialize(ab_test_manager:, version_manager: nil, evaluators: [], scoring_strategy: nil, audit_adapter: nil, cache_agents: true) ⇒ ABTestingAgent
Returns a new instance of ABTestingAgent.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 16 def initialize( ab_test_manager:, version_manager: nil, evaluators: [], scoring_strategy: nil, audit_adapter: nil, cache_agents: true ) @ab_test_manager = ab_test_manager @version_manager = version_manager || ab_test_manager.version_manager @base_evaluators = evaluators @scoring_strategy = scoring_strategy @audit_adapter = audit_adapter @cache_agents = cache_agents @agent_cache = {} # Cache agents by version_id @agent_cache_mutex = Mutex.new end |
Instance Attribute Details
#ab_test_manager ⇒ Object (readonly)
Returns the value of attribute ab_test_manager.
8 9 10 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 8 def ab_test_manager @ab_test_manager end |
#version_manager ⇒ Object (readonly)
Returns the value of attribute version_manager.
8 9 10 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 8 def version_manager @version_manager end |
Instance Method Details
#active_tests ⇒ Array<ABTest>
List active A/B tests
70 71 72 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 70 def active_tests @ab_test_manager.active_tests end |
#cache_stats ⇒ Object
Get cache statistics
80 81 82 83 84 85 86 87 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 80 def cache_stats @agent_cache_mutex.synchronize do { cached_agents: @agent_cache.size, version_ids: @agent_cache.keys } end end |
#clear_agent_cache! ⇒ Object
Clear the agent cache (useful for testing or when versions are updated)
75 76 77 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 75 def clear_agent_cache! @agent_cache_mutex.synchronize { @agent_cache.clear } end |
#decide(context:, feedback: {}, ab_test_id: nil, user_id: nil) ⇒ Hash
Make a decision with A/B testing support
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 40 def decide(context:, feedback: {}, ab_test_id: nil, user_id: nil) ctx = context.is_a?(Context) ? context : Context.new(context) # If A/B test is specified, use variant assignment if ab_test_id decide_with_ab_test(ctx, feedback, ab_test_id, user_id) else # Standard decision without A/B testing agent = build_agent(@base_evaluators) decision = agent.decide(context: ctx, feedback: feedback) { decision: decision.decision, confidence: decision.confidence, explanations: decision.explanations, evaluations: decision.evaluations, ab_test: nil } end end |
#get_test_results(test_id) ⇒ Hash
Get A/B test results
64 65 66 |
# File 'lib/decision_agent/ab_testing/ab_testing_agent.rb', line 64 def get_test_results(test_id) @ab_test_manager.get_results(test_id) end |