import dspy

from core import ModelFactory

from .file import FileAgent


class OrchestratorSignature(dspy.Signature):
    """ """

    question: str = dspy.InputField()
    history: dspy.History = dspy.InputField()
    answer: str = dspy.OutputField()


class TheOracle(dspy.Module):
    """The Oracle is the orchestrator of all the agents."""

    def __init__(self):
        """Initialize the Oracle with available expert tools."""
        self.tools = [
            self.consult_file_expert,
        ]
        self.oracle = dspy.ReAct(signature=OrchestratorSignature, tools=self.tools, max_iters=10)

    def consult_file_expert(self, command: str) -> str:
        """Use this expert when you want to save or retrieve information from files.

        Also used to find files and update files
        """
        with dspy.context(lm=ModelFactory.create_file_model()):
            result = FileAgent().file_agent(command=command)
            return result.answer
