From a3dd6a33cd4b80ef32d244487de74f00e7ac9c4a Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Mon, 12 Jan 2026 22:10:27 +0800 Subject: [PATCH] feat: integrate file I/O dependency rules and constraints into tool processing and planning logic --- agents/matmaster_agent/flow_agents/agent.py | 17 ++++----- .../flow_agents/plan_make_agent/prompt.py | 36 ++++++++++++++----- agents/matmaster_agent/sub_agents/tools.py | 2 ++ 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/agents/matmaster_agent/flow_agents/agent.py b/agents/matmaster_agent/flow_agents/agent.py index 53c60882..a68fbb52 100644 --- a/agents/matmaster_agent/flow_agents/agent.py +++ b/agents/matmaster_agent/flow_agents/agent.py @@ -425,18 +425,13 @@ async def _run_async_impl( available_tools = get_tools_list(ctx, scenes) if not available_tools: available_tools = ALL_AGENT_TOOLS_LIST - available_tools_with_info = { - item: { - 'scene': ALL_TOOLS[item]['scene'], - 'description': ALL_TOOLS[item]['description'], - } - for item in available_tools - } available_tools_with_info_str = '\n'.join( - [ - f"{key}\n scene: {', '.join(value['scene'])}\n description: {value['description']}" - for key, value in available_tools_with_info.items() - ] + f"{tool}\n" + f" scene: {', '.join(ALL_TOOLS[tool]['scene'])}\n" + f" description: {ALL_TOOLS[tool]['description']}\n" + f" needs_file_input: {ALL_TOOLS[tool].get('needs_file_input', None)}\n" + f" generates_file_output: {ALL_TOOLS[tool].get('generates_file_output', None)}\n" + for tool in available_tools ) self.plan_make_agent.instruction = get_plan_make_instruction( available_tools_with_info_str diff --git a/agents/matmaster_agent/flow_agents/plan_make_agent/prompt.py b/agents/matmaster_agent/flow_agents/plan_make_agent/prompt.py index 314e28c0..04bbe0ff 100644 --- a/agents/matmaster_agent/flow_agents/plan_make_agent/prompt.py +++ b/agents/matmaster_agent/flow_agents/plan_make_agent/prompt.py @@ -2,19 +2,38 @@ def get_plan_make_instruction(available_tools_with_info: str): return f""" You are an AI assistant specialized in creating structured execution plans. Analyze user intent and any provided error logs to break down requests into sequential steps. + +{{upload_file}} + {available_tools_with_info} +### TOOL I/O DEPENDENCY RULE (NEW): +Each tool in includes two boolean fields: +- needs_file_input: whether this tool requires a file as input +- generates_file_output: whether this tool produces a file output that can be consumed by later tools + +You MUST enforce the following dependency constraint: +- If a step uses a tool where needs_file_input == true, then at least one of the following must be true: + 1) The user has provided an uploaded file: upload_file == true + OR + 2) There exists a preceding step whose tool has generates_file_output == true, meaning it can produce the required file input. + +If neither condition is satisfied, you must still create the step (per “Create a step for EVERY discrete action”), but set tool_name to null and explain in: +- description: what file input is missing and what would be needed +- feasibility: why this step is not currently executable given the dependency rule + ### RE-PLANNING LOGIC: If the input contains errors from previous steps, analyze the failure and adjust the current plan (e.g., fix parameters or change tools) to resolve the issue. Mention the fix in the "description". +Additionally, when re-planning, verify that any needs_file_input step is still backed by either upload_file == true or a prior generates_file_output step. Return a JSON structure with the following format: {{ "steps": [ {{ - "tool_name": , // Name of the tool to use (exact match from available list). Use null if no suitable tool exists - "description": , // Clear explanation of what this tool call will accomplish - "feasibility", // Clear evidence that the preceding step or user input supports the execution of the step. Or why is there no tool support for this step + "tool_name": , // Name of the tool to use (exact match from available list). Use null if no suitable tool exists or dependency constraints cannot be satisfied + "description": , // Clear explanation of what this tool call will accomplish (include any parameter/configuration details here) + "feasibility": , // Evidence that prior steps or user input support this step, including file I/O dependency satisfaction, OR explain why no tool/support exists "status": "plan" // Always return "plan" }} ] @@ -22,24 +41,25 @@ def get_plan_make_instruction(available_tools_with_info: str): CRITICAL GUIDELINES: 1. Configuration parameters should NOT be treated as separate steps - integrate them into relevant execution steps -2. **CRITICAL: If user queries contain file URLs, DO NOT create separate steps for downloading, parsing, or any file preprocessing (e.g., "download and prepare structure", "prepare input structure"). Treat file URLs as direct inputs to relevant end-processing tools.** +2. **CRITICAL: If user queries contain file URLs, DO NOT create separate steps for downloading, parsing, or any file preprocessing. Treat file URLs as direct inputs to relevant end-processing tools.** 3. **MULTI-STRUCTURE PROCESSING: When processing multiple structures (generation, retrieval, or calculation), create SEPARATE steps for EACH individual structure. Never combine multiple structures into a single tool call, even if the tool technically supports batch processing.** 4. Create a step for EVERY discrete action identified in the user request, regardless of tool availability -5. Use null for tool_name only when no appropriate tool exists in the available tools list +5. Use null for tool_name only when no appropriate tool exists in the available tools list OR when required dependencies (e.g., needs_file_input) are not satisfied 6. Never invent or assume tools - only use tools explicitly listed in the available tools 7. Match tools precisely to requirements - if functionality doesn't align exactly, use null 8. Ensure steps array represents the complete execution sequence for the request EXECUTION PRINCIPLES: -- Make sure that the previous steps can provide the input information required for the current step, such as the file URL +- Make sure that the previous steps can provide the input information required for the current step (including the file I/O dependency rule) - Configuration parameters should be embedded within the step that uses them, not isolated as standalone steps - **File URLs should be treated as direct inputs to processing tools - no separate download, parsing, or preparation steps** - **Assume processing tools can handle URLs directly and include all necessary preprocessing capabilities** - **Skip any intermediate file preparation steps - go directly to the core processing task** -- **For multiple structures: Always use one step per structure per operation type (generation → structure1, generation → structure2; retrieval → structure1, retrieval → structure2; etc.)** -- **Maintain strict sequential processing: complete all operations for one structure before moving to the next, or group by operation type across all structures** +- **For multiple structures: Always use one step per structure per operation type** +- **Maintain strict sequential processing** - Prioritize accuracy over assumptions - Maintain logical flow in step sequencing - Ensure descriptions clearly communicate purpose - Validate tool compatibility before assignment +- Validate tool file I/O compatibility before assignment (needs_file_input / generates_file_output) """ diff --git a/agents/matmaster_agent/sub_agents/tools.py b/agents/matmaster_agent/sub_agents/tools.py index 5e2f79ee..23ecf65a 100644 --- a/agents/matmaster_agent/sub_agents/tools.py +++ b/agents/matmaster_agent/sub_agents/tools.py @@ -1733,5 +1733,7 @@ 'alternative': [], 'bypass_confirmation': True, 'self_check': False, + 'needs_file_input': True, + 'generates_file_output': False, }, }