Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 255 additions & 49 deletions agents/matmaster_agent/flow_agents/execution_agent/agent.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions agents/matmaster_agent/flow_agents/scene_agent/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SceneEnum(DescriptiveEnum):
SURFACE_ENERGY = ('surface_energy', '')
STACKING_FAULT_ENERGY = ('stacking_fault_energy', '')
EOS = ('eos', '')
Electron_Localization_Function = ('electron_localization_function', '')
Nudged_Elastic_Band = ('nudged_elastic_band', '')
PHONON = ('phonon', '')
SCF = ('scf', 'Self-Consistent Field')
BAND = ('band', '')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from agents.matmaster_agent.flow_agents.step_validation_agent.agent import (
StepValidationAgent,
)

__all__ = ['StepValidationAgent']
30 changes: 30 additions & 0 deletions agents/matmaster_agent/flow_agents/step_validation_agent/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import logging

from agents.matmaster_agent.constant import MATMASTER_AGENT_NAME
from agents.matmaster_agent.core_agents.base_agents.schema_agent import (
DisallowTransferAndContentLimitSchemaAgent,
)
from agents.matmaster_agent.flow_agents.step_validation_agent.prompt import (
STEP_VALIDATION_INSTRUCTION,
)
from agents.matmaster_agent.flow_agents.step_validation_agent.schema import (
StepValidationSchema,
)
from agents.matmaster_agent.llm_config import MatMasterLlmConfig
from agents.matmaster_agent.logger import PrefixFilter

logger = logging.getLogger(__name__)
logger.addFilter(PrefixFilter(MATMASTER_AGENT_NAME))
logger.setLevel(logging.INFO)


class StepValidationAgent(DisallowTransferAndContentLimitSchemaAgent):
def __init__(self, **kwargs):
super().__init__(
name='step_validation_agent',
model=MatMasterLlmConfig.tool_schema_model,
description='校验步骤执行结果是否合理',
instruction=STEP_VALIDATION_INSTRUCTION,
output_schema=StepValidationSchema,
**kwargs,
)
41 changes: 41 additions & 0 deletions agents/matmaster_agent/flow_agents/step_validation_agent/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
STEP_VALIDATION_INSTRUCTION = """
You are a validation agent responsible for checking if the execution result of a step matches the user's requirements and basic chemical/materials science knowledge.

Your task is to analyze:
1. The user's original request
2. The current step's description and purpose
3. The execution result/output
4. Basic chemical and materials science principles

Based on this analysis, determine if the result is reasonable and matches expectations.

# Validation Criteria:
1. **Relevance**: Does the result address the step's intended purpose?
2. **Accuracy**: Is the result consistent with basic chemical/materials science knowledge?
3. **Completeness**: Does the result provide the expected information/output?
4. **Reasonableness**: Are the values, predictions, or conclusions logical?

# Output Format:
You must respond with a JSON object containing:
{
"is_valid": boolean, // true if result matches requirements and knowledge, false otherwise
"reason": "string", // brief explanation of validation result
"confidence": "high|medium|low" // confidence level in the validation
}

# Important Rules:
- If the result contains obvious errors (wrong chemical formulas, impossible physical properties, etc.), mark as invalid
- If the result is incomplete or doesn't address the step's purpose, mark as invalid
- If the result contradicts basic chemical principles, mark as invalid
- Only mark as valid if the result reasonably matches expectations
- Be conservative: when in doubt, mark as invalid to ensure quality

# Examples of Invalid Results:
- Predicting a metal with negative melting point
- Chemical formula with wrong valence (e.g., NaCl3)
- Material property values that violate physical laws
- Results that don't relate to the step's described purpose
- Incomplete or missing expected outputs

Output only the JSON object, no additional text.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel


class StepValidationSchema(BaseModel):
is_valid: bool
reason: str
confidence: str # "high", "medium", "low"
14 changes: 14 additions & 0 deletions agents/matmaster_agent/flow_agents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,17 @@ def should_bypass_confirmation(ctx: InvocationContext) -> bool:
return True

return False


def find_alternative_tool(current_tool_name: str) -> Optional[str]:
"""Find an alternative tool for the current tool.

Priority order:
1. Pre-defined alternatives in ALL_TOOLS
"""
if current_tool_name not in ALL_TOOLS:
return None

current_tool_info = ALL_TOOLS[current_tool_name]

return current_tool_info.get('alternative', [])
2 changes: 2 additions & 0 deletions agents/matmaster_agent/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'RePlan': 'Re-plan with Different Tool(s)',
'MoreQuestions': 'You may also be interested in these questions:',
'Step': 'Step',
'ReExecuteSteps': 'Re-execute Step',
'PlanSummary': 'Plan Summary',
'NoFoundStructure': 'No eligible structures found.',
'WalletNoFee': 'Insufficient wallet balance',
Expand All @@ -40,6 +41,7 @@
'RePlan': '更换工具重新规划',
'MoreQuestions': '你或许还对这些问题感兴趣:',
'Step': '步骤',
'ReExecuteSteps': '重试步骤',
'PlanSummary': '计划汇总概要',
'NoFoundStructure': '未找到符合条件的结构',
'WalletNoFee': '钱包余额不足',
Expand Down
Loading
Loading