Repository navigation
feat(experiments): add pluggable experiment lifecycle callback system - #423
Conversation
…tLimitCallback) - Add callbacks.py: AbstractCallback base, CallbackList dispatcher, ConsoleProgressCallback, BudgetLimitCallback - Wire CallbackList into ExpArgs.run() at 5 lifecycle points (on_exp_start, on_step_start, on_action_selected, on_step_end, on_exp_end) - Add callbacks field to ExpArgs dataclass (default=[]) -- 100% backward-compatible - Export public API from experiments/__init__.py - Add 24 unit tests in tests/experiments/test_callbacks.py (all passing)
…tream) - Add WandbCallback: live experiment streaming to Weights & Biases - Add MLflowCallback: experiment tracking for MLflow - Add JsonlStreamCallback: live JSONL event streaming for web UIs and dashboards - Add EpisodeAbortedError base exception to allow guardrails to safely abort episodes - Add safe Windows fallback for console output in ConsoleProgressCallback - Add 36 new unit tests in tests/experiments/test_callbacks_cloud.py (60/60 passing)
|
@Surya-5555 kindly review the integrations.......!!! |
a0d208b to
5899276
Compare
5899276 to
4a6f39b
Compare
|
Hi @sriram687, thank you for proposing and implementing this callback system! The architecture is very clean, extensible, and well-documented. Before this can be merged, there is one critical lifecycle bug in
Thanks again for the solid foundation and great design! |
5fb6913 to
4a6f39b
Compare
- loop.py: move on_step_end to after from_step so reward/terminated are populated; call on_step_end(is_done=True) on action=None break path - callbacks.py: CallbackList(None) no longer raises TypeError - callbacks.py: BudgetLimitCallback accumulates tokens on terminal step - callbacks.py: WandbCallback/MLflowCallback success metric now checks cumulative_reward > 0 in addition to no err_msg - tests: add TestCallbackListNoneGraceful, TestBudgetLimitCallbackTerminalAccumulation, TestLoopOnStepEndFinalStep (29 tests total, all pass)
1c763e9 to
74e9ee7
Compare
b91af6f to
571946f
Compare
|
Hi @sriram687, thanks for turning those fixes around so quickly! While double-checking the updated
Once these are in and CI is green, this is ready to merge! |
- loop.py: build merged _cb_snapshot so on_step_end receives both agent stats (step, action, agent_info, stats from prev step) and env result (obs, reward, terminated from new step); no disk objects mutated - loop.py: pickle-safe prepare() — temporarily clears self.callbacks before pickle.dump, restores in finally; fixes JsonlStreamCallback crash - callbacks.py: WandbCallback.on_step_end accumulates _cumulative_reward and _cumulative_tokens before the log_step_metrics guard so on_exp_end summaries are correct even when per-step logging is disabled - callbacks.py: same fix for MLflowCallback.on_step_end - tests: replace CallbackList-only simulation with real ExpArgs.prepare() + ExpArgs.run() integration tests asserting non-zero tokens, correct reward on terminal step, BudgetLimitCallback mid-episode abort, and JsonlStreamCallback surviving prepare() with callbacks restored - 31 tests total, all pass; black 24.2.0 clean
|
@Surya-5555 kindly review!!! |
Surya-5555
left a comment
There was a problem hiding this comment.
Thanks for addressing all the feedback, @sriram687
LGTM, approving and merging now
Experiment Lifecycle Callbacks
Summary
ExpArgs.run()now broadcasts structured events at five hook points, so researchers can attach monitoring, safety guardrails, and dashboard integrations without modifying any core loop code.Motivation
As described in #417, the existing loop is a closed, synchronous black box. In practice this causes three problems:
Backward Compatibility
No existing behaviour changes. The
callbacksfield defaults to[], soCallbackListiterates over an empty list — zero overhead. All existing tests pass unchanged.Verification
Usage Example
PROOF OF WORK