From 81551f8452e24db3be758f763ecee013b2823dcf Mon Sep 17 00:00:00 2001 From: OhMyApps <74984020+GiGiDKR@users.noreply.github.com> Date: Fri, 25 Jul 2025 06:48:44 +0200 Subject: [PATCH] fix: harmonize method signatures and add localization support for workflow tools - Add LOCALE-based localization support to all workflow tools - Harmonize method signatures for prepare_prompt and _prepare_file_content_for_prompt - Remove obsolete methods and clarify comments - Ensure consistent behavior between SimpleTool and WorkflowTool --- tools/workflow/workflow_mixin.py | 56 ++++++++++++++------------------ 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/workflow/workflow_mixin.py b/tools/workflow/workflow_mixin.py index 0b660d7..a8601da 100644 --- a/tools/workflow/workflow_mixin.py +++ b/tools/workflow/workflow_mixin.py @@ -89,6 +89,11 @@ class BaseWorkflowMixin(ABC): """Return the system prompt for this tool. Usually provided by BaseTool.""" pass + @abstractmethod + def get_language_instruction(self) -> str: + """Return the language instruction for localization. Usually provided by BaseTool.""" + pass + @abstractmethod def get_default_temperature(self) -> float: """Return the default temperature for this tool. Usually provided by BaseTool.""" @@ -107,11 +112,13 @@ class BaseWorkflowMixin(ABC): @abstractmethod def _prepare_file_content_for_prompt( self, - files: list[str], + request_files: list[str], continuation_id: Optional[str], - description: str, + context_description: str = "New files", + max_tokens: Optional[int] = None, + reserve_tokens: int = 1_000, remaining_budget: Optional[int] = None, - arguments: Optional[dict[str, Any]] = None, + arguments: Optional[dict] = None, model_context: Optional[Any] = None, ) -> tuple[str, list[str]]: """Prepare file content for prompts. Usually provided by BaseTool.""" @@ -299,7 +306,7 @@ class BaseWorkflowMixin(ABC): f"MANDATORY: DO NOT call the {self.get_name()} tool again immediately. " f"You MUST first work using appropriate tools. " f"REQUIRED ACTIONS before calling {self.get_name()} step {next_step_number}:\n" - + "\n".join(f"{i+1}. {action}" for i, action in enumerate(required_actions)) + + "\n".join(f"{i + 1}. {action}" for i, action in enumerate(required_actions)) + f"\n\nOnly call {self.get_name()} again with step_number: {next_step_number} " f"AFTER completing this work." ) @@ -1447,8 +1454,10 @@ class BaseWorkflowMixin(ABC): if file_content: expert_context = self._add_files_to_expert_context(expert_context, file_content) - # Get system prompt for this tool - system_prompt = self.get_system_prompt() + # Get system prompt for this tool with localization support + base_system_prompt = self.get_system_prompt() + language_instruction = self.get_language_instruction() + system_prompt = language_instruction + base_system_prompt # Check if tool wants system prompt embedded in main prompt if self.should_embed_system_prompt(): @@ -1547,36 +1556,21 @@ class BaseWorkflowMixin(ABC): # Default implementations for methods that workflow-based tools typically don't need - def prepare_prompt(self, request, continuation_id=None, max_tokens=None, reserve_tokens=0): + async def prepare_prompt(self, request) -> str: """ - Base implementation for workflow tools. + Base implementation for workflow tools - compatible with BaseTool signature. - Allows subclasses to customize prompt preparation behavior by overriding - customize_prompt_preparation(). - """ - # Allow subclasses to customize the prompt preparation - self.customize_prompt_preparation(request, continuation_id, max_tokens, reserve_tokens) - - # Workflow tools typically don't need to return a prompt - # since they handle their own prompt preparation internally - return "", "" - - def customize_prompt_preparation(self, request, continuation_id=None, max_tokens=None, reserve_tokens=0): - """ - Override this method in subclasses to customize prompt preparation. - - Base implementation does nothing - subclasses can extend this to add - custom prompt preparation logic without the base class needing to - know about specific tool capabilities. + Workflow tools typically don't need to return a prompt since they handle + their own prompt preparation internally through the workflow execution. Args: - request: The request object (may have files, prompt, etc.) - continuation_id: Optional continuation ID - max_tokens: Optional max token limit - reserve_tokens: Optional reserved token count + request: The validated request object + + Returns: + Empty string since workflow tools manage prompts internally """ - # Base implementation does nothing - subclasses override as needed - return None + # Workflow tools handle their prompts internally during workflow execution + return "" def format_response(self, response: str, request, model_info=None): """