Fix config override bug by recreating LMs after load_state

This commit is contained in:
2026-01-24 02:29:44 -08:00
parent f6706d1c00
commit 761579391a

View File

@@ -4,6 +4,7 @@ from modaic import PrecompiledProgram, PrecompiledConfig
import dspy import dspy
import re import re
import subprocess import subprocess
from dspy.utils.callback import BaseCallback
# --- Modaic --- # --- Modaic ---
@@ -23,6 +24,7 @@ MAGENTA = "\033[35m"
# --- File operations --- # --- File operations ---
def read_file(path: str, offset: int = 0, limit: int = None) -> str: def read_file(path: str, offset: int = 0, limit: int = None) -> str:
"""Read file contents with line numbers. """Read file contents with line numbers.
@@ -163,8 +165,15 @@ def run_bash(cmd: str) -> str:
return "".join(output_lines).strip() or "(empty output)" return "".join(output_lines).strip() or "(empty output)"
class RLMReasoningCallback(BaseCallback):
def on_module_end(self, call_id, outputs, exception):
if outputs and hasattr(outputs, "reasoning") and hasattr(outputs, "code"):
print(f"\n[REASONING STEP] reasoning: {outputs.reasoning}\n")
# -- Program --- # -- Program ---
class CodingAssistant(dspy.Signature): class CodingAssistant(dspy.Signature):
"""You are a concise coding assistant with access to sub agents.""" """You are a concise coding assistant with access to sub agents."""
@@ -279,13 +288,18 @@ class RLMCodingProgram(PrecompiledProgram):
PrecompiledProgram.from_precompiled() calls load_state() AFTER __init__, PrecompiledProgram.from_precompiled() calls load_state() AFTER __init__,
which overwrites our LMs with saved state. We fix this by recreating which overwrites our LMs with saved state. We fix this by recreating
the LMs from self.config after the parent load_state runs. Modaic will the LMs from self.config after the parent load_state runs. Modaic will
fix this in a later patch for future devs. fix this in a later patch for future devs.
""" """
super().load_state(state) super().load_state(state)
# recreate LMs from config (not from saved state) # recreate LMs from config (not from saved state)
self.reload_lms() self.reload_lms()
if __name__ == "__main__": if __name__ == "__main__":
agent = RLMCodingProgram(RLMCodingConfig()) agent = RLMCodingProgram(RLMCodingConfig())
agent.push_to_hub(MODAIC_REPO_PATH, commit_message="Fix config override bug by recreating LMs after load_state") agent.push_to_hub(
MODAIC_REPO_PATH,
commit_message="Fix config override bug by recreating LMs after load_state",
branch="main"
)