Skip to content

[FSSDK-11589] Add go-sdk logic to support agent for cmab #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

Mat001
Copy link
Contributor

@Mat001 Mat001 commented Jun 27, 2025

Added CMAB (Contextual Multi-Armed Bandit) support to go-sdk for Agent integration:

  1. CMAB Service: Core service that makes HTTP calls to external CMAB prediction endpoints
  2. CMAB Cache: LRU cache with TTL to store prediction responses and reduce API calls
  3. CMAB Configuration: Settings for request timeouts, cache size/TTL, and retry logic with exponential backoff
  4. Client Integration:
    - Added cmabService field to OptimizelyClient
    - Added WithCmabService() factory option for dependency injection
    - Modified Decide() method to call CMAB service for CMAB-enabled experiments
  5. Decision Enhancement: Extended decision responses to include CMAB predictions alongside existing feature flag results

We need CMAB support for agent in go-sdk because:

  1. go-sdk is the core SDK - It contains all the Optimizely decision logic (bucketing, feature flags, etc.)
  2. Agent is just a wrapper - Agent creates go-sdk clients and exposes them via HTTP endpoints
  3. CMAB integrates with decisions - CMAB predictions need to be combined with existing feature flag logic, which lives in go-sdk's Decide()
    method

This is how CMAB data flows between go-sdk and agent:

  1. Client request → Agent's /decide HTTP endpoint
  2. Agent → Creates Optimizely client from go-sdk (with CMAB config)
  3. go-sdk → Makes prediction API call to CMAB service endpoint
  4. CMAB service → Returns ML prediction response
  5. go-sdk → Caches prediction + combines with feature flag decision
  6. Agent → Returns combined response (feature flags + CMAB predictions) to client

Key points:

  • Agent creates the Optimizely client using go-sdk's factory
  • go-sdk handles all CMAB API calls, caching, and retry logic
  • Agent just passes through the enriched decision response that now includes CMAB data
  • The /decide endpoint response format stays the same, just with additional CMAB fields

https://jira.sso.episerver.net/browse/FSSDK-11589

@Mat001 Mat001 changed the title [FSSDK-] add go-sdk logic to support agent for cmab [FSSDK-11589] Add go-sdk logic to support agent for cmab Jun 27, 2025
Mat001 added 26 commits June 26, 2025 19:45
* Fix CMAB error handling to properly propagate error reasons in Decision objects

* add cmab cache options to getAllOptions

* fix failing fsc tests

* add cmab errors file

* adjust lowercase

* add test

* fix error message propagation in resons

* add error handling to feature experiment servvice

* Add more error handling to feature exper and composite feature service

* nil back to err

* add reasons message to composite feature service GetDecision

* use AddError for reasons

* Trigger PR check

* remove implicit error handling - PR feedback

* use nil instead of err for legacy

* fix error format

* Fix lint issue with fsc error

* Rename error var, lint stuttering issue
@Mat001 Mat001 requested review from raju-opti and jaeopt July 25, 2025 05:59
@Mat001 Mat001 requested a review from raju-opti August 6, 2025 17:50
Mat001 added 4 commits August 7, 2025 15:54
- Restore correct space indentation to match master branch
- Addresses coworker comment: 'can we keep this file unchanged?'
@Mat001 Mat001 requested a review from raju-opti August 8, 2025 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants