From 1a005b658459a9af00b27febd7065564fbf9ce98 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 24 Jan 2026 00:29:10 -0800 Subject: [PATCH] Add reload_lms method and debug forward() --- nanocode.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/nanocode.py b/nanocode.py index 090d673..204e0ee 100644 --- a/nanocode.py +++ b/nanocode.py @@ -229,6 +229,14 @@ class RLMCodingProgram(PrecompiledProgram): if not task: return dspy.Prediction(answer="No Task Given.") + # Debug: verify LM at call time + actual_lm = self.agent.get_lm() + print(f"{YELLOW}DEBUG forward() - agent.get_lm().model: {actual_lm.model}{RESET}") + print(f"{YELLOW}DEBUG forward() - self.lm.model: {self.lm.model}{RESET}") + print(f"{YELLOW}DEBUG forward() - agent.sub_lm.model: {self.agent.sub_lm.model}{RESET}") + print(f"{YELLOW}DEBUG forward() - self.sub_lm.model: {self.sub_lm.model}{RESET}") + print(f"{YELLOW}DEBUG forward() - id(agent.get_lm()): {id(actual_lm)}, id(self.lm): {id(self.lm)}{RESET}") + return self.agent(task=task) def get_tools(self): @@ -257,6 +265,23 @@ class RLMCodingProgram(PrecompiledProgram): new_instance.set_lm(self.lm) self.agent = new_instance + def reload_lms(self): + """Recreate LM objects from current config. Call this after changing config.lm or config.sub_lm.""" + self.lm = dspy.LM( + model=self.config.lm, + api_base=self.config.api_base, + max_tokens=self.config.max_tokens, + track_usage=self.config.track_usage, + ) + self.sub_lm = dspy.LM( + model=self.config.sub_lm, + api_base=self.config.api_base, + max_tokens=self.config.max_tokens, + track_usage=self.config.track_usage, + ) + self.reload_repl() + print(f"{BLUE}LMs RELOADED: {self.lm.model}, {self.sub_lm.model}{RESET}") + if __name__ == "__main__": agent = RLMCodingProgram(RLMCodingConfig()) - agent.push_to_hub(MODAIC_REPO_PATH, commit_message="change signature", branch="dev") + agent.push_to_hub(MODAIC_REPO_PATH, commit_message="Add reload_lms method and debug forward()", branch="dev")