chore(agent): polish clarification helper and tests

This commit is contained in:
Haohao-end 2026-03-15 12:37:39 +08:00
parent 664f125335
commit 793e9e47f5
2 changed files with 29 additions and 40 deletions

View File

@ -27,7 +27,7 @@ def should_enable_clarification(node_data: AgentNodeData) -> bool:
def extract_clarification_request(
agent_output: dict[str, Any],
_agent_output: dict[str, Any],
enable_clarification: bool,
) -> dict[str, Any] | None:
"""
@ -37,7 +37,7 @@ def extract_clarification_request(
Currently returns None as clarification is not yet implemented.
Args:
agent_output: The output from agent execution.
_agent_output: The output from agent execution. Currently unused, reserved for future HITL expansion.
enable_clarification: Whether clarification is enabled.
Returns:

View File

@ -2,6 +2,8 @@
Tests for agent node clarification helper and configuration.
"""
import pytest
from core.workflow.nodes.agent.clarification_helper import (
extract_clarification_request,
should_enable_clarification,
@ -10,51 +12,47 @@ from core.workflow.nodes.agent.entities import AgentNodeData
from dify_graph.enums import NodeType
@pytest.fixture
def base_node_data_args() -> dict:
"""Fixture providing base arguments for AgentNodeData construction."""
return {
"id": "test_node",
"type": NodeType.AGENT,
"agent_strategy_provider_name": "test_provider",
"agent_strategy_name": "test_strategy",
"agent_strategy_label": "Test Strategy",
"agent_parameters": {},
}
class TestClarificationHelper:
"""Test suite for clarification helper functions."""
def test_should_enable_clarification_when_enabled(self):
def test_should_enable_clarification_when_enabled(self, base_node_data_args):
"""Test that should_enable_clarification returns True when enabled."""
node_data = AgentNodeData(
id="test_node",
type=NodeType.AGENT,
agent_strategy_provider_name="test_provider",
agent_strategy_name="test_strategy",
agent_strategy_label="Test Strategy",
agent_parameters={},
**base_node_data_args,
enable_human_clarification=True,
)
assert should_enable_clarification(node_data) is True
def test_should_enable_clarification_when_disabled(self):
def test_should_enable_clarification_when_disabled(self, base_node_data_args):
"""Test that should_enable_clarification returns False when disabled."""
node_data = AgentNodeData(
id="test_node",
type=NodeType.AGENT,
agent_strategy_provider_name="test_provider",
agent_strategy_name="test_strategy",
agent_strategy_label="Test Strategy",
agent_parameters={},
**base_node_data_args,
enable_human_clarification=False,
)
assert should_enable_clarification(node_data) is False
def test_should_enable_clarification_default_false(self):
def test_should_enable_clarification_default_false(self, base_node_data_args):
"""Test that clarification is disabled by default."""
node_data = AgentNodeData(
id="test_node",
type=NodeType.AGENT,
agent_strategy_provider_name="test_provider",
agent_strategy_name="test_strategy",
agent_strategy_label="Test Strategy",
agent_parameters={},
)
node_data = AgentNodeData(**base_node_data_args)
assert should_enable_clarification(node_data) is False
def test_extract_clarification_request_when_disabled(self):
"""Test that extract_clarification_request returns None when disabled."""
result = extract_clarification_request(
agent_output={"text": "test output"},
_agent_output={"text": "test output"},
enable_clarification=False,
)
assert result is None
@ -63,31 +61,22 @@ class TestClarificationHelper:
"""Test that extract_clarification_request returns None when enabled (placeholder)."""
# Currently returns None as placeholder for future implementation
result = extract_clarification_request(
agent_output={"text": "test output"},
_agent_output={"text": "test output"},
enable_clarification=True,
)
assert result is None
def test_agent_node_data_with_clarification_field(self):
def test_agent_node_data_with_clarification_field(self, base_node_data_args):
"""Test that AgentNodeData properly stores enable_human_clarification."""
node_data = AgentNodeData(
id="test_node",
type=NodeType.AGENT,
agent_strategy_provider_name="test_provider",
agent_strategy_name="test_strategy",
agent_strategy_label="Test Strategy",
agent_parameters={},
**base_node_data_args,
enable_human_clarification=True,
)
assert node_data.enable_human_clarification is True
node_data_disabled = AgentNodeData(
id="test_node",
type=NodeType.AGENT,
agent_strategy_provider_name="test_provider",
agent_strategy_name="test_strategy",
agent_strategy_label="Test Strategy",
agent_parameters={},
**base_node_data_args,
enable_human_clarification=False,
)
assert node_data_disabled.enable_human_clarification is False