How mahakagarwal7/featureflag works
Purpose and Entrypoints
This repository is a feature-flag rollout simulation benchmark: agents make sequential rollout decisions while telemetry, risk, revenue, and health evolve. The primary runtime is Python; entrypoints include API servers at backend/feature_flag_env/server/app.py and backend/server/app.py, local/remote evaluation in backend/inference.py, and training scripts backend/train_rl.py and backend/train_enterprise.py.
Simulation Environment
The environment owns episode state, action application, and telemetry transitions for rollout actions such as increase, halt, full rollout, and rollback. backend/feature_flag_env/server/feature_flag_environment.py is the central environment boundary; backend/feature_flag_env/server/simulation_engine.py supplies simulation behavior, while backend/feature_flag_env/models.py defines domain/state models. Scenario and mission inputs extend the core simulation through backend/feature_flag_env/configs/scenario_library.py and backend/feature_flag_env/missions.py.
Evaluation and Reward Pipeline
A step produces updated observation and reward; a completed trajectory is task-scored. Task definitions separate benchmark objectives—safe rollout, risk-aware scaling, and multi-objective optimization—in backend/feature_flag_env/tasks/task1_safe_rollout.py, backend/feature_flag_env/tasks/task2_risk_aware.py, and backend/feature_flag_env/tasks/task3_multi_objective.py. Shared trajectory grading is in backend/feature_flag_env/tasks/graders.py; reward policy and extended reward signals reside in backend/feature_flag_env/utils/reward_functions.py and backend/feature_flag_env/utils/extended_rewards.py.
Agent Layer
Agents consume observations and emit environment actions behind a common abstraction. backend/agents/base_agent.py establishes the agent contract, and backend/agents/factory.py selects implementations. Major policy variants are deterministic baseline (backend/agents/baseline_agent.py), LLM-driven (backend/agents/llm_agent.py), RL/checkpoint-driven (backend/agents/rl_agent.py), and enterprise orchestration (backend/agents/enterprise_agent_v2.py, backend/agents/master_agent.py). Ensemble and human-approval modes are separate decision boundaries in backend/agents/ensemble_agent.py and backend/agents/human_in_loop_agent.py.
API, Security, and Operational Controls
The simulation is exposed as an HTTP API with reset, step, state, health, and info operations through backend/feature_flag_env/server/app.py. Server concerns are split from environment behavior: backend/feature_flag_env/server/security.py handles security controls, and backend/feature_flag_env/utils/monitoring.py provides monitoring/alerting support. Persistence/audit-oriented infrastructure is represented by backend/feature_flag_env/utils/database.py and repository runtime artifacts under logs/.
Integrations and External Services
Tooling isolates external actions behind interfaces and a manager: backend/feature_flag_env/tools/tool_interface.py, backend/feature_flag_env/tools/tool_manager.py, and backend/feature_flag_env/tools/connectors.py. GitHub and Slack integrations have dedicated adapters in backend/feature_flag_env/tools/github_integration.py and backend/feature_flag_env/tools/slack_integration.py; mock versus real adapter boundaries are explicit in backend/feature_flag_env/tools/mock_adapters.py and backend/feature_flag_env/tools/real_adapters.py. The LLM agent supports OpenAI-compatible/Hugging Face router-style inference via environment configuration.
UI and Deployment Boundary
A separate Next.js/TypeScript frontend presents dashboard, flag, experiment, monitoring, integration, and AI-decision workflows. Route composition begins at frontend/app/layout.tsx, dashboard pages live under frontend/app/(dashboard)/, and backend communication is centralized in frontend/lib/api.ts. The backend can also serve committed static frontend output from backend/static/. Docker deployment is defined by Dockerfile and backend/Dockerfile, targeting Hugging Face Spaces’ Docker runtime and port 7860.
Main entry points: feature_flag_environment.py Feature Flag Environment · enterprise_agent_v2.py Enterprise Orchestration · app.py Simulation HTTP API · base_agent.py Agent Contract & Factory
Components 21
Runtimes
- Simulation HTTP API · Exposes reset, step, state, health, and info operations.
backend/feature_flag_env/server/app.py - Backend API
backend/server/app.py - Evaluation Runner · Runs local or remote agent evaluation.
backend/inference.py - RL & Enterprise Training
backend/train_rl.py
Simulation & Scoring
- Feature Flag Environment · Owns state, action application, observations, and transitions.
backend/feature_flag_env/server/feature_flag_environment.py - Simulation Engine
backend/feature_flag_env/server/simulation_engine.py - Domain Models
backend/feature_flag_env/models.py - Scenarios & Missions
backend/feature_flag_env/configs/scenario_library.py - Benchmark Tasks · Safe rollout, risk-aware scaling, and multi-objective objectives.
backend/feature_flag_env/tasks/task1_safe_rollout.py - Trajectory Grading & Rewards
backend/feature_flag_env/tasks/graders.py
Agent Policies
- Agent Contract & Factory
backend/agents/base_agent.py - Baseline, LLM & RL Agents
backend/agents/llm_agent.py - Enterprise Orchestration
backend/agents/enterprise_agent_v2.py - Ensemble & Human Approval
backend/agents/ensemble_agent.py
Operations & Integrations
- Security Controls
backend/feature_flag_env/server/security.py - Monitoring & Audit Store
backend/feature_flag_env/utils/monitoring.py - Tool Manager · Coordinates isolated external actions through tool interfaces.
backend/feature_flag_env/tools/tool_manager.py - GitHub & Slack Adapters · Supports mock and real external-service adapters.
backend/feature_flag_env/tools/github_integration.py
UI & Deployment
- Next.js Dashboard · Presents rollout, monitoring, integrations, and AI decisions.
frontend/app/layout.tsx - Frontend API Client
frontend/lib/api.ts - Docker / Spaces Runtime · Targets Hugging Face Spaces on port 7860.
Dockerfile
Connections 24
- Simulation HTTP API → Security Controls: protects requests
- Simulation HTTP API → Feature Flag Environment: reset / step
- Backend API → Feature Flag Environment: serves simulation
- Evaluation Runner → Agent Contract & Factory: selects agent
- Evaluation Runner → Feature Flag Environment: runs episodes
- RL & Enterprise Training → Feature Flag Environment: collects rollouts
- Feature Flag Environment → Simulation Engine: applies actions
- Feature Flag Environment → Domain Models: reads and updates state
- Scenarios & Missions → Feature Flag Environment: configures episode
- Feature Flag Environment → Benchmark Tasks: provides trajectory
- Benchmark Tasks → Trajectory Grading & Rewards: uses scoring policy
- Trajectory Grading & Rewards → Feature Flag Environment: returns reward
- Agent Contract & Factory → Baseline, LLM & RL Agents: instantiates policies
- Agent Contract & Factory → Enterprise Orchestration: instantiates orchestration
- Enterprise Orchestration → Ensemble & Human Approval: uses approval modes
- Baseline, LLM & RL Agents → Feature Flag Environment: actions from observations
- Enterprise Orchestration → Feature Flag Environment: orchestrated actions
- Feature Flag Environment → Monitoring & Audit Store: emits telemetry
- Enterprise Orchestration → Tool Manager: invokes external actions
- Tool Manager → GitHub & Slack Adapters: routes integrations
- Next.js Dashboard → Frontend API Client: uses
- Frontend API Client → Simulation HTTP API: backend requests
- Docker / Spaces Runtime → Simulation HTTP API: runs
- Docker / Spaces Runtime → Next.js Dashboard: deploys UI